123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
"use strict";
modulum('GroupWidget', ['WidgetGridLayoutBase', 'WidgetFactory'],
function(context, cls) {
cls.GroupWidget = context.oo.Class(cls.WidgetGridLayoutBase, function($super) {
return {
__name: "GroupWidget",
_title: null,
_titleClickHandler: null,
_isCollapsible: false,
_gridWidthHandle: null,
_groupWidgetContent: null,
_groupContent: null,
_groupIdentifier: null,
setGroupIdentifier: function(id) {
this._groupIdentifier = id;
},
_initElement: function() {
$super._initElement.call(this);
this._title = cls.WidgetFactory.createWidget("GroupTitle", this.getBuildParameters());
this._titleClickHandler = this._title.when(context.constants.widgetEvents.click, this._onTitleClick.bind(this));
this._groupWidgetContent = this._element.getElementsByClassName("gbc_GroupWidgetContent")[0];
this._groupWidgetContent.prependChild(this._title.getElement());
this._groupContent = this._groupWidgetContent.getElementsByClassName("containerElement")[0];
this.setCollapserPosition(gbc.ThemeService.getValue("gbc-GroupWidget-collapser-position"));
},
_initLayout: function() {
this._layoutInformation = new cls.LayoutInformation(this);
this._layoutEngine = new cls.GroupLayoutEngine(this);
this._gridWidthHandle = this.getLayoutInformation().onGridInfoChanged(this._onGridWidthChanged.bind(this));
},
destroy: function() {
if (this._titleClickHandler) {
this._titleClickHandler();
this._titleClickHandler = null;
}
if (this._title) {
this._title.destroy();
this._title = null;
}
if (this._gridWidthHandle) {
this._gridWidthHandle();
this._gridWidthHandle = null;
}
this._groupWidgetContent = null;
this._groupContent = null;
$super.destroy.call(this);
},
_onGridWidthChanged: function() {
this._title.getLayoutInformation().setGridWidth(this.getLayoutInformation().getGridWidth());
},
setGridChildrenInParent: function(isGridChildrenInParent) {
if (this._isGridChildrenInParent !== isGridChildrenInParent) {
if (!isGridChildrenInParent) {
this._groupContent.removeClass("gridChildrenInParent");
}
$super.setGridChildrenInParent.call(this, isGridChildrenInParent);
if (isGridChildrenInParent) {
this._groupContent.addClass("gridChildrenInParent");
}
}
},
setText: function(text) {
this._title.setText(text);
this.getLayoutEngine().forceMeasurement();
this.getLayoutEngine().invalidateMeasure();
},
getText: function() {
return this._title.getText();
},
_onTitleClick: function() {
if (this._isCollapsible) {
this._updateCollapsedState();
this.emit(context.constants.widgetEvents.toggleClick);
var session = context.SessionService.getCurrent();
if (session) {
var app = session.getCurrentApplication();
if (app) {
app.layout.when(context.constants.widgetEvents.afterLayout, function() {
var pw = this.getParentWidget();
while (pw) {
pw.emit(context.constants.widgetEvents.splitViewChange, true);
pw = pw.getParentWidget();
}
}.bind(this), true);
}
}
}
},
setCollapsible: function(collapsible) {
this._isCollapsible = Boolean(collapsible);
this._title.setCollapsible(this._isCollapsible);
if (this._isCollapsible) {
this.setCollapsed(Boolean(context.StoredSettingsService
.getGroupCollapsedState(this._groupIdentifier.formName, this._groupIdentifier.id)));
}
},
setCollapsed: function(collapsed) {
var result = false;
if (this._isCollapsible) {
if (this._title.isCollapsed() !== Boolean(collapsed)) {
this._title.setCollapsed(collapsed);
this._updateCollapsedState();
result = true;
}
}
return result;
},
setCollapserPosition: function(pos) {
this._title.setCollapserPosition(pos);
},
_updateCollapsedState: function() {
this._layoutEngine._willRenderContent = !this._title.isCollapsed();
context.StoredSettingsService.setGroupCollapsedState(this._groupIdentifier.formName,
this._groupIdentifier.id, Boolean(this._title.isCollapsed()));
this.getLayoutEngine().forceMeasurement();
this.getLayoutEngine().invalidateMeasure();
}
};
});
cls.WidgetFactory.registerBuilder('Group', cls.GroupWidget);
});