123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
"use strict";
modulum('StretchableScrollGridWidget', ['StretchableScrollGridWidgetBase', 'WidgetFactory'],
function(context, cls) {
cls.StretchableScrollGridWidget = context.oo.Class(cls.StretchableScrollGridWidgetBase, function($super) {
return {
__name: "StretchableScrollGridWidget",
_pageSize: null,
_size: null,
_offset: null,
lastSentOffset: null,
_rowHeight: 0,
_currentRow: 0,
_uiWidget: null,
_folderPageWidget: null,
_uiActivateHandler: null,
_pageActivateHandler: 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);
},
_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);
}
},
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;
if (this._rowHeight > 0) {
var rowMargin = parseInt(context.ThemeService.getValue("gbc-ScrollGridWidget-inner-gutter"), 10);
this._rowHeight += rowMargin;
}
}
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;
},
getRowBoundWidget: function() {
return this._rowBoundWidget;
},
hasRowBound: function() {
return this._rowBoundWidget !== null;
},
setReduceFilter: function(b) {
this._hasReduceFilter = b;
},
hasReduceFilter: function() {
return this._hasReduceFilter;
},
setItemsAlignment: function(alignment) {
if (this._containerElement) {
this._containerElement.style.alignItems = {
start: "flex-start",
left: "flex-start",
center: "center",
stretch: "stretch",
right: "flex-end",
end: "flex-end"
} [alignment] || "stretch";
}
}
};
});
cls.WidgetFactory.registerBuilder('StretchableScrollGrid', cls.StretchableScrollGridWidget);
});