123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
"use strict";
modulum('PageWidget', ['WidgetGroupBase'],
function(context, cls) {
cls.PageWidget = context.oo.Class(cls.WidgetGroupBase, function($super) {
return {
__name: "PageWidget",
_title: null,
_clickHandler: null,
_onActivationHandler: null,
_pageActivateHandler: null,
_pageDisableHandler: null,
_initElement: function() {
$super._initElement.call(this);
this._title = cls.WidgetFactory.createWidget("PageTitle", this.getBuildParameters());
this._clickHandler = this._title.when(context.constants.widgetEvents.click, function(event) {
var folderWidget = this.getParentWidget();
if (folderWidget) {
folderWidget.onTitleClick(this);
this.emit(context.constants.widgetEvents.click, event);
}
}.bind(this));
this._onActivationHandler = this.when(context.constants.widgetEvents.ready, this._onActivation.bind(this));
this.setAriaAttribute("labelledby", this._title.getRootClassName());
},
_initLayout: function() {
this._layoutInformation = new cls.PageLayoutInformation(this);
this._layoutEngine = new cls.PageLayoutEngine(this);
},
destroy: function() {
if (this._pageActivateHandler) {
this._pageActivateHandler();
this._pageActivateHandler = null;
}
if (this._pageDisableHandler) {
this._pageDisableHandler();
this._pageDisableHandler = null;
}
if (this._onActivationHandler) {
this._onActivationHandler();
this._onActivationHandler = null;
}
if (this._clickHandler) {
this._clickHandler();
this._clickHandler = null;
}
this._title.destroy();
this._title = null;
$super.destroy.call(this);
},
activate: function() {
this.emit(context.constants.widgetEvents.activate, this);
},
onActivate: function(hook) {
return this.when(context.constants.widgetEvents.activate, hook);
},
disable: function() {
this.emit(context.constants.widgetEvents.disable);
},
onDisable: function(hook) {
return this.when(context.constants.widgetEvents.disable, hook);
},
_onActivation: function(event, widget, parentPageWidget) {
if (parentPageWidget) {
this._pageActivateHandler = parentPageWidget.onActivate(this.activate.bind(this));
this._pageDisableHandler = parentPageWidget.onDisable(this.disable.bind(this));
}
},
getPageIndex: function() {
var parent = this.getParentWidget();
if (parent) {
return parent.getChildren().indexOf(this);
}
return -1;
},
getTitleWidget: function() {
return this._title;
},
addChildWidget: function(widget, options) {
if (this._children.length !== 0) {
throw "A page can only contain a single child";
}
$super.addChildWidget.call(this, widget, options);
},
setText: function(text) {
this._title.setText(text);
},
getText: function() {
return this._title.getText();
},
setTitle: function(title) {
this._title.setTitle(title);
},
getTitle: function() {
return this._title.getTitle();
},
setImage: function(image) {
this._title.setImage(image);
},
getImage: function() {
return this._title.getImage();
},
setHidden: function(hidden) {
if (this._hidden !== hidden) {
this.getParentWidget().emit(context.constants.widgetEvents.pageVisibility);
}
$super.setHidden.call(this, hidden);
this._title.setHidden(hidden);
if (this.getParentWidget().getCurrentPage() === this && this.isHidden()) {
this.getParentWidget().updateCurrentPage();
}
},
isVisible: function() {
return this.getParentWidget().getCurrentPage() === this && !this.isHidden();
},
isLayoutMeasureable: function(deep) {
return true;
}
};
});
cls.WidgetFactory.registerBuilder('Page', cls.PageWidget);
});