123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422
"use strict";
modulum('StretchableScrollGridWidget', ['WidgetGroupBase', 'WidgetFactory'],
function(context, cls) {
cls.StretchableScrollGridWidget = context.oo.Class(cls.WidgetGroupBase, function($super) {
return {
__name: "StretchableScrollGridWidget",
_pageSize: null,
_size: null,
_offset: null,
lastSentOffset: null,
_rowActionTriggerByDoubleClick: true,
_rowHeight: 0,
_currentRow: 0,
_focusOnField: false,
_uiWidget: null,
_folderPageWidget: null,
_uiActivateHandler: null,
_pageActivateHandler: null,
_highlightColor: null,
_highlightTextColor: null,
_highlightCurrentRow: null,
_highlightCurrentRowCssSelector: ":not(.disabled) .gbc_StretchableScrollGridLineWidget.highlight.currentRow",
_highlightCurrentCellCssSelector: ":not(.disabled) .gbc_StretchableScrollGridLineWidget .g_GridElement >.currentRow",
_highlightCurrentCell: null,
_rowBoundWidget: null,
_hasReduceFilter: false,
_firstPageSize: null,
constructor: function(opts) {
opts = opts || {};
this._uiWidget = opts.uiWidget;
this._folderPageWidget = opts.folderPageWidget;
$super.constructor.call(this, opts);
},
_initLayout: function() {
this._layoutInformation = new cls.LayoutInformation(this);
this._layoutEngine = new cls.StretchableScrollLayoutEngine(this);
this._layoutInformation.getStretched().setDefaultX(true);
this._layoutInformation.getStretched().setDefaultY(true);
},
_initElement: function() {
$super._initElement.call(this);
this._element.on('scroll.StretchableScrollGridWidget', function(event) {
this.emit(context.constants.widgetEvents.scroll, event, this.getRowHeight());
}.bind(this));
this._uiActivateHandler = this._uiWidget.onActivate(this.updateVerticalScroll.bind(this, true));
if (this._folderPageWidget) {
this._pageActivateHandler = this._folderPageWidget.onActivate(this.updateVerticalScroll.bind(this, true));
}
},
destroy: function() {
if (this._uiActivateHandler) {
this._uiActivateHandler();
this._uiActivateHandler = null;
}
if (this._pageActivateHandler) {
this._pageActivateHandler();
this._pageActivateHandler = null;
}
this._element.off('scroll.StretchableScrollGridWidget');
this._rowBoundWidget = null;
this._uiWidget = null;
this._folderPageWidget = null;
this.destroyChildren();
$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;
},
addChildWidget: function(widget, options) {
if (widget.isInstanceOf(cls.StretchableScrollGridLineWidget)) {
$super.addChildWidget.call(this, widget, options);
if (this.hasRowBound()) {
widget.addRowBoundDecorator();
}
} else if (widget.isInstanceOf(cls.ContextMenuWidget)) {
this._rowBoundWidget = widget;
this._rowBoundWidget.setParentWidget(this);
}
},
setRowActionTriggerByDoubleClick: function(b) {
this._rowActionTriggerByDoubleClick = b;
},
setFocusOnField: function(focusOnField) {
if (this._focusOnField !== focusOnField) {
this._focusOnField = focusOnField;
this.updateHighlight();
}
},
hasFocusOnField: function() {
return this._focusOnField;
},
getDataAreaHeight: function() {
return this.getLayoutInformation().getAvailable().getHeight();
},
getScrollableArea: function() {
return this.getElement();
},
getRowHeight: function() {
if (this._rowHeight === 0 && this.getChildren().length !== 0) {
this._rowHeight = this.getChildren()[0]._element.getBoundingClientRect().height;
}
return this._rowHeight;
},
setPageSize: function(pageSize) {
this._pageSize = pageSize;
},
setSize: function(size) {
this._size = size;
},
setOffset: function(offset) {
this._offset = offset;
},
updateVerticalScroll: function(forceScroll) {
this.updateContentPosition(this._size, this._pageSize, this._offset, forceScroll);
},
updateContentPosition: function(size, pageSize, offset, forceScroll) {
this.setSize(size);
this._pageSize = pageSize;
var top = offset * this.getRowHeight();
var height = (size - offset) * this.getRowHeight();
this.setStyle("> .containerElement", {
"margin-top": top + "px",
"height": height + "px"
});
if (!!forceScroll || (this.lastSentOffset === null || this.lastSentOffset === offset) && offset !== this._offset) {
this._offset = offset;
this.afterDomMutator(function() {
this.getScrollableArea().scrollTop = top;
}.bind(this));
}
this.lastSentOffset = null;
},
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);
},
getRowBoundWidget: function() {
return this._rowBoundWidget;
},
hasRowBound: function() {
return this._rowBoundWidget !== null;
},
setReduceFilter: function(b) {
this._hasReduceFilter = b;
},
hasReduceFilter: function() {
return this._hasReduceFilter;
}
};
});
cls.WidgetFactory.registerBuilder('StretchableScrollGrid', cls.StretchableScrollGridWidget);
});