2018-08-04 21:46:25 +00:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
(function() {
|
|
|
|
var moduleName = "views/pane";
|
|
|
|
|
|
|
|
var defineArray = [];
|
|
|
|
defineArray.push("views/view");
|
|
|
|
defineArray.push("views/layout");
|
|
|
|
defineArray.push("views/label");
|
|
|
|
defineArray.push("views/image");
|
2018-11-28 06:54:14 +00:00
|
|
|
defineArray.push("views/button");
|
2018-08-04 21:46:25 +00:00
|
|
|
defineArray.push("lib/wController/localModel");
|
|
|
|
|
|
|
|
define(moduleName, defineArray, function() {
|
|
|
|
var View = require("views/view");
|
|
|
|
var Layout = require("views/layout");
|
|
|
|
var Label = require("views/label");
|
|
|
|
var Image = require("views/image");
|
2018-11-28 06:54:14 +00:00
|
|
|
var Button = require("views/button");
|
2018-08-04 21:46:25 +00:00
|
|
|
var LM = require("lib/wController/localModel");
|
|
|
|
|
|
|
|
var Pane = Layout.inherit({
|
|
|
|
"constructor": function PaneView (controller, options) {
|
|
|
|
var base = {
|
|
|
|
|
|
|
|
};
|
|
|
|
W.extend(base, options);
|
|
|
|
Layout.fn.constructor.call(this, controller, options);
|
|
|
|
|
2019-02-01 22:24:09 +00:00
|
|
|
this._aCount = 0;
|
2018-08-04 21:46:25 +00:00
|
|
|
this._initProxy();
|
|
|
|
this.addClass("hoverable");
|
|
|
|
this._e.addEventListener("click", this._proxy.onClick, false);
|
|
|
|
|
|
|
|
var lm = this._labelModel = new LM({
|
|
|
|
fontFamily: "casualFont"
|
|
|
|
});
|
|
|
|
|
|
|
|
if (this._f.hasImage()) {
|
|
|
|
this._image = new Image(this._f.image);
|
|
|
|
this.append(this._image, Layout.Aligment.CenterCenter);
|
|
|
|
}
|
|
|
|
|
|
|
|
var name = this._f.data.at("name");
|
|
|
|
this._labelModel.setData(name || "");
|
|
|
|
this._labelView = new Label(this._labelModel);
|
|
|
|
this._labelView.on("changeLimits", this._onLabelChangeLimits, this);
|
|
|
|
this.append(this._labelView, Layout.Aligment.CenterCenter);
|
|
|
|
|
|
|
|
this._f.on("newElement", this._onNewElement, this);
|
|
|
|
this._f.on("removeElement", this._onRemoveElement, this);
|
2018-11-28 06:54:14 +00:00
|
|
|
this._f.on("addAction", this._onAddAction, this);
|
|
|
|
|
|
|
|
var acts = this._f.getActions();
|
|
|
|
for (var i = 0; i < acts.length; ++i) {
|
|
|
|
this._onAddAction(acts[i]);
|
|
|
|
}
|
2018-08-04 21:46:25 +00:00
|
|
|
|
|
|
|
this._uncyclic.push(function() {
|
|
|
|
lm.destructor();
|
|
|
|
});
|
|
|
|
},
|
|
|
|
"destructor": function() {
|
|
|
|
this._e.removeEventListener("click", this._proxy.onClick, false);
|
|
|
|
|
|
|
|
Layout.fn.destructor.call(this);
|
|
|
|
},
|
2018-11-28 06:54:14 +00:00
|
|
|
"_onAddAction": function(model) {
|
2019-02-01 22:24:09 +00:00
|
|
|
var alignment;
|
|
|
|
switch (this._aCount) {
|
|
|
|
case 0:
|
|
|
|
alignment = Layout.Aligment.LeftTop;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
alignment = Layout.Aligment.RightTop;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
alignment = Layout.Aligment.RightBottom;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
alignment = Layout.Aligment.LeftBottom;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
console.warn("Pane can't place more then 4 action, ignoring");
|
|
|
|
break
|
|
|
|
}
|
|
|
|
if (alignment !== undefined) {
|
|
|
|
var view = new Button(model);
|
|
|
|
this.append(view, alignment);
|
|
|
|
this._aCount++;
|
|
|
|
}
|
2018-11-28 06:54:14 +00:00
|
|
|
},
|
2018-08-04 21:46:25 +00:00
|
|
|
"_applyProperties": function() {
|
|
|
|
this._onAddProperty("secondaryColor", "background");
|
|
|
|
|
|
|
|
Layout.fn._applyProperties.call(this);
|
|
|
|
},
|
|
|
|
"_initProxy": function() {
|
|
|
|
this._proxy = {
|
|
|
|
onClick: this._onClick.bind(this)
|
|
|
|
};
|
|
|
|
},
|
|
|
|
"_onClick": function() {
|
2018-11-28 06:54:14 +00:00
|
|
|
if (this._f.hasPageLink()) {
|
|
|
|
this.trigger("activate", this._f.getPageLink());
|
2018-08-04 21:46:25 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
"_onLabelChangeLimits": function(label) {
|
|
|
|
this.setMinSize(label._o.minWidth, this._h);
|
|
|
|
},
|
|
|
|
"_onNewElement": function(key, value) {
|
|
|
|
switch (key) {
|
|
|
|
case "name":
|
|
|
|
this._labelModel.setData(value.toString());
|
|
|
|
break;
|
|
|
|
case "image":
|
|
|
|
this._image = new Image(this._f.image);
|
|
|
|
this.append(this._image, Layout.Aligment.LeftTop, 0);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"_onRemoveElement": function(key) {
|
|
|
|
switch (key) {
|
|
|
|
case "name":
|
|
|
|
this._labelModel.setData("");
|
|
|
|
break;
|
|
|
|
case "image":
|
|
|
|
this._image.destructor();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"setSize": function(w, h) {
|
|
|
|
Layout.fn.setSize.call(this, w, h);
|
|
|
|
|
|
|
|
if (this._f.hasImage()) {
|
|
|
|
this._image.setSize(w, h);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return Pane;
|
|
|
|
});
|
|
|
|
})();
|