123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
"use strict";
modulum('RowBoundDecoratorWidget', ['WidgetBase', 'WidgetFactory'],
function(context, cls) {
cls.RowBoundDecoratorWidget = context.oo.Class(cls.WidgetBase, function($super) {
return {
__name: "RowBoundDecoratorWidget",
_contextMenuWidget: null,
_quickActions: null,
_quickActionsNumber: 0,
_contextMenuIconElement: null,
_initElement: function() {
this._ignoreLayout = true;
$super._initElement.call(this);
this._quickActions = new Map();
this._contextMenuIconElement = this._element.getElementsByTagName('span')[0];
this._contextMenuIconElement.toggleClass("hidden", true);
},
destroy: function() {
this._quickActions.clear();
this._quickActions = null;
$super.destroy.call(this);
},
manageMouseClick: function(domEvent) {
let rowBoundContainerWidget = this.getTableWidgetBase();
if (!rowBoundContainerWidget && this.getParentWidget().isInstanceOf(cls.StretchableScrollGridLineWidget)) {
rowBoundContainerWidget = this.getParentWidget().getParentWidget();
}
if (rowBoundContainerWidget) {
if (this.getParentWidget().requestFocus) {
this.getParentWidget().requestFocus(domEvent);
}
if (domEvent.target.isElementOrChildOf(this._contextMenuIconElement)) {
let rowBoundWidget = rowBoundContainerWidget.getRowBoundWidget();
if (rowBoundWidget) {
rowBoundWidget.parentElement = this._contextMenuIconElement;
rowBoundWidget.reverseX = true;
rowBoundContainerWidget.emit(context.constants.widgetEvents.rowBoundMenu);
return false;
}
} else {
for (const [elem, menuLabel] of this._quickActions) {
if (domEvent.target.isElementOrChildOf(elem)) {
menuLabel.emit(context.constants.widgetEvents.click);
return false;
}
}
}
}
return true;
},
setContextMenuWidget: function(contextMenu) {
this._contextMenuWidget = contextMenu;
},
updateQuickActions: function() {
if (this._element.hasChildNodes()) {
let children = this._element.childNodes;
while (children.length > 1) {
this._element.removeChild(this._element.lastChild);
}
}
this._quickActions.clear();
let actions = this._contextMenuWidget.getActionWidgets();
let i = 0;
for (const [name, menuLabel] of actions) {
if (i < this._quickActionsNumber) {
let clone = menuLabel._imageContainer.cloneNode(true);
this._element.appendChild(clone);
this._quickActions.set(clone, menuLabel);
menuLabel.setHidden(true);
}
i++;
}
this._contextMenuIconElement.toggleClass("hidden", i <= this._quickActionsNumber);
}
};
});
cls.WidgetFactory.registerBuilder('RowBoundDecorator', cls.RowBoundDecoratorWidget);
});