radio/magnus/lib/wModel/proxy/pane.js

70 lines
2.2 KiB
JavaScript

"use strict";
var MVocabulary = require("./vocabulary");
var Address = require("../../wType/address");
var Boolean = require("../../wType/boolean");
var Uint64 = require("../../wType/uint64");
var String = require("../../wType/string");
var Vocabulary = require("../../wType/vocabulary");
var Vector = require("../../wType/vector");
var Pane = MVocabulary.inherit({
"className": "Pane",
"constructor": function(address, controllerAddress, socket, actions) {
MVocabulary.fn.constructor.call(this, address, controllerAddress, socket);
this._actions = new Vector();
this._createActions(actions || []);
if (this.constructor.pageAddress) {
this.hasPageLink = true;
var id = address.back();
this._pageLink = this.constructor.pageAddress["+"](new Address([id.toString()]));
}
},
"destructor": function() {
this._actions.destructor();
if (this.hasPageLink) {
this._pageLink.destructor();
}
MVocabulary.fn.destructor.call(this);
},
"_createActions": function(actions) {
for (var i = 0; i < actions.length; ++i) {
var action = actions[i];
var actionVC = new Vocabulary();
actionVC.insert("type", new Uint64(action.type));
var supported = false;
switch (action.type) {
case 0: //this type of actions has only action itself, no additional arguments, what to do is desctibed in the view
actionVC.insert("action", new String(action.action));
supported = true;
break;
}
if (supported) {
this._actions.push(actionVC);
} else {
actionVC.destructor();
}
}
},
"_getAllData": function() {
var vc = this.controller.data.clone();
vc.insert("hasPageLink", new Boolean(this.hasPageLink));
vc.insert("actions", this._actions.clone());
if (this.hasPageLink) {
vc.insert("pageLink", this._pageLink.clone());
}
return vc;
}
});
module.exports = Pane;