123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
"use strict";
modulum('PagedScrollGridWidget', ['WidgetGroupBase', 'WidgetFactory'],
function(context, cls) {
cls.PagedScrollGridWidget = context.oo.Class(cls.WidgetGroupBase, function($super) {
return {
__name: "PagedScrollGridWidget",
_rowActionTriggerByDoubleClick: true,
_currentRow: 0,
_focusOnField: false,
_highlightColor: null,
_highlightTextColor: null,
_highlightCurrentRow: null,
_highlightCurrentRowCssSelector: ":not(.disabled) .gbc_PagedScrollGridWidget.highlight.currentRow",
_highlightCurrentCellCssSelector: ":not(.disabled) .gbc_PagedScrollGridWidget .g_GridElement >.currentRow",
_highlightCurrentCell: null,
_paginationWidget: null,
_onOffsetHandler: null,
_initLayout: function() {
$super._initLayout.call(this);
this._layoutEngine = new cls.StretchableScrollLayoutEngine(this);
this._layoutInformation.getStretched().setDefaultX(true);
this._layoutInformation.getStretched().setDefaultY(true);
},
_initElement: function() {
$super._initElement.call(this);
this._paginationWidget = cls.WidgetFactory.createWidget("Pagination", this.getBuildParameters());
this._onOffsetHandler = this._paginationWidget.when(context.constants.widgetEvents.offset, function(event) {
this.emit(context.constants.widgetEvents.offset, event.data[0]);
}.bind(this));
this._element.appendChild(this._paginationWidget.getElement());
},
destroy: function() {
if (this._onOffsetHandler) {
this._onOffsetHandler();
this._onOffsetHandler = null;
}
this._paginationWidget.destroy();
this._paginationWidget = null;
this.destroyChildren();
$super.destroy.call(this);
},
manageMouseClick: function(domEvent) {
if (domEvent.target.isElementOrChildOf(this._containerElement)) {
cls.ScrollGridWidget._onClick.call(this, domEvent);
}
return true;
},
manageMouseDblClick: function(domEvent) {
if (domEvent.target.isElementOrChildOf(this._containerElement)) {
cls.ScrollGridWidget._onDblClick.call(this, domEvent);
}
return true;
},
addChildWidget: function(widget, options) {
$super.addChildWidget.call(this, widget, options);
widget.removeClass("gbc_WidgetBase_standalone");
widget.addClass("gbc_WidgetBase_in_array");
},
setRowActionTriggerByDoubleClick: function(b) {
this._rowActionTriggerByDoubleClick = b;
},
setFocusOnField: function(focusOnField) {
if (this._focusOnField !== focusOnField) {
this._focusOnField = focusOnField;
this.updateHighlight();
}
},
hasFocusOnField: function() {
return this._focusOnField;
},
getDataAreaWidth: function() {
return this.getContainerElement().getBoundingClientRect().width;
},
getDataAreaHeight: function() {
return this.getContainerElement().getBoundingClientRect().height;
},
getRowWidth: function() {
var children = this.getChildren();
if (children.length !== 0) {
return children[0].getElement().getBoundingClientRect().width;
}
return 0;
},
getRowHeight: function() {
var children = this.getChildren();
if (children.length !== 0) {
return children[0].getElement().getBoundingClientRect().height;
}
return 0;
},
updateContentPosition: function(size, pageSize, offset) {
this._paginationWidget.updateContentPosition(size, pageSize, offset);
},
setCurrentRow: function(row) {
this._currentRow = row;
var children = this.getChildren();
var length = children.length;
for (var i = 0; i < length; ++i) {
var rowWidget = children[i];
rowWidget.setCurrent(i === row);
}
},
getCurrentRow: function() {
return this._currentRow;
},
setHighlightColor: function(color) {
if (this._highlightColor !== color) {
this._highlightColor = color;
color = (color === null ? null : color + " !important");
this.setStyle({
selector: this._highlightCurrentRowCssSelector,
appliesOnRoot: true
}, {
"background-color": color
});
this.setStyle({
selector: this._highlightCurrentCellCssSelector,
appliesOnRoot: true
}, {
"background-color": color
});
}
},
setHighlightTextColor: function(color) {
if (this._highlightTextColor !== color) {
this._highlightTextColor = color;
color = (color === null ? null : color + " !important");
this.setStyle({
selector: this._highlightCurrentCellCssSelector,
appliesOnRoot: true
}, {
"color": color,
"fill": color
});
}
},
setHighlightCurrentRow: function(b) {
this._highlightCurrentRow = b;
},
isHighlightCurrentRow: function() {
return this._highlightCurrentRow;
},
setHighlightCurrentCell: function(b) {
this._highlightCurrentCell = b;
},
isHighlightCurrentCell: function() {
return this._highlightCurrentCell;
},
updateHighlight: function() {
this.setCurrentRow(this._currentRow);
},
getPaginationWidget: function() {
return this._paginationWidget;
}
};
});
cls.WidgetFactory.registerBuilder('ScrollGrid[customWidget=pagedScrollGrid]', cls.PagedScrollGridWidget);
cls.WidgetFactory.registerBuilder('StretchableScrollGrid[customWidget=pagedScrollGrid]', cls.PagedScrollGridWidget);
});