123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449
"use strict";
modulum('TableColumnItemWidget', ['WidgetGroupBase'],
function(context, cls) {
cls.TableColumnItemWidget = context.oo.Class(cls.WidgetGroupBase, function($super) {
return {
__name: "TableColumnItemWidget",
_treeAnchor: null,
_imageWidget: null,
_imageClickHandler: null,
_imageSpanElement: null,
_dndEnabled: false,
_currentImagePath: null,
_current: false,
_clientSelected: false,
constructor: function(opts) {
opts = (opts || {});
var isTreeItem = opts.isTreeItem;
opts.inTable = true;
$super.constructor.call(this, opts);
if (isTreeItem) {
this._treeAnchor = document.createElement("span");
this._treeAnchor.addClass("gbc_TreeAnchor");
this._element.prependChild(this._treeAnchor);
this._element.onDoubleTap("TreeAnchor", this.manageMouseClick.bind(this));
this.setLeaf(true);
}
},
_initLayout: function() {
},
destroy: function() {
if (this._treeAnchor) {
this._element.offDoubleTap("TreeAnchor");
}
if (this._imageClickHandler) {
this._imageClickHandler();
this._imageClickHandler = null;
}
if (this._imageWidget) {
this._imageWidget.destroy();
this._imageWidget = null;
}
$super.destroy.call(this);
},
requestFocus: function(domEvent) {
var tableWidget = this.getTableWidgetBase();
if (tableWidget) {
var widget = tableWidget.getWidgetAt(tableWidget.getCurrentColumn(), this.getItemIndex());
tableWidget.requestFocusFromWidget(widget, domEvent);
}
},
manageMouseClick: function(domEvent) {
if (domEvent.target === this._treeAnchor) {
var index = this.getItemIndex();
this.getParentWidget().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";
}
$super.addChildWidget.call(this, widget, options);
},
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 Boolean(this._treeAnchor);
},
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);
var 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);
}
},
isExpanded: function() {
return this.isTreeItem();
},
isReversed: function() {
return this._parentWidget.isReversed();
},
updateVisibility: function() {
var visibleRows = this.getParentWidget().getParentWidget().getVisibleRows();
this.setHidden(this.getItemIndex() >= visibleRows);
},
setDepth: function(depth) {
var depthObj = {};
depthObj["padding-" + this.getStart()] = depth + 'em';
this.setStyle(depthObj);
},
getDepth: function() {
var depth = this.getStyle('padding-left');
if (depth) {
return parseInt(depth, 10);
}
return 0;
},
setCurrent: function(current) {
if (this._current !== current) {
this._current = current;
if (current) {
this._element.addClass("currentRow");
this._children[0].addClass("currentRow");
} else {
this._element.removeClass("currentRow");
this._children[0].removeClass("currentRow");
}
this.setAriaAttribute("labeledby", this._children[0].getRootClassName());
this.setAriaSelection();
}
},
setImage: function(path) {
if (this._currentImagePath !== path) {
if (path && path !== "") {
if (!this._imageSpanElement) {
this._imageSpanElement = document.createElement("span");
this._imageSpanElement.addClass("gbc_TableItemImage");
this._element.insertBefore(this._imageSpanElement, this.getContainerElement());
}
if (!this._imageWidget) {
var opts = this.getBuildParameters();
opts.inTable = true;
this._imageWidget = cls.WidgetFactory.createWidget("ImageWidget", opts);
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._imageSpanElement.prependChild(this._imageWidget.getElement());
}
this._imageSpanElement.addClass("visibleImage");
this._imageWidget.setSrc(path);
this._imageWidget.setHidden(false);
} else if (this._imageWidget) {
this._imageSpanElement.removeClass("visibleImage");
this._imageWidget.setHidden(true);
}
this._currentImagePath = path;
}
},
isCurrent: function() {
return this._element.hasClass("currentRow");
},
setSelected: function(selected) {
var children = this.getChildren();
if (children.length !== 0) {
children[0].setIgnoreBackgroundColor(Boolean(selected));
}
this._element.toggleClass("selectedRow", Boolean(selected));
},
isSelected: function() {
return this._element.hasClass("selectedRow");
},
isClientSelected: function() {
return this._clientSelected;
},
setClientSelected: function(selected) {
this._clientSelected = selected;
},
getItemIndex: function() {
var parent = this.getParentWidget();
if (parent) {
return parent.getChildren().indexOf(this);
}
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");
}
}
var tableColumn = this.getParentWidget();
tableColumn.emit(gbc.constants.widgetEvents.tableDragStart, this.getItemIndex(), evt);
},
onDragEnd: function() {
var tableColumn = this.getParentWidget();
tableColumn.emit(gbc.constants.widgetEvents.tableDragEnd);
},
onDragOver: function(evt) {
var tableColumn = this.getParentWidget();
tableColumn.emit(gbc.constants.widgetEvents.tableDragOver, this.getItemIndex(), evt);
},
onDragLeave: function(evt) {
var tableColumn = this.getParentWidget();
tableColumn.emit(gbc.constants.widgetEvents.tableDragLeave, this.getItemIndex(), evt);
},
onDragEnter: function(evt) {
var tableColumn = this.getParentWidget();
tableColumn.emit(gbc.constants.widgetEvents.tableDragEnter, this.getItemIndex(), evt);
},
onDrop: function() {
var tableColumn = this.getParentWidget();
tableColumn.emit(gbc.constants.widgetEvents.tableDrop, this.getItemIndex());
},
isLayoutMeasureable: function(deep) {
return true;
}
};
});
cls.WidgetFactory.registerBuilder('TableColumnItem', cls.TableColumnItemWidget);
});