123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468
"use strict";
modulum('RTableItemWidget', ['WidgetGroupBase'],
function(context, cls) {
cls.RTableItemWidget = context.oo.Class(cls.WidgetGroupBase, function($super) {
return {
__name: "RTableItemWidget",
_treeAnchor: null,
_imageWidget: null,
_imageClickHandler: null,
_dndEnabled: false,
_currentImagePath: null,
_clientSelected: false,
_isTreeItem: false,
_columnWidget: null,
constructor: function(opts) {
opts = (opts || {});
this._isTreeItem = opts.isTreeItem;
opts.inTable = true;
$super.constructor.call(this, opts);
},
_initLayout: function() {
},
isLayoutMeasureable: function(deep) {
return true;
},
init: function() {
this.setLeftFrozen(this._columnWidget.isLeftFrozen());
this.setRightFrozen(this._columnWidget.isRightFrozen());
this.setOrder(this._columnWidget.getOrder());
this.setCurrentColumn(this._columnWidget.isCurrent());
this.setDndEnabled(this.getTableWidgetBase().isDndItemEnabled());
},
destroy: function() {
this._treeAnchor = null;
if (this._imageClickHandler) {
this._imageClickHandler();
this._imageClickHandler = null;
}
if (this._imageWidget) {
this._imageWidget.destroy();
this._imageWidget = null;
}
this._columnWidget = null;
$super.destroy.call(this);
},
setHidden: function(hidden) {
if (this._hidden !== Boolean(hidden)) {
this._hidden = Boolean(hidden);
if (this._element) {
if (this._hidden) {
this.addClass("hidden");
} else {
this.removeClass("hidden");
}
}
}
},
requestFocus: function(domEvent) {
let tableWidget = this.getTableWidgetBase();
if (tableWidget) {
tableWidget.requestFocusFromWidget(this._children[0], domEvent);
}
},
manageMouseClick: function(domEvent) {
if (domEvent.target === this.getElement()) {
this.getTableWidgetBase().requestFocusFromWidget(this._children[0], domEvent);
return false;
}
if (domEvent.target === this._treeAnchor) {
let index = this.getRowIndex();
let tableWidget = this.getTableWidgetBase();
tableWidget.emit(context.constants.widgetEvents.toggleClick, index);
return false;
}
return true;
},
manageMouseDblClick: function(domEvent) {
if (domEvent.target === this._treeAnchor) {
return false;
}
return true;
},
addChildWidget: function(widget, options) {
if (this._children.length !== 0) {
throw "A item only contain a single child";
}
this._layoutInformation = widget.getLayoutInformation();
$super.addChildWidget.call(this, widget, options);
if (this._isTreeItem) {
this._treeAnchor = document.createElement("span");
this._treeAnchor.addClass("gbc_TreeAnchor");
this._element.prependChild(this._treeAnchor);
this.setLeaf(true);
}
},
setBackgroundColor: function(color) {
if (this._backgroundColor !== color) {
this._backgroundColor = color;
this.setStyle({
"background-color": color && !this._ignoreBackgroundColor ? color : null
});
}
},
setDndEnabled: function(b) {
if (this._dndEnabled !== b) {
this._dndEnabled = b;
if (b) {
this._element.setAttribute("draggable", "true");
} else {
this._element.removeAttribute("draggable");
}
}
},
isTreeItem: function() {
return this._isTreeItem;
},
setLeaf: function(leaf) {
if (this.isTreeItem()) {
this.setAriaExpanded(null);
if (leaf) {
this._treeAnchor.removeClass("treeExpanded");
this._treeAnchor.removeClass("treeCollapsed");
}
this._treeAnchor.toggleClass("treeLeaf", leaf);
}
},
isLeaf: function() {
return this.isTreeItem() && this._treeAnchor.hasClass("treeLeaf");
},
setExpanded: function(expanded) {
if (this.isTreeItem() && !this.isLeaf()) {
this.setAriaExpanded(expanded);
this._treeAnchor.toggleClass("treeExpanded", "treeCollapsed", expanded);
if (gbc.qaMode) {
let qaElement = this.getContainerElement().querySelector("[data-gqa-name]");
if (qaElement) {
qaElement.setAttribute('data-gqa-expanded', expanded.toString());
}
}
}
},
setAriaExpanded: function(expanded) {
this.setAriaAttribute("expanded", expanded);
if (this._children[0]) {
this._children[0].setAriaAttribute("expanded", expanded);
}
},
isReversed: function() {
return this.getParentWidget().isReversed();
},
setDepth: function(depth) {
let depthObj = {};
depthObj["padding-" + this.getStart()] = depth + 'em';
this.setStyle(depthObj);
},
setLeftFrozen: function(b) {
this.toggleClass("leftFrozen", b);
this.toggleClass("lastLeftFrozen", this.getColumnWidget().isLastLeftFrozen());
if (b) {
this.setStyle({
"left": this.getColumnWidget().getLeftFrozenPosition() + "px"
});
}
},
setRightFrozen: function(b) {
this.toggleClass("rightFrozen", b);
this.toggleClass("firstRightFrozen", this.getColumnWidget().isFirstRightFrozen());
if (b) {
this.setStyle({
"right": this.getColumnWidget().getRightFrozenPosition() + "px"
});
}
},
setCurrentColumn: function(b) {
this.toggleClass("currentColumn", b);
},
setOrder: function(colIndex) {
let rowWidget = this.getParentWidget();
let colIndexString = colIndex === -1 ? "0" : colIndex.toString();
while (colIndexString.length < 3) {
colIndexString = "0" + colIndexString;
}
let order = parseInt(rowWidget.getRowIndex() + "" + colIndexString);
this.setStyle({
"order": order
});
},
setImage: function(path) {
if (this._currentImagePath !== path) {
if (path && path !== "") {
if (!this._imageWidget) {
let opts = this.getBuildParameters();
opts.inTable = true;
this._imageWidget = cls.WidgetFactory.createWidget("ImageWidget", opts);
this._imageWidget.getElement().addClass("gbc_RTableItemImage");
this._imageWidget.setParentWidget(this);
this._imageClickHandler = this._imageWidget.when(context.constants.widgetEvents.click, function(event) {
this.getTableWidgetBase().requestFocusFromWidget(this._children[0], event);
}.bind(this));
this._element.prependChild(this._imageWidget.getElement());
}
this._imageWidget.setSrc(path, true);
this._imageWidget.setHidden(false);
} else if (this._imageWidget) {
this._imageWidget.setHidden(true);
}
this._currentImagePath = path;
}
},
isClientSelected: function() {
return this._clientSelected;
},
setClientSelected: function(selected) {
this._clientSelected = selected;
},
getColumnWidget: function() {
return this._columnWidget;
},
setColumnWidget: function(colWidget) {
this._columnWidget = colWidget;
},
getRowIndex: function() {
let parent = this.getParentWidget();
if (parent) {
return parent.getRowIndex();
}
return -1;
},
onDragStart: function(evt) {
if (window.browserInfo.isFirefox) {
try {
evt.dataTransfer.setData('text/plain', '');
} catch (ex) {
console.error("evt.dataTransfer.setData('text/plain', ''); not supported");
}
}
this._columnWidget.emit(gbc.constants.widgetEvents.tableDragStart, this.getRowIndex(), evt);
},
onDragEnd: function() {
this._columnWidget.emit(gbc.constants.widgetEvents.tableDragEnd);
},
onDragOver: function(evt) {
this._columnWidget.emit(gbc.constants.widgetEvents.tableDragOver, this.getRowIndex(), evt);
},
onDragLeave: function(evt) {
this._columnWidget.emit(gbc.constants.widgetEvents.tableDragLeave, this.getRowIndex(), evt);
},
onDragEnter: function(evt) {
this._columnWidget.emit(gbc.constants.widgetEvents.tableDragEnter, this.getRowIndex(), evt);
},
onDrop: function() {
this._columnWidget.emit(gbc.constants.widgetEvents.tableDrop, this.getRowIndex());
}
};
});
cls.WidgetFactory.registerBuilder('RTableItem', cls.RTableItemWidget);
});