123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
"use strict";
modulum('TableColumnAggregateWidget', ['WidgetBase', 'WidgetFactory'],
function(context, cls) {
cls.TableColumnAggregateWidget = context.oo.Class(cls.WidgetBase, function($super) {
return {
__name: "TableColumnAggregateWidget",
_textElement: null,
_textAlign: null,
constructor: function(opts) {
opts = (opts || {});
opts.inTable = true;
$super.constructor.call(this, opts);
},
_initElement: function() {
$super._initElement.call(this);
this._textElement = this._element.getElementsByClassName("gbc_TableAggregateText")[0];
},
_initLayout: function() {
},
destroy: function() {
this._textElement = null;
$super.destroy.call(this);
},
setText: function(text) {
var tableColumn = this.getParentWidget();
if (tableColumn.getChildren().length > 0) {
var item = tableColumn.getColumnItem(0);
var widget = item.getChildren().length > 0 ? item.getChildren()[0] : null;
if (widget && widget.getFormat) {
text = cls.DateTimeHelper.toDbDateFormat(text, widget.getFormat());
}
}
this._setTextContent(text, "_textElement");
},
getText: function() {
return this._textElement.textContent;
},
setTextAlign: function(align) {
this._textAlign = align;
this.setStyle(".gbc_TableAggregateText", {
"text-align": align
});
},
computeWidth: function(aggregateWidth) {
var tableColumn = this.getParentWidget();
if (tableColumn.getWidth() === null) {
return;
}
this.setStyle({
"width": aggregateWidth + "px"
});
this.setStyle(".gbc_TableAggregateText", {
"border-left": null,
"border-right": null,
"margin-left": null
});
var isRightTextAlign = (this._textAlign === "right");
var isCenterTextAlign = (this._textAlign === "center");
var isLeftTextAlign = (this._textAlign === "left" || this._textAlign === null);
if (isLeftTextAlign || isCenterTextAlign) {
this.setStyle(".gbc_TableAggregateText", {
"margin-left": (aggregateWidth - tableColumn.getWidth()) + "px",
});
}
var borderColor = context.ThemeService.getValue("gbc-TableWidget-inner-border-color");
if (isRightTextAlign) {
this.setStyle(".gbc_TableAggregateText", {
"border-right": "solid 1px " + borderColor
});
} else if (isLeftTextAlign && tableColumn.getOrderedColumnIndex() > 0) {
this.setStyle(".gbc_TableAggregateText", {
"border-left": "solid 1px " + borderColor
});
}
},
getWidthStyle: function() {
return this.getStyle("width");
},
setOrder: function(index) {
this.setStyle({
"order": index
});
}
};
});
cls.WidgetFactory.registerBuilder('TableColumnAggregate', cls.TableColumnAggregateWidget);
});