an ability to create panes actions, player frontend draft

This commit is contained in:
Blue 2018-11-28 09:54:14 +03:00 committed by Gitea
parent c8b432fe57
commit ec349d9bb4
16 changed files with 304 additions and 28 deletions

View file

@ -6,3 +6,4 @@ add_jslib(wModel/proxy/vocabulary.js lib/wModel/proxy/vocabulary ${MAGNUS_DIR} n
add_jslib(wModel/proxy/catalogue.js lib/wModel/proxy/catalogue ${MAGNUS_DIR} node)
configure_file(pane.js pane.js)
configure_file(panesList.js panesList.js)

View file

@ -4,12 +4,18 @@ 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) {
"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;
@ -17,14 +23,45 @@ var Pane = MVocabulary.inherit({
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;
}
});

View file

@ -0,0 +1,66 @@
"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;