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

70 lines
2.2 KiB
JavaScript
Raw Normal View History

2018-08-04 21:46:25 +00:00
"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");
2018-08-04 21:46:25 +00:00
var Pane = MVocabulary.inherit({
"className": "Pane",
"constructor": function(address, controllerAddress, socket, actions) {
2018-08-04 21:46:25 +00:00
MVocabulary.fn.constructor.call(this, address, controllerAddress, socket);
this._actions = new Vector();
this._createActions(actions || []);
2018-08-04 21:46:25 +00:00
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();
}
}
},
2018-08-04 21:46:25 +00:00
"_getAllData": function() {
var vc = this.controller.data.clone();
vc.insert("hasPageLink", new Boolean(this.hasPageLink));
vc.insert("actions", this._actions.clone());
2018-08-04 21:46:25 +00:00
if (this.hasPageLink) {
vc.insert("pageLink", this._pageLink.clone());
}
2018-08-04 21:46:25 +00:00
return vc;
}
});
module.exports = Pane;