123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
"use strict";
modulum('ListViewRowWidget', ['WidgetGroupBase'],
function(context, cls) {
cls.ListViewRowWidget = context.oo.Class(cls.WidgetGroupBase, function($super) {
return {
__name: "ListViewRowWidget",
_current: false,
_imageWidget: null,
_horizontalLayout: false,
_imageElement: null,
_rowBoundDecoratorWidget: null,
_initElement: function() {
this._ignoreLayout = true;
$super._initElement.call(this);
this._imageElement = this._element.getElementsByClassName("gbc_ListViewRowImage")[0];
this._element.onDoubleTap("ListViewRowWidget", this._onDoubleClick.bind(this));
},
_initLayout: function() {
},
destroy: function() {
this._element.offDoubleTap("ListViewRowWidget");
if (this._imageWidget) {
this._imageWidget.destroy();
this._imageWidget = null;
}
if (this._rowBoundDecoratorWidget) {
this._rowBoundDecoratorWidget.destroy();
this._rowBoundDecoratorWidget = null;
}
this._imageElement = null;
this.destroyChildren();
$super.destroy.call(this);
},
requestFocus: function(domEvent) {
var listViewWidget = this.getTableWidgetBase();
if (listViewWidget) {
listViewWidget.requestFocusFromWidget(this._children[0], domEvent);
}
},
manageMouseClick: function(domEvent) {
var childClicked = false;
for (var i = 0; !childClicked && i < this._children.length; ++i) {
childClicked = domEvent.target.isElementOrChildOf(this._children[i].getElement());
}
var listViewWidget = this.getTableWidgetBase();
if (!childClicked) {
this.requestFocus(domEvent);
}
var clickInRowbound = listViewWidget.hasRowBound() && domEvent.target.isElementOrChildOf(this._rowBoundDecoratorWidget
.getElement());
if (!listViewWidget.isRowActionTriggerByDoubleClick() && !clickInRowbound) {
listViewWidget.emit(context.constants.widgetEvents.rowAction);
return false;
}
return true;
},
manageMouseDblClick: function(domEvent) {
this._onDoubleClick(domEvent);
return false;
},
_onDoubleClick: function(event) {
var listViewWidget = this.getTableWidgetBase();
if (listViewWidget && listViewWidget.isRowActionTriggerByDoubleClick()) {
listViewWidget.emit(context.constants.widgetEvents.rowAction);
}
},
addChildWidget: function(widget, options) {
if (this._children.length > 2) {
throw "A listview item can only contain two children";
}
$super.addChildWidget.call(this, widget, options);
},
setHorizontalLayout: function(horizontal) {
this._horizontalLayout = horizontal;
this._element.toggleClass('horizontal', horizontal);
},
isHorizontalLayout: function() {
return this._horizontalLayout;
},
setImage: function(path) {
if (path && path !== "") {
if (!this._imageWidget) {
this._imageWidget = cls.WidgetFactory.createWidget("ImageWidget", this.getBuildParameters());
this._imageWidget.setParentWidget(this);
this._imageElement.appendChild(this._imageWidget.getElement());
}
this._imageWidget.setSrc(path);
if (window.browserInfo.isIE) {
var width = null;
if (path.startsWith("font:")) {
width = this.getParentWidget().getRowHeight() + "px";
}
this.setStyle(" .gbc_ImageWidget", {
"width": width
});
}
this._imageWidget.getElement().removeClass("hidden");
this._imageElement.removeClass("hidden");
} else if (this._imageWidget) {
this._imageElement.addClass("hidden");
}
},
getLineCount: function() {
if (this._horizontalLayout) {
return Math.min(this.getChildren().length, 1);
} else {
return this.getChildren().length;
}
},
setCurrent: function(current) {
if (this._current !== current) {
this._current = current;
if (current) {
this._element.addClass("currentRow");
} else {
this._element.removeClass("currentRow");
}
}
},
isLayoutMeasureable: function(deep) {
return true;
},
addRowBoundDecorator: function() {
if (this._rowBoundDecoratorWidget === null) {
this._rowBoundDecoratorWidget = cls.WidgetFactory.createWidget("RowBoundDecorator", this.getBuildParameters());
this._rowBoundDecoratorWidget.setParentWidget(this);
this._element.appendChild(this._rowBoundDecoratorWidget.getElement());
}
}
};
});
cls.WidgetFactory.registerBuilder('ListViewRow', cls.ListViewRowWidget);
});