123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
"use strict";
modulum('GroupTitleWidget', ['WidgetBase', 'WidgetFactory'],
function(context, cls) {
cls.GroupTitleWidget = context.oo.Class(cls.WidgetBase, function($super) {
return {
__name: "GroupTitleWidget",
_textContainer: null,
_isCollapsible: false,
_collapser: null,
_collapserIcon: null,
_collapsed: false,
_isEmpty: true,
_initLayout: function() {
this._layoutInformation = new cls.LayoutInformation(this);
this._layoutEngine = new cls.LeafLayoutEngine(this);
this._layoutInformation.getSizePolicyConfig().setMode('dynamic');
},
_initElement: function() {
$super._initElement.call(this);
this._textContainer = this._element.getElementsByTagName('span')[0];
this._collapser = this._element.getElementsByTagName('span')[1];
this._collapserIcon = this._element.getElementsByTagName('i')[0];
},
destroy: function() {
this._textContainer = null;
this._collapser = null;
this._collapserIcon = null;
$super.destroy.call(this);
},
setText: function(text) {
this.domAttributesMutator(function() {
if (/^[ \t]+$/.test(text)) {
this._textContainer.innerHTML = " ";
} else {
this._textContainer.textContent = text;
}
this._element.toggleClass("empty", !text);
}.bind(this));
this._isEmpty = !text;
this.getLayoutEngine().forceMeasurement();
this.getLayoutEngine().invalidateMeasure();
},
getText: function() {
return this._textContainer.textContent;
},
setCollapsible: function(collapsible) {
this._isCollapsible = Boolean(collapsible);
this._element.toggleClass("collapsible", this._isCollapsible);
},
isCollapsed: function() {
return this._collapsed;
},
manageMouseClick: function(domEvent) {
if (!this._isEmpty) {
this._collapsed = !this._collapsed;
this._updateToggle();
this.emit(context.constants.widgetEvents.click);
}
return true;
},
setCollapsed: function(collapsed) {
if (this._collapsed !== Boolean(collapsed)) {
this._collapsed = Boolean(collapsed);
this._updateToggle();
}
},
_updateToggle: function() {
this._collapserIcon.toggleClass("zmdi-chevron-down", !this._collapsed).toggleClass("zmdi-chevron-right", this._collapsed);
},
setCollapserPosition: function(pos) {
this.removeClass("collapser-position-right");
this.removeClass("collapser-position-left");
this.addClass("collapser-position-" + pos);
}
};
});
cls.WidgetFactory.registerBuilder('GroupTitle', cls.GroupTitleWidget);
});