123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
"use strict";
modulum('ScrollGridWidget', ['WidgetGridLayoutBase', 'WidgetFactory'],
function(context, cls) {
cls.ScrollGridWidget = context.oo.Class(cls.GridWidget, function($super) {
return {
$static: {
_onClick: function(event) {
this.emit(context.constants.widgetEvents.click, event);
if (!this._rowActionTriggerByDoubleClick && event.target !== this._containerElement) {
this.emit(context.constants.widgetEvents.rowAction, event);
}
},
_onDblClick: function(event) {
if (this._rowActionTriggerByDoubleClick && event.target !== this._containerElement) {
this.emit(context.constants.widgetEvents.rowAction, event);
}
},
},
__name: "ScrollGridWidget",
_scrollWidget: null,
_rowActionTriggerByDoubleClick: true,
_uiWidget: null,
_folderPageWidget: null,
_uiActivateHandler: null,
_pageActivateHandler: null,
_focusOnField: false,
_highlightColor: null,
_highlightTextColor: null,
_highlightCurrentRow: null,
_highlightCurrentRowCssSelector: ":not(.disabled).gbc_ScrollGridWidget.highlight .currentRow",
_highlightCurrentCellCssSelector: ":not(.disabled).gbc_ScrollGridWidget.highlightCell .currentRow.gbc_Focus",
_highlightCurrentCell: null,
constructor: function(opts) {
opts = opts || {};
this._uiWidget = opts.uiWidget;
this._folderPageWidget = opts.folderPageWidget;
$super.constructor.call(this, opts);
},
_initElement: function() {
$super._initElement.call(this);
this._scrollWidget = cls.WidgetFactory.createWidget("Scroll", this.getBuildParameters());
this.addChildWidget(this._scrollWidget, {
noDOMInsert: true
});
this._element.appendChild(this._scrollWidget.getElement());
this._uiActivateHandler = this._uiWidget.onActivate(this.refreshScroll.bind(this, true));
if (this._folderPageWidget) {
this._pageActivateHandler = this._folderPageWidget.onActivate(this.refreshScroll.bind(this));
}
},
_initLayout: function() {
this._layoutInformation = new cls.LayoutInformation(this);
this._layoutEngine = new cls.ScrollGridLayoutEngine(this);
},
destroy: function() {
this._rerouteChildren = false;
this._element.removeChild(this._scrollWidget.getElement());
this._scrollWidget.destroy();
this._scrollWidget = null;
this._uiWidget = null;
this._folderPageWidget = null;
if (this._uiActivateHandler) {
this._uiActivateHandler();
this._uiActivateHandler = null;
}
if (this._pageActivateHandler) {
this._pageActivateHandler();
this._pageActivateHandler = null;
}
$super.destroy.call(this);
},
manageMouseClick: function(domEvent) {
cls.ScrollGridWidget._onClick.call(this, domEvent);
return true;
},
manageMouseDblClick: function(domEvent) {
cls.ScrollGridWidget._onDblClick.call(this, domEvent);
return true;
},
_listChildrenToMoveWhenGridChildrenInParent: function() {
return this._children.filter(function(item) {
return item !== this._scrollWidget;
}.bind(this));
},
setRowActionTriggerByDoubleClick: function(b) {
this._rowActionTriggerByDoubleClick = b;
},
getScrollWidget: function() {
return this._scrollWidget;
},
getRowHeight: function() {
return this._layoutInformation.getMeasured().getHeight(true) / Math.max(1, this._scrollWidget.getPageSize());
},
getScrollableArea: function() {
return this._scrollWidget.getElement();
},
setPageSize: function(pageSize) {
this._scrollWidget.setPageSize(pageSize);
},
setSize: function(size) {
this._scrollWidget.setSize(size);
},
setOffset: function(offset) {
this._scrollWidget.setOffset(offset);
},
setTotalHeight: function(size) {
this._scrollWidget.setTotalHeight(size);
},
refreshScroll: function(force) {
this._scrollWidget.setLineHeight(this.getRowHeight());
this._scrollWidget.refreshScroll(force);
},
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
});
this.setStyle({
selector: this._highlightCurrentRowCssSelector,
appliesOnRoot: true
}, {
"color": color,
"fill": color
});
}
},
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
});
}
},
setHighlightCurrentRow: function(highlight) {
if (!this._focusOnField) {
this._highlightCurrentRow = highlight;
this._element.toggleClass("nohighlight", !highlight);
this._element.toggleClass("highlight", highlight);
}
},
isHighlightCurrentRow: function() {
return this._highlightCurrentRow;
},
setHighlightCurrentCell: function(b) {
this._highlightCurrentCell = b;
this._element.toggleClass("highlightCell", b);
},
isHighlightCurrentCell: function() {
return this._highlightCurrentCell;
},
setFocusOnField: function(focusOnField) {
if (this._focusOnField !== focusOnField) {
this._focusOnField = focusOnField;
this._element.toggleClass("focusOnField", focusOnField);
this._element.toggleClass("nohighlight", true);
this._element.toggleClass("highlight", false);
}
},
hasFocusOnField: function() {
return this._focusOnField;
},
getCurrentRow: function() {
return this._currentRow;
},
setCurrentRow: function(currentRow) {
this._currentRow = currentRow;
},
updateHighlight: function() {}
};
});
cls.WidgetFactory.registerBuilder('ScrollGrid', cls.ScrollGridWidget);
});