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

67 lines
2.1 KiB
JavaScript

"use strict";
var Vocabulary = require("../../wType/vocabulary");
var Uint64 = require("../../wType/uint64");
var String = require("../../wType/string");
var Vector = require("../../wType/vector");
var Catalogue = require("./catalogue");
var PanesList = Catalogue.inherit({
"className": "PanesList",
"constructor": function(address, ctrlAddr, ctrlOpts, socket, actions) {
Catalogue.fn.constructor.call(this, address, ctrlAddr, ctrlOpts, socket);
this._actions = new Vector();
this._createActions(actions || []);
},
"destructor": function() {
this._actions.destructor();
Catalogue.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();
}
}
},
"_h_get": function(ev) {
if (this.ready) {
var vc = new Vocabulary();
vc.insert("data", this._getAllData());
vc.insert("actions", this._actions.clone());
this.response(vc, "get", ev);
} else {
this._waitingEvents.push(ev.clone());
}
},
"_onRemoteData": function() {
this.setReady(true);
var vc = new Vocabulary();
vc.insert("data", this._getAllData());
vc.insert("actions", this._actions.clone());
this.broadcast(vc, "get")
}
});
module.exports = PanesList;