initial commit
This commit is contained in:
commit
4b60ece582
327 changed files with 28286 additions and 0 deletions
17
libjs/wModel/CMakeLists.txt
Normal file
17
libjs/wModel/CMakeLists.txt
Normal file
|
@ -0,0 +1,17 @@
|
|||
cmake_minimum_required(VERSION 2.8.12)
|
||||
|
||||
configure_file(model.js model.js)
|
||||
configure_file(globalControls.js globalControls.js)
|
||||
configure_file(link.js link.js)
|
||||
configure_file(list.js list.js)
|
||||
configure_file(page.js page.js)
|
||||
configure_file(pageStorage.js pageStorage.js)
|
||||
configure_file(panesList.js panesList.js)
|
||||
configure_file(string.js string.js)
|
||||
configure_file(theme.js theme.js)
|
||||
configure_file(themeStorage.js themeStorage.js)
|
||||
configure_file(vocabulary.js vocabulary.js)
|
||||
configure_file(attributes.js attributes.js)
|
||||
configure_file(image.js image.js)
|
||||
|
||||
add_subdirectory(proxy)
|
44
libjs/wModel/attributes.js
Normal file
44
libjs/wModel/attributes.js
Normal file
|
@ -0,0 +1,44 @@
|
|||
"use strict";
|
||||
|
||||
var ModelVocabulary = require("./vocabulary");
|
||||
var Vocabulary = require("../wType/vocabulary");
|
||||
var String = require("../wType/string");
|
||||
var Uint64 = require("../wType/uint64");
|
||||
|
||||
var Attributes = ModelVocabulary.inherit({
|
||||
"className": "Attributes",
|
||||
"constructor": function(addr) {
|
||||
ModelVocabulary.fn.constructor.call(this, addr);
|
||||
|
||||
this._attributes = global.Object.create(null);
|
||||
},
|
||||
"addAttribute": function(key, model) {
|
||||
var old = this._attributes[key];
|
||||
if (old) {
|
||||
throw new Error("Attribute with key " + key + " already exists");
|
||||
}
|
||||
this._attributes[key] = model;
|
||||
this.addModel(model);
|
||||
|
||||
var vc = new Vocabulary();
|
||||
vc.insert("name", new String(key));
|
||||
vc.insert("address", model.getAddress());
|
||||
vc.insert("type", new Uint64(model.getType()));
|
||||
this.insert(key, vc);
|
||||
},
|
||||
"removeAttribute": function(key) {
|
||||
var model = this._attributes[key];
|
||||
if (!model) {
|
||||
throw new Error("An attempt to access non existing Attribute");
|
||||
}
|
||||
delete this._attributes[key];
|
||||
this.erase(key);
|
||||
this.removeModel(model);
|
||||
model.destructor();
|
||||
},
|
||||
"setAttribute": function(key, value) {
|
||||
this._attributes[key].set(value);
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = Attributes;
|
60
libjs/wModel/globalControls.js
Normal file
60
libjs/wModel/globalControls.js
Normal file
|
@ -0,0 +1,60 @@
|
|||
"use strict";
|
||||
|
||||
var List = require("./list");
|
||||
var Model = require("./model");
|
||||
var ModelString = require("./string");
|
||||
var ModelLink = require("./link");
|
||||
var ThemeStorage = require("./themeStorage");
|
||||
var Vocabulary = require("../wType/vocabulary");
|
||||
var Address = require("../wType/address");
|
||||
var String = require("../wType/string");
|
||||
|
||||
var GlobalControls = List.inherit({
|
||||
"className": "GlobalControls",
|
||||
"constructor": function(address) {
|
||||
List.fn.constructor.call(this, address);
|
||||
|
||||
this._initModels()
|
||||
},
|
||||
"addModel": function(name, model) {
|
||||
List.fn.addModel.call(this, model);
|
||||
|
||||
var vc = new Vocabulary();
|
||||
vc.insert("type", new String(model.className));
|
||||
vc.insert("address", model.getAddress());
|
||||
vc.insert("name", new String(name));
|
||||
|
||||
this.push(vc);
|
||||
},
|
||||
"addModelAsLink": function(name, model) {
|
||||
var vc = new Vocabulary();
|
||||
vc.insert("type", new String(model.className));
|
||||
vc.insert("address", model.getAddress());
|
||||
vc.insert("name", new String(name));
|
||||
|
||||
this.push(vc);
|
||||
},
|
||||
"_initModels": function() {
|
||||
var navigationPanel = this._np = new List(this._address["+"](new Address(["navigationPanel"])));
|
||||
|
||||
navigationPanel.addProperty("backgroundColor", "primaryColor");
|
||||
this.addModel("navigationPanel", navigationPanel);
|
||||
|
||||
var ts = new ThemeStorage(this._address["+"](new Address(["themes"])));
|
||||
this.addModel("themes", ts);
|
||||
},
|
||||
"addNav": function(name, address) {
|
||||
var vc = new Vocabulary();
|
||||
|
||||
var model = new ModelLink(this._np._address["+"](new Address(["" + this._np._data.length()])), name, address);
|
||||
model.label.addProperty("fontSize", "largeFontSize");
|
||||
model.label.addProperty("fontFamily", "largeFont");
|
||||
model.label.addProperty("color", "primaryFontColor");
|
||||
this._np.addModel(model);
|
||||
|
||||
vc.insert("address", model.getAddress());
|
||||
this._np.push(vc);
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = GlobalControls;
|
47
libjs/wModel/image.js
Normal file
47
libjs/wModel/image.js
Normal file
|
@ -0,0 +1,47 @@
|
|||
"use strict";
|
||||
|
||||
var Model = require("./model");
|
||||
var Uint64 = require("../wType/uint64");
|
||||
var Address = require("../wType/address");
|
||||
var Vocabulary = require("../wType/vocabulary");
|
||||
|
||||
var ModelImage = Model.inherit({
|
||||
"className": "Image",
|
||||
"constructor": function(address, uint64) {
|
||||
Model.fn.constructor.call(this, address);
|
||||
|
||||
this._data = uint64;
|
||||
|
||||
this.addHandler("get");
|
||||
},
|
||||
"destructor": function() {
|
||||
this._data.destructor();
|
||||
|
||||
Model.fn.destructor.call(this);
|
||||
},
|
||||
"_h_subscribe": function(ev) {
|
||||
Model.fn._h_subscribe.call(this, ev);
|
||||
|
||||
this._h_get(ev);
|
||||
},
|
||||
"_h_get": function(ev) {
|
||||
var vc = new Vocabulary();
|
||||
|
||||
vc.insert("data", this._data.clone());
|
||||
this.response(vc, "get", ev);
|
||||
},
|
||||
"set": function(uint64) {
|
||||
this._data.destructor();
|
||||
|
||||
this._data = uint64;
|
||||
|
||||
if (this._registered) {
|
||||
var vc = new Vocabulary();
|
||||
|
||||
vc.insert("data", this._data.clone());
|
||||
this.broadcast(vc, "get");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = ModelImage;
|
44
libjs/wModel/link.js
Normal file
44
libjs/wModel/link.js
Normal file
|
@ -0,0 +1,44 @@
|
|||
"use strict";
|
||||
|
||||
var Model = require("./model");
|
||||
var ModelString = require("./string")
|
||||
|
||||
var String = require("../wType/string");
|
||||
|
||||
var Vocabulary = require("../wType/vocabulary");
|
||||
var Address = require("../wType/address");
|
||||
|
||||
var Link = Model.inherit({
|
||||
"className": "Link",
|
||||
"constructor": function(addr, text, tAddress) {
|
||||
Model.fn.constructor.call(this, addr);
|
||||
|
||||
this.addHandler("get");
|
||||
|
||||
this._targetAddress = tAddress;
|
||||
|
||||
var hop = new Address(["label"]);
|
||||
this.label = new ModelString(addr["+"](hop), text);
|
||||
this.addModel(this.label);
|
||||
|
||||
hop.destructor();
|
||||
},
|
||||
"destructor": function() {
|
||||
this._targetAddress.destructor();
|
||||
|
||||
Model.fn.destructor.call(this);
|
||||
},
|
||||
"_h_get": function(ev) {
|
||||
var vc = new Vocabulary();
|
||||
|
||||
vc.insert("targetAddress", this._targetAddress.clone());
|
||||
this.response(vc, "get", ev);
|
||||
},
|
||||
"_h_subscribe": function(ev) {
|
||||
Model.fn._h_subscribe.call(this, ev);
|
||||
|
||||
this._h_get(ev);
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = Link;
|
51
libjs/wModel/list.js
Normal file
51
libjs/wModel/list.js
Normal file
|
@ -0,0 +1,51 @@
|
|||
"use strict";
|
||||
|
||||
var Model = require("./model");
|
||||
var Vector = require("../wType/vector");
|
||||
var Vocabulary = require("../wType/vocabulary");
|
||||
var Object = require("../wType/object")
|
||||
|
||||
var List = Model.inherit({
|
||||
"className": "List",
|
||||
"constructor": function(address) {
|
||||
Model.fn.constructor.call(this, address);
|
||||
|
||||
this._data = new Vector();
|
||||
|
||||
this.addHandler("get");
|
||||
},
|
||||
"destructor": function() {
|
||||
this._data.destructor();
|
||||
|
||||
Model.fn.destructor.call(this);
|
||||
},
|
||||
"clear": function() {
|
||||
this._data.clear();
|
||||
|
||||
this.broadcast(new Vocabulary(), "clear");
|
||||
},
|
||||
"_h_subscribe": function(ev) {
|
||||
Model.fn._h_subscribe.call(this, ev);
|
||||
|
||||
this._h_get(ev);
|
||||
},
|
||||
"_h_get": function(ev) {
|
||||
var vc = new Vocabulary();
|
||||
|
||||
vc.insert("data", this._data.clone());
|
||||
this.response(vc, "get", ev);
|
||||
},
|
||||
"push": function(obj) {
|
||||
if (!(obj instanceof Object)) {
|
||||
throw new Error("An attempt to push into list unserializable value");
|
||||
}
|
||||
this._data.push(obj);
|
||||
|
||||
var vc = new Vocabulary();
|
||||
vc.insert("data", obj.clone());
|
||||
|
||||
this.broadcast(vc, "push");
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = List;
|
316
libjs/wModel/model.js
Normal file
316
libjs/wModel/model.js
Normal file
|
@ -0,0 +1,316 @@
|
|||
"use strict";
|
||||
var Subscribable = require("../utils/subscribable");
|
||||
var AbstcractMap = require("../wContainer/abstractmap");
|
||||
var AbstractOrder = require("../wContainer/abstractorder");
|
||||
var Address = require("../wType/address");
|
||||
var Uint64 = require("../wType/uint64");
|
||||
var Event = require("../wType/event");
|
||||
var Vector = require("../wType/vector");
|
||||
var Vocabulary = require("../wType/vocabulary");
|
||||
var String = require("../wType/string");
|
||||
var Handler = require("../wDispatcher/handler");
|
||||
|
||||
var Model = Subscribable.inherit({
|
||||
"className": "Model",
|
||||
"constructor": function(address) {
|
||||
Subscribable.fn.constructor.call(this);
|
||||
|
||||
var SMap = AbstcractMap.template(Uint64, Model.addressOrder);
|
||||
|
||||
this._registered = false;
|
||||
this._subscribers = new SMap(false);
|
||||
this._handlers = [];
|
||||
this._models = [];
|
||||
this._props = new Vector();
|
||||
this._address = address;
|
||||
this._subscribersCount = 0;
|
||||
|
||||
this.addHandler("subscribe");
|
||||
this.addHandler("unsubscribe");
|
||||
},
|
||||
"destructor": function() {
|
||||
var i;
|
||||
if (this._registered) {
|
||||
this.unregister();
|
||||
}
|
||||
|
||||
this._subscribers.destructor();
|
||||
|
||||
for (i = 0; i < this._models.length; ++i) {
|
||||
this._models[i].destructor();
|
||||
}
|
||||
|
||||
for (i = 0; i < this._handlers.length; ++i) {
|
||||
this._handlers[i].destructor();
|
||||
}
|
||||
this._props.destructor();
|
||||
|
||||
Subscribable.fn.destructor.call(this);
|
||||
},
|
||||
"addHandler": function(name) {
|
||||
if (!(this["_h_" + name] instanceof Function)) {
|
||||
throw new Error("An attempt to create handler without a handling method");
|
||||
}
|
||||
|
||||
var handler = new Handler(this._address["+"](new Address([name])), this, this["_h_" + name]);
|
||||
|
||||
this._addHandler(handler);
|
||||
},
|
||||
"_addHandler": function(handler) {
|
||||
this._handlers.push(handler);
|
||||
if (this._registered) {
|
||||
this._dp.registerHandler(handler);
|
||||
}
|
||||
},
|
||||
"addModel": function(model) {
|
||||
if (!(model instanceof Model)) {
|
||||
throw new Error("An attempt to add not a model into " + this.className);
|
||||
}
|
||||
this._models.push(model);
|
||||
model.on("serviceMessage", this._onModelServiceMessage, this);
|
||||
if (this._registered) {
|
||||
model.register(this._dp, this._server);
|
||||
}
|
||||
},
|
||||
"addProperty": function(property, key) {
|
||||
var vc = new Vocabulary();
|
||||
vc.insert("property", new String(property));
|
||||
vc.insert("key", new String(key));
|
||||
|
||||
this._props.push(vc);
|
||||
|
||||
if (this._registered) {
|
||||
var nvc = new Vocabulary();
|
||||
nvc.insert("properties", this._props.clone());
|
||||
this.broadcast(nvc, "properties");
|
||||
}
|
||||
},
|
||||
"broadcast": function(vc, handler) {
|
||||
var itr = this._subscribers.begin();
|
||||
var end = this._subscribers.end();
|
||||
vc.insert("source", this._address.clone());
|
||||
|
||||
for (;!itr["=="](end); itr["++"]()) {
|
||||
var obj = itr["*"]();
|
||||
var order = obj.second;
|
||||
var socket = this._server.getConnection(obj.first);
|
||||
var oItr = order.begin();
|
||||
var oEnd = order.end();
|
||||
for (;!oItr["=="](oEnd); oItr["++"]()) {
|
||||
var addr = oItr["*"]()["+"](new Address([handler]));
|
||||
var ev = new Event(addr, vc.clone());
|
||||
ev.setSenderId(socket.getId().clone());
|
||||
socket.send(ev);
|
||||
ev.destructor();
|
||||
}
|
||||
}
|
||||
vc.destructor();
|
||||
},
|
||||
"getAddress": function() {
|
||||
return this._address.clone();
|
||||
},
|
||||
"getType": function() {
|
||||
var type = Model.ModelType[this.className];
|
||||
if (type === undefined) {
|
||||
throw new Error("Undefined ModelType");
|
||||
}
|
||||
return type;
|
||||
},
|
||||
"_h_subscribe": function(ev) {
|
||||
var id = ev.getSenderId();
|
||||
var source = ev.getData().at("source");
|
||||
|
||||
var itr = this._subscribers.find(id);
|
||||
var ord;
|
||||
if (itr["=="](this._subscribers.end())) {
|
||||
ord = new Model.addressOrder(true);
|
||||
var socket = this._server.getConnection(id);
|
||||
socket.one("disconnected", this._onSocketDisconnected, this);
|
||||
this._subscribers.insert(id.clone(), ord);
|
||||
} else {
|
||||
ord = itr["*"]().second;
|
||||
var oItr = ord.find(source);
|
||||
if (!oItr["=="](ord.end())) {
|
||||
this.trigger("serviceMessage", "id: " + id.toString() + ", " +
|
||||
"source: " + source.toString() + " " +
|
||||
"is trying to subscribe on model " + this._address.toString() + " " +
|
||||
"but it's already subscribed", 1);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
ord.push_back(source.clone());
|
||||
++this._subscribersCount;
|
||||
this.trigger("serviceMessage", this._address.toString() + " has now " + this._subscribersCount + " subscribers", 0);
|
||||
|
||||
var nvc = new Vocabulary();
|
||||
nvc.insert("properties", this._props.clone());
|
||||
|
||||
this.response(nvc, "properties", ev);
|
||||
},
|
||||
"_h_unsubscribe": function(ev) {
|
||||
var id = ev.getSenderId();
|
||||
var source = ev.getData().at("source");
|
||||
|
||||
var itr = this._subscribers.find(id);
|
||||
|
||||
if (itr["=="](this._subscribers.end())) {
|
||||
this.trigger("serviceMessage", "id: " + id.toString() + ", " +
|
||||
"source: " + source.toString() + " " +
|
||||
"is trying to unsubscribe from model " + this._address.toString() + " " +
|
||||
"but even this id is not registered in subscribers map", 1
|
||||
);
|
||||
return
|
||||
}
|
||||
var ord = itr["*"]().second;
|
||||
var oItr = ord.find(source);
|
||||
if (oItr["=="](ord.end())) {
|
||||
this.trigger("serviceMessage", "id: " + id.toString() + ", " +
|
||||
"source: " + source.toString() + " " +
|
||||
"is trying to unsubscribe from model " + this._address.toString() + " " +
|
||||
"but such address is not subscribed to this model", 1
|
||||
);
|
||||
return
|
||||
}
|
||||
ord.erase(oItr["*"]());
|
||||
if (ord.size() === 0) {
|
||||
var socket = this._server.getConnection(itr["*"]().first);
|
||||
socket.off("disconnected", this._onSocketDisconnected, this);
|
||||
this._subscribers.erase(itr);
|
||||
ord.destructor();
|
||||
}
|
||||
|
||||
--this._subscribersCount;
|
||||
this.trigger("serviceMessage", this._address.toString() + " has now " + this._subscribersCount + " subscribers", 0);
|
||||
},
|
||||
"_onModelServiceMessage": function(msg, severity) {
|
||||
this.trigger("serviceMessage", msg, severity);
|
||||
},
|
||||
"_onSocketDisconnected": function(ev, socket) {
|
||||
var id = socket.getId();
|
||||
var itr = this._subscribers.find(id);
|
||||
|
||||
if (itr["=="](this._subscribers.end())) {
|
||||
this.trigger("serviceMessage", "id: " + id.toString() + ", " +
|
||||
"after socket disconnected trying to remove subscriptions from model " +
|
||||
"but id haven't been found in subscribers map", 1);
|
||||
return
|
||||
}
|
||||
var ord = itr["*"]().second;
|
||||
this._subscribersCount -= ord.size();
|
||||
this._subscribers.erase(itr);
|
||||
ord.destructor();
|
||||
this.trigger("serviceMessage", this._address.toString() + " has now " + this._subscribersCount + " subscribers", 0);
|
||||
},
|
||||
"register": function(dp, server) {
|
||||
if (this._registered) {
|
||||
throw new Error("Model " + this._address.toString() + " is already registered");
|
||||
}
|
||||
this._dp = dp;
|
||||
this._server = server;
|
||||
var i;
|
||||
|
||||
for (i = 0; i < this._models.length; ++i) {
|
||||
this._models[i].register(dp, server);
|
||||
}
|
||||
|
||||
for (i = 0; i < this._handlers.length; ++i) {
|
||||
dp.registerHandler(this._handlers[i]);
|
||||
}
|
||||
this._registered = true;
|
||||
},
|
||||
"_removeHandler": function(handler) {
|
||||
var index = this._handlers.indexOf(handler);
|
||||
if (index === -1) {
|
||||
throw new Error("An attempt to remove non existing handler");
|
||||
}
|
||||
this._handlers.splice(index, 1);
|
||||
if (this._registered) {
|
||||
this._dp.unregisterHandler(handler);
|
||||
}
|
||||
},
|
||||
"removeModel": function(model) {
|
||||
if (!(model instanceof Model)) {
|
||||
throw new Error("An attempt to remove not a model from " + this.className);
|
||||
}
|
||||
var index = this._models.indexOf(model);
|
||||
if (index === -1) {
|
||||
throw new Error("An attempt to remove non existing model from " + this.className);
|
||||
}
|
||||
this._models.splice(index, 1);
|
||||
if (this._registered) {
|
||||
model.unregister(this._dp, this._server);
|
||||
}
|
||||
},
|
||||
"response": function(vc, handler, src) {
|
||||
if (!this._registered) {
|
||||
throw new Error("An attempt to send a message from unregistered model " + this._address.toString());
|
||||
}
|
||||
var source = src.getData().at("source").clone();
|
||||
var id = src.getSenderId().clone();
|
||||
var addr = source["+"](new Address([handler]));
|
||||
vc.insert("source", this._address.clone());
|
||||
|
||||
var ev = new Event(addr, vc);
|
||||
ev.setSenderId(id);
|
||||
var socket = this._server.getConnection(id);
|
||||
socket.send(ev);
|
||||
ev.destructor();
|
||||
},
|
||||
"unregister": function() {
|
||||
if (!this._registered) {
|
||||
throw new Error("Model " + this._address.toString() + " is not registered");
|
||||
}
|
||||
var i;
|
||||
|
||||
for (i = 0; i < this._models.length; ++i) {
|
||||
this._models[i].unregister();
|
||||
}
|
||||
|
||||
for (i = 0; i < this._handlers.length; ++i) {
|
||||
this._dp.unregisterHandler(this._handlers[i]);
|
||||
}
|
||||
|
||||
var itr = this._subscribers.begin();
|
||||
var end = this._subscribers.end();
|
||||
|
||||
for (;!itr["=="](end); itr["++"]()) {
|
||||
var socket = this._server.getConnection(itr["*"]().first);
|
||||
var ord = itr["*"]().second;
|
||||
ord.destructor();
|
||||
socket.off("disconnected", this._onSocketDisconnected, this);
|
||||
}
|
||||
this._subscribers.clear();
|
||||
this._subscribersCount = 0;
|
||||
|
||||
delete this._dp;
|
||||
delete this._server;
|
||||
|
||||
this._registered = false;
|
||||
}
|
||||
});
|
||||
|
||||
Model.getModelTypeId = function(model) {
|
||||
return this.ModelType[model.className];
|
||||
}
|
||||
|
||||
Model.addressOrder = AbstractOrder.template(Address);
|
||||
Model.ModelType = {
|
||||
String: 0,
|
||||
List: 1,
|
||||
Vocabulary: 2,
|
||||
Image: 3,
|
||||
Model: 4,
|
||||
|
||||
Attributes: 50,
|
||||
|
||||
GlobalControls: 100,
|
||||
Link: 101,
|
||||
Page: 102,
|
||||
PageStorage: 103,
|
||||
PanesList: 104,
|
||||
Theme: 105,
|
||||
ThemeStorage: 106
|
||||
};
|
||||
|
||||
module.exports = Model;
|
163
libjs/wModel/page.js
Normal file
163
libjs/wModel/page.js
Normal file
|
@ -0,0 +1,163 @@
|
|||
"use strict";
|
||||
|
||||
var Model = require("./model");
|
||||
var AbstractMap = require("../wContainer/abstractmap");
|
||||
var Vocabulary = require("../wType/vocabulary");
|
||||
var Vector = require("../wType/vector");
|
||||
var Address = require("../wType/address");
|
||||
var String = require("../wType/string");
|
||||
var UInt64 = require("../wType/uint64");
|
||||
|
||||
var ContentMap = AbstractMap.template(Address, Vocabulary);
|
||||
|
||||
var Page = Model.inherit({
|
||||
"className": "Page",
|
||||
"constructor": function(address, name) {
|
||||
Model.fn.constructor.call(this, address);
|
||||
|
||||
this._data = new ContentMap(true);
|
||||
this.name = name.toLowerCase();
|
||||
this.urlAddress = [this.name];
|
||||
this._hasParentReporter = false;
|
||||
this._pr = undefined;
|
||||
this._childPages = {};
|
||||
|
||||
this.addHandler("get");
|
||||
this.addHandler("ping");
|
||||
|
||||
this.addProperty("backgroundColor", "mainColor");
|
||||
this.addProperty("color", "mainFontColor");
|
||||
},
|
||||
"destructor": function() {
|
||||
this._data.destructor();
|
||||
|
||||
Model.fn.destructor.call(this);
|
||||
},
|
||||
"addItem": function(model, row, col, rowspan, colspan, aligment, viewType, viewOptions) {
|
||||
Model.fn.addModel.call(this, model);
|
||||
|
||||
var vc = new Vocabulary();
|
||||
viewOptions = viewOptions || new Vocabulary();
|
||||
viewType = viewType || new UInt64(Page.getModelTypeId(model))
|
||||
|
||||
vc.insert("type", new UInt64(Page.getModelTypeId(model)));
|
||||
vc.insert("row", new UInt64(row || 0));
|
||||
vc.insert("col", new UInt64(col || 0));
|
||||
vc.insert("rowspan", new UInt64(rowspan || 1));
|
||||
vc.insert("colspan", new UInt64(colspan || 1));
|
||||
vc.insert("aligment", new UInt64(aligment || Page.Aligment.LeftTop));
|
||||
vc.insert("viewOptions", viewOptions);
|
||||
vc.insert("viewType", viewType);
|
||||
|
||||
this._data.insert(model.getAddress(), vc);
|
||||
|
||||
var evc = vc.clone();
|
||||
evc.insert("address", model.getAddress());
|
||||
|
||||
this.broadcast(evc, "addItem");
|
||||
},
|
||||
"addPage": function(page) {
|
||||
this.addModel(page);
|
||||
var addr = this.urlAddress.slice();
|
||||
addr.push(page.name);
|
||||
page.setUrlAddress(addr)
|
||||
page.on("newPage", this._onNewPage, this);
|
||||
page.on("removePage", this._onRemovePage, this);
|
||||
this._childPages[page.name] = page;
|
||||
|
||||
this.trigger("newPage", page);
|
||||
},
|
||||
"clear": function() {
|
||||
this._data.clear();
|
||||
|
||||
this.broadcast(new Vocabulary(), "clear");
|
||||
},
|
||||
"getChildPage": function(name) {
|
||||
return this._childPages[name];
|
||||
},
|
||||
"_h_get": function(ev) {
|
||||
var data = new Vocabulary();
|
||||
|
||||
var vector = new Vector();
|
||||
var itr = this._data.begin();
|
||||
var end = this._data.end();
|
||||
|
||||
for (; !itr["=="](end); itr["++"]()) {
|
||||
var pair = itr["*"]();
|
||||
var vc = pair.second.clone();
|
||||
|
||||
vc.insert("address", pair.first.clone());
|
||||
vector.push(vc);
|
||||
}
|
||||
|
||||
data.insert("name", new String(this.name));
|
||||
data.insert("data", vector);
|
||||
this.response(data, "get", ev);
|
||||
},
|
||||
"_h_ping": function(ev) {
|
||||
this.trigger("serviceMessage", "page " + this._address.toString() + " got pinged", 0);
|
||||
},
|
||||
"_h_subscribe": function(ev) {
|
||||
Model.fn._h_subscribe.call(this, ev);
|
||||
|
||||
this._h_get(ev);
|
||||
},
|
||||
"_onNewPage": function(page) {
|
||||
this.trigger("newPage", page);
|
||||
},
|
||||
"_onRemovePage": function(page) {
|
||||
this.trigger("removePage", page);
|
||||
},
|
||||
"removeItem": function(model) {
|
||||
Model.fn.removeModel.call(this, model);
|
||||
var addr = model.getAddress();
|
||||
|
||||
var itr = this._data.find(addr);
|
||||
this._data.erase(itr);
|
||||
|
||||
var vc = new Vocabulary();
|
||||
vc.insert("address", addr);
|
||||
|
||||
this.broadcast(vc, "removeItem");
|
||||
},
|
||||
"removePage": function(page) {
|
||||
Model.fn.removeModel.call(this, page);
|
||||
|
||||
delete this._childPages[page.name];
|
||||
page.off("newPage", this._onNewPage, this);
|
||||
page.off("removePage", this._onRemovePage, this);
|
||||
|
||||
this.trigger("removePage", page);
|
||||
},
|
||||
"setParentReporter": function(pr) {
|
||||
if (this._hasParentReporter) {
|
||||
throw new Error("An attempt to set parent reporter to page while another one already exists");
|
||||
}
|
||||
this._pr = pr;
|
||||
this._hasParentReporter = true;
|
||||
},
|
||||
"setUrlAddress": function(address) {
|
||||
this.urlAddress = address;
|
||||
},
|
||||
"unsetParentReporter": function() {
|
||||
if (!this._hasParentReporter) {
|
||||
throw new Error("An attempt to unset parent reporter from page which doesn't have one");
|
||||
}
|
||||
delete this._pr;
|
||||
this._hasParentReporter = false;
|
||||
}
|
||||
});
|
||||
|
||||
Page.Aligment = {
|
||||
"LeftTop": 1,
|
||||
"LeftCenter": 4,
|
||||
"LeftBottom": 7,
|
||||
"CenterTop": 2,
|
||||
"CenterCenter": 5,
|
||||
"CenterBottom": 8,
|
||||
"RightTop": 3,
|
||||
"RightCenter": 6,
|
||||
"RightBottom": 9
|
||||
};
|
||||
|
||||
module.exports = Page;
|
124
libjs/wModel/pageStorage.js
Normal file
124
libjs/wModel/pageStorage.js
Normal file
|
@ -0,0 +1,124 @@
|
|||
"use strict";
|
||||
|
||||
var Model = require("./model");
|
||||
var Page = require("./page");
|
||||
var ModelString = require("./string");
|
||||
var Vocabulary = require("../wType/vocabulary");
|
||||
var Address = require("../wType/address");
|
||||
var String = require("../wType/string");
|
||||
var Event = require("../wType/event");
|
||||
var AbstractMap = require("../wContainer/abstractmap");
|
||||
|
||||
var AddressMap = AbstractMap.template(Address, String);
|
||||
|
||||
var PageStorage = Model.inherit({
|
||||
"className": "PageStorage",
|
||||
"constructor": function(addr, rootPage, pr) {
|
||||
Model.fn.constructor.call(this, addr);
|
||||
|
||||
this._urls = {};
|
||||
this._specialPages = {};
|
||||
this._rMap = new AddressMap(true);
|
||||
this._root = rootPage;
|
||||
this._pr = pr;
|
||||
|
||||
this._initRootPage();
|
||||
this._initNotFoundPage();
|
||||
|
||||
this.addHandler("getPageAddress");
|
||||
this.addHandler("getPageName");
|
||||
},
|
||||
"destructor": function() {
|
||||
this._rMap.destructor();
|
||||
|
||||
Model.fn.destructor.call(this);
|
||||
},
|
||||
"getPageByUrl": function(url) {
|
||||
var addr = url.split("/");
|
||||
var page = this._root;
|
||||
for (var i = 0; i < addr.length; ++i) {
|
||||
if (addr[i] !== "") {
|
||||
page = page.getChildPage(addr[i]);
|
||||
if (page === undefined) {
|
||||
return this._specialPages.notFound;
|
||||
}
|
||||
}
|
||||
}
|
||||
return page;
|
||||
},
|
||||
"hasPage": function(name) {
|
||||
return this.getPageByUrl(name) !== this._specialPages.notFound
|
||||
},
|
||||
"_h_getPageAddress": function(ev) {
|
||||
var data = ev.getData();
|
||||
|
||||
var page = this.getPageByUrl(data.at("url").valueOf());
|
||||
|
||||
var vc = new Vocabulary();
|
||||
if (page) {
|
||||
vc.insert("address", page.getAddress());
|
||||
} else {
|
||||
vc.insert("address", this._specialPages.notFound.getAddress());
|
||||
}
|
||||
|
||||
this.response(vc, "pageAddress", ev);
|
||||
},
|
||||
"_h_getPageName": function(ev) {
|
||||
var data = ev.getData();
|
||||
var address = data.at("address");
|
||||
|
||||
var evp = new Event(address["+"](new Address(["ping"])));
|
||||
this._dp.pass(evp);
|
||||
evp.destructor();
|
||||
|
||||
var itr = this._rMap.find(address);
|
||||
var vc = new Vocabulary();
|
||||
if (itr["=="](this._rMap.end())) {
|
||||
vc.insert("name", new String("notFound"));
|
||||
} else {
|
||||
vc.insert("name", itr["*"]().second.clone());
|
||||
}
|
||||
this.response(vc, "pageName", ev);
|
||||
},
|
||||
"_initNotFoundPage": function() {
|
||||
var nf = new Page(this._address["+"](new Address(["special", "notFound"])), "Not found");
|
||||
this._specialPages["notFound"] = nf;
|
||||
this.addModel(nf);
|
||||
var msg = new ModelString(nf._address["+"](new Address(["errorMessage"])), "Error: page not found");
|
||||
nf.addItem(msg, 0, 0, 1, 1);
|
||||
},
|
||||
"_initRootPage": function() {
|
||||
this.addModel(this._root);
|
||||
|
||||
this._rMap.insert(this._root.getAddress(), new String("/"));
|
||||
this._root.on("newPage", this._onNewPage, this);
|
||||
this._root.on("removePage", this._onRemovePage, this);
|
||||
},
|
||||
"_onNewPage": function(page) {
|
||||
var addr = page.urlAddress.join("/").slice(this._root.name.length);
|
||||
this.trigger("serviceMessage", "Adding new page: " + addr);
|
||||
this.trigger("serviceMessage", "Page address: " + page.getAddress().toString());
|
||||
|
||||
if (this._urls[addr]) {
|
||||
throw new Error("An attempt to add page with an existing url");
|
||||
}
|
||||
this._urls[addr] = page;
|
||||
this._rMap.insert(page.getAddress(), new String(addr));
|
||||
page.setParentReporter(this._pr);
|
||||
},
|
||||
"_onRemovePage": function(page) {
|
||||
var addr = page.urlAddress.join("/").slice(this._root.name.length);
|
||||
this.trigger("serviceMessage", "Removing page: " + addr);
|
||||
this.trigger("serviceMessage", "Page address: " + page.getAddress().toString());
|
||||
|
||||
if (!this._urls[addr]) {
|
||||
throw new Error("An attempt to remove a non existing page");
|
||||
}
|
||||
delete this._urls[addr];
|
||||
var itr = this._rMap.find(page.getAddress());
|
||||
this._rMap.erase(itr);
|
||||
page.unsetParentReporter();
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = PageStorage;
|
21
libjs/wModel/panesList.js
Normal file
21
libjs/wModel/panesList.js
Normal file
|
@ -0,0 +1,21 @@
|
|||
"use strict";
|
||||
|
||||
var List = require("./list");
|
||||
var Vocabulary = require("../wType/vocabulary");
|
||||
|
||||
var PanesList = List.inherit({
|
||||
"className": "PanesList",
|
||||
"constructor": function(address) {
|
||||
List.fn.constructor.call(this, address);
|
||||
},
|
||||
"addItem": function(model) {
|
||||
List.fn.addModel.call(this, model);
|
||||
|
||||
var vc = new Vocabulary();
|
||||
vc.insert("address", model.getAddress());
|
||||
|
||||
this.push(vc);
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = PanesList;
|
6
libjs/wModel/proxy/CMakeLists.txt
Normal file
6
libjs/wModel/proxy/CMakeLists.txt
Normal file
|
@ -0,0 +1,6 @@
|
|||
cmake_minimum_required(VERSION 2.8.12)
|
||||
|
||||
configure_file(proxy.js proxy.js)
|
||||
configure_file(list.js list.js)
|
||||
configure_file(vocabulary.js vocabulary.js)
|
||||
configure_file(catalogue.js catalogue.js)
|
54
libjs/wModel/proxy/catalogue.js
Normal file
54
libjs/wModel/proxy/catalogue.js
Normal file
|
@ -0,0 +1,54 @@
|
|||
"use strict";
|
||||
|
||||
var Proxy = require("./proxy");
|
||||
var Vocabulary = require("../../wType/vocabulary");
|
||||
var Vector = require("../../wType/vector");
|
||||
var Ctrl = require("../../wController/catalogue");
|
||||
|
||||
var Catalogue = Proxy.inherit({
|
||||
"className": "List", //no, it is not a typo, this is the way data structure here suppose to look like
|
||||
"constructor": function(address, ctrlAddr, ctrlOpts, socket) {
|
||||
var controller = new Ctrl(ctrlAddr, ctrlOpts);
|
||||
Proxy.fn.constructor.call(this, address, controller, socket);
|
||||
|
||||
this.controller.on("data", this._onRemoteData, this);
|
||||
this.controller.on("addElement", this._onRemoteAddElement, this);
|
||||
//this.controller.on("removeElement", this._onRemoteRemoveElement, this); //not supported yet
|
||||
},
|
||||
"_getAllData": function() {
|
||||
var vec = new Vector();
|
||||
|
||||
var itr = this.controller.data.begin();
|
||||
var end = this.controller.data.end();
|
||||
|
||||
for (; !itr["=="](end); itr["++"]()) {
|
||||
vec.push(itr["*"]().clone());
|
||||
}
|
||||
|
||||
return vec;
|
||||
},
|
||||
"_h_subscribe": function(ev) {
|
||||
Proxy.fn._h_subscribe.call(this, ev);
|
||||
|
||||
if (this.ready) {
|
||||
this._h_get(ev);
|
||||
}
|
||||
},
|
||||
"_onRemoteData": function() {
|
||||
this.setReady(true);
|
||||
|
||||
var vc = new Vocabulary();
|
||||
vc.insert("data", this._getAllData());
|
||||
this.broadcast(vc, "get")
|
||||
},
|
||||
"_onRemoteAddElement": function(obj, before) {
|
||||
if (this.ready) { //only end appends are supported now
|
||||
var vc = new Vocabulary();
|
||||
vc.insert("data", obj.clone());
|
||||
|
||||
this.broadcast(vc, "push");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = Catalogue;
|
46
libjs/wModel/proxy/list.js
Normal file
46
libjs/wModel/proxy/list.js
Normal file
|
@ -0,0 +1,46 @@
|
|||
"use strict";
|
||||
|
||||
var Proxy = require("./proxy");
|
||||
var Vocabulary = require("../../wType/vocabulary");
|
||||
var Ctrl = require("../../wController/list");
|
||||
|
||||
var List = Proxy.inherit({
|
||||
"className": "List",
|
||||
"constructor": function(address, controllerAddress, socket) {
|
||||
var controller = new Ctrl(controllerAddress);
|
||||
Proxy.fn.constructor.call(this, address, controller, socket);
|
||||
|
||||
this.controller.on("data", this._onRemoteData, this);
|
||||
this.controller.on("clear", this._onRemoteClear, this);
|
||||
this.controller.on("newElement", this._onRemoteNewElement, this);
|
||||
},
|
||||
"_h_subscribe": function(ev) {
|
||||
Proxy.fn._h_subscribe.call(this, ev);
|
||||
|
||||
if (this.ready) {
|
||||
this._h_get(ev);
|
||||
}
|
||||
},
|
||||
"_onRemoteClear": function() {
|
||||
if (this.ready) {
|
||||
this.broadcast(new Vocabulary(), "clear");
|
||||
}
|
||||
},
|
||||
"_onRemoteData": function() {
|
||||
this.setReady(true);
|
||||
|
||||
var vc = new Vocabulary();
|
||||
vc.insert("data", this.controller.data.clone())
|
||||
this.broadcast(vc, "get")
|
||||
},
|
||||
"_onRemoteNewElement": function(obj) {
|
||||
if (this.ready) {
|
||||
var vc = new Vocabulary();
|
||||
vc.insert("data", obj.clone());
|
||||
|
||||
this.broadcast(vc, "push");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = List;
|
180
libjs/wModel/proxy/proxy.js
Normal file
180
libjs/wModel/proxy/proxy.js
Normal file
|
@ -0,0 +1,180 @@
|
|||
"use strict";
|
||||
|
||||
var Model = require("../model");
|
||||
var Handler = require("../../wDispatcher/handler");
|
||||
var Vocabulary = require("../../wType/vocabulary");
|
||||
var Address = require("../../wType/address");
|
||||
|
||||
var config = require("../../../config/config.json");
|
||||
|
||||
var Proxy = Model.inherit({
|
||||
"className": "Proxy",
|
||||
"constructor": function(address, controller, socket) { //les't pretend - this class is abstract
|
||||
Model.fn.constructor.call(this, address);
|
||||
|
||||
this._socket = socket;
|
||||
this.ready = false;
|
||||
this.controller = controller;
|
||||
this.childrenPossible = false;
|
||||
this._destroyOnLastUnsubscription = false;
|
||||
this._destructionTimeout = undefined;
|
||||
this._childClass = undefined;
|
||||
this._waitingEvents = [];
|
||||
|
||||
this.addHandler("get");
|
||||
this.reporterHandler = new Handler(this._address["+"](new Address(["subscribeMember"])), this, this._h_subscribeMember);
|
||||
|
||||
this._uncyclic.push(function() {
|
||||
controller.destructor();
|
||||
});
|
||||
},
|
||||
"destructor": function() {
|
||||
if (this._destructionTimeout) {
|
||||
clearTimeout(this._destructionTimeout);
|
||||
}
|
||||
for (var i = 0; i < this._waitingEvents.length; ++i) {
|
||||
this._waitingEvents[i].destructor();
|
||||
}
|
||||
this.reporterHandler.destructor();
|
||||
Model.fn.destructor.call(this);
|
||||
},
|
||||
"checkSubscribersAndDestroy": function() {
|
||||
if (this._subscribersCount === 0 && this._destructionTimeout === undefined) {
|
||||
this.trigger("serviceMessage", this._address.toString() + " has no more subscribers, destroying model");
|
||||
this._destructionTimeout = setTimeout(this.trigger.bind(this, "destroyMe"), config.modelDestructionTimeout);
|
||||
}
|
||||
},
|
||||
"dispatchWaitingEvents": function() {
|
||||
for (var i = 0; i < this._waitingEvents.length; ++i) {
|
||||
var ev = this._waitingEvents[i];
|
||||
var cmd = "_h_" + ev.getDestination().back().toString();
|
||||
this[cmd](ev);
|
||||
ev.destructor();
|
||||
}
|
||||
this._waitingEvents = [];
|
||||
},
|
||||
"_getAllData": function() {
|
||||
return this.controller.data.clone();
|
||||
},
|
||||
"_h_get": function(ev) {
|
||||
if (this.ready) {
|
||||
var vc = new Vocabulary();
|
||||
|
||||
vc.insert("data", this._getAllData());
|
||||
this.response(vc, "get", ev);
|
||||
} else {
|
||||
this._waitingEvents.push(ev.clone());
|
||||
}
|
||||
},
|
||||
"_h_subscribe": function(ev) {
|
||||
Model.fn._h_subscribe.call(this, ev);
|
||||
|
||||
if (this._destructionTimeout) {
|
||||
clearTimeout(this._destructionTimeout);
|
||||
this._destructionTimeout = undefined;
|
||||
}
|
||||
},
|
||||
"_h_unsubscribe": function(ev) {
|
||||
Model.fn._h_unsubscribe.call(this, ev);
|
||||
|
||||
if (this._destroyOnLastUnsubscription) {
|
||||
this.checkSubscribersAndDestroy();
|
||||
}
|
||||
},
|
||||
"_h_subscribeMember": function(ev) {
|
||||
if (!this.childrenPossible) {
|
||||
return;
|
||||
}
|
||||
var dest = ev.getDestination();
|
||||
var lastHops = dest["<<"](this._address.length());
|
||||
|
||||
if (lastHops.length() === 2) {
|
||||
var command = lastHops.back().toString();
|
||||
var id = lastHops[">>"](1);
|
||||
if (command === "subscribe" || command === "get") {
|
||||
var child = new this._childClass(this._address["+"](id), this.controller._pairAddress["+"](id), this._socket);
|
||||
this.addModel(child);
|
||||
child._destroyOnLastUnsubscription = true;
|
||||
child["_h_" + command](ev);
|
||||
if (command === "get") {
|
||||
child.on("ready", child.checkSubscribersAndDestroy, child);
|
||||
}
|
||||
child.subscribe();
|
||||
child.on("destroyMe", this.destroyChild.bind(this, child)); //to remove model if it has no subscribers
|
||||
} else {
|
||||
this.trigger("serviceMessage", "Proxy model got a strange event: " + ev.toString(), 1);
|
||||
}
|
||||
} else {
|
||||
this.trigger("serviceMessage", "Proxy model got a strange event: " + ev.toString(), 1);
|
||||
}
|
||||
},
|
||||
"_onSocketDisconnected": function(ev, socket) {
|
||||
Model.fn._onSocketDisconnected.call(this, ev, socket);
|
||||
|
||||
if (this._destroyOnLastUnsubscription) {
|
||||
this.checkSubscribersAndDestroy();
|
||||
}
|
||||
},
|
||||
"register": function(dp, server) {
|
||||
Model.fn.register.call(this, dp, server);
|
||||
|
||||
this.controller.register(dp, this._socket);
|
||||
},
|
||||
"unregister": function() {
|
||||
Model.fn.unregister.call(this);
|
||||
|
||||
if (this.controller._subscribed) {
|
||||
this.controller.unsubscribe();
|
||||
}
|
||||
this.controller.unregister();
|
||||
},
|
||||
"setChildrenClass": function(Class) {
|
||||
if (this.childrenPossible) {
|
||||
this.trigger("serviceMessage", "An attempt to set another class for children in Proxy", 1);
|
||||
}
|
||||
if (!Class instanceof Proxy) {
|
||||
this.trigger("serviceMessage", "An attempt to set not inherited chidren class from Proxy to a Proxy", 2);
|
||||
}
|
||||
this.childrenPossible = true;
|
||||
this._childClass = Class;
|
||||
},
|
||||
"setReady": function(bool) {
|
||||
bool = !!bool;
|
||||
if (bool !== this.ready) {
|
||||
this.ready = bool;
|
||||
if (bool) {
|
||||
this.dispatchWaitingEvents();
|
||||
this.trigger("ready");
|
||||
} else {
|
||||
//todo do I realy need to trigger smth here?
|
||||
}
|
||||
}
|
||||
},
|
||||
"subscribe": function() {
|
||||
this.controller.subscribe();
|
||||
},
|
||||
"destroyChild": function(child) {
|
||||
this.removeModel(child);
|
||||
child.destructor();
|
||||
},
|
||||
"unsetChildrenClass": function() {
|
||||
if (!this.childrenPossible) {
|
||||
this.trigger("serviceMessage", "An attempt to unset children class in Proxy, which don't have it", 1);
|
||||
} else {
|
||||
delete this._childClass;
|
||||
this.childrenPossible = false;
|
||||
}
|
||||
},
|
||||
"unsubscribe": function() {
|
||||
this.controller.unsubscribe();
|
||||
this.setReady(false);
|
||||
}
|
||||
});
|
||||
|
||||
Proxy.onChildReady = function(ev) {
|
||||
this._h_get(ev);
|
||||
this.checkSubscribersAndDestroy();
|
||||
}
|
||||
|
||||
module.exports = Proxy;
|
||||
|
43
libjs/wModel/proxy/vocabulary.js
Normal file
43
libjs/wModel/proxy/vocabulary.js
Normal file
|
@ -0,0 +1,43 @@
|
|||
"use strict";
|
||||
|
||||
var Proxy = require("./proxy");
|
||||
var Vocabulary = require("../../wType/vocabulary");
|
||||
var Ctrl = require("../../wController/vocabulary");
|
||||
|
||||
var MVocabulary = Proxy.inherit({
|
||||
"className": "Vocabulary",
|
||||
"constructor": function(address, controllerAddress, socket) {
|
||||
var controller = new Ctrl(controllerAddress);
|
||||
Proxy.fn.constructor.call(this, address, controller, socket);
|
||||
|
||||
this.controller.on("data", this._onRemoteData, this);
|
||||
this.controller.on("clear", this._onRemoteClear, this);
|
||||
this.controller.on("change", this._onRemoteChange, this);
|
||||
},
|
||||
"_h_subscribe": function(ev) {
|
||||
Proxy.fn._h_subscribe.call(this, ev);
|
||||
|
||||
if (this.ready) {
|
||||
this._h_get(ev);
|
||||
}
|
||||
},
|
||||
"_onRemoteClear": function() {
|
||||
if (this.ready) {
|
||||
this.broadcast(new Vocabulary(), "clear");
|
||||
}
|
||||
},
|
||||
"_onRemoteData": function() {
|
||||
this.setReady(true);
|
||||
|
||||
var vc = new Vocabulary();
|
||||
vc.insert("data", this._getAllData());
|
||||
this.broadcast(vc, "get")
|
||||
},
|
||||
"_onRemoteChange": function(data) {
|
||||
if (this.ready) {
|
||||
this.broadcast(data, "change");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = MVocabulary;
|
47
libjs/wModel/string.js
Normal file
47
libjs/wModel/string.js
Normal file
|
@ -0,0 +1,47 @@
|
|||
"use strict";
|
||||
|
||||
var Model = require("./model");
|
||||
var String = require("../wType/string");
|
||||
var Address = require("../wType/address");
|
||||
var Vocabulary = require("../wType/vocabulary");
|
||||
|
||||
var ModelString = Model.inherit({
|
||||
"className": "String",
|
||||
"constructor": function(address, string) {
|
||||
Model.fn.constructor.call(this, address);
|
||||
|
||||
this._data = new String(string);
|
||||
|
||||
this.addHandler("get");
|
||||
},
|
||||
"destructor": function() {
|
||||
this._data.destructor();
|
||||
|
||||
Model.fn.destructor.call(this);
|
||||
},
|
||||
"_h_subscribe": function(ev) {
|
||||
Model.fn._h_subscribe.call(this, ev);
|
||||
|
||||
this._h_get(ev);
|
||||
},
|
||||
"_h_get": function(ev) {
|
||||
var vc = new Vocabulary();
|
||||
|
||||
vc.insert("data", this._data.clone());
|
||||
this.response(vc, "get", ev);
|
||||
},
|
||||
"set": function(value) {
|
||||
this._data.destructor();
|
||||
|
||||
this._data = new String(value.toString());
|
||||
|
||||
if (this._registered) {
|
||||
var vc = new Vocabulary();
|
||||
|
||||
vc.insert("data", this._data.clone());
|
||||
this.broadcast(vc, "get");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = ModelString;
|
70
libjs/wModel/theme.js
Normal file
70
libjs/wModel/theme.js
Normal file
|
@ -0,0 +1,70 @@
|
|||
"use strict";
|
||||
|
||||
var Model = require("./model");
|
||||
var Vocabulary = require("../wType/vocabulary");
|
||||
var String = require("../wType/string");
|
||||
var Uint64 = require("../wType/uint64");
|
||||
|
||||
var Theme = Model.inherit({
|
||||
"className": "Theme",
|
||||
"constructor": function(address, name, theme) {
|
||||
Model.fn.constructor.call(this, address);
|
||||
|
||||
this._themeName = name;
|
||||
var result = {};
|
||||
W.extend(result, Theme.default, theme);
|
||||
|
||||
var data = new Vocabulary();
|
||||
|
||||
for (var key in result) {
|
||||
if (result.hasOwnProperty(key)) {
|
||||
var type = typeof result[key];
|
||||
switch (type) {
|
||||
case "number":
|
||||
data.insert(key, new Uint64(result[key]));
|
||||
break;
|
||||
default:
|
||||
data.insert(key, new String(result[key]));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this._data = data;
|
||||
|
||||
this.addHandler("get");
|
||||
},
|
||||
"getName": function() {
|
||||
return this._themeName;
|
||||
},
|
||||
"_h_get": function(ev) {
|
||||
var vc = new Vocabulary();
|
||||
|
||||
vc.insert("data", this._data.clone());
|
||||
vc.insert("name", new String(this._themeName));
|
||||
this.response(vc, "get", ev);
|
||||
},
|
||||
"_h_subscribe": function(ev) {
|
||||
Model.fn._h_subscribe.call(this, ev);
|
||||
|
||||
this._h_get(ev);
|
||||
}
|
||||
});
|
||||
|
||||
Theme.default = {
|
||||
mainColor: "#ffffff",
|
||||
mainFontColor: "#222222",
|
||||
primaryColor: "#0000ff",
|
||||
primaryFontColor: "#ffffff",
|
||||
secondaryColor: "#dddddd",
|
||||
secondaryFontColor: "#222222",
|
||||
|
||||
smallFont: "Liberation",
|
||||
smallFontSize: "12px",
|
||||
casualFont: "Liberation",
|
||||
casualFontSize: "16px",
|
||||
largeFont: "Liberation",
|
||||
largeFontSize: "20px"
|
||||
}
|
||||
|
||||
module.exports = Theme;
|
54
libjs/wModel/themeStorage.js
Normal file
54
libjs/wModel/themeStorage.js
Normal file
|
@ -0,0 +1,54 @@
|
|||
"use strict"
|
||||
|
||||
var Model = require("./model");
|
||||
|
||||
var Vocabulary = require("../wType/vocabulary");
|
||||
var Address = require("../wType/address");
|
||||
var String = require("../wType/string");
|
||||
var Theme = require("./theme")
|
||||
|
||||
var ThemeStorage = Model.inherit({
|
||||
"className": "ThemeStorage",
|
||||
"constructor": function(address) {
|
||||
Model.fn.constructor.call(this, address);
|
||||
|
||||
this._dtn = "budgie";
|
||||
this._data = new Vocabulary();
|
||||
|
||||
this.addHandler("get");
|
||||
this._initThemes();
|
||||
},
|
||||
"destructor": function() {
|
||||
this._data.destructor();
|
||||
|
||||
Model.fn.destructor.call(this);
|
||||
},
|
||||
"_h_subscribe": function(ev) {
|
||||
Model.fn._h_subscribe.call(this, ev);
|
||||
|
||||
this._h_get(ev);
|
||||
},
|
||||
"_h_get": function(ev) {
|
||||
var vc = new Vocabulary();
|
||||
|
||||
vc.insert("data", this._data.clone());
|
||||
vc.insert("default", new String(this._dtn));
|
||||
this.response(vc, "get", ev);
|
||||
},
|
||||
"_initThemes": function() {
|
||||
var budgie = new Theme(this._address["+"](new Address(["budgie"])), "budgie");
|
||||
this.insert(budgie);
|
||||
},
|
||||
"insert": function(theme) {
|
||||
this.addModel(theme);
|
||||
this._data.insert(theme.getName(), theme.getAddress());
|
||||
|
||||
var vc = new Vocabulary();
|
||||
vc.insert("name", new String(theme.getName()));
|
||||
vc.insert("address", theme.getAddress());
|
||||
|
||||
this.broadcast(vc, "insertion");
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = ThemeStorage;
|
79
libjs/wModel/vocabulary.js
Normal file
79
libjs/wModel/vocabulary.js
Normal file
|
@ -0,0 +1,79 @@
|
|||
"use strict";
|
||||
|
||||
var Model = require("./model");
|
||||
var Vector = require("../wType/vector");
|
||||
var Vocabulary = require("../wType/vocabulary");
|
||||
var Object = require("../wType/object")
|
||||
var String = require("../wType/string");
|
||||
|
||||
var ModelVocabulary = Model.inherit({
|
||||
"className": "Vocabulary",
|
||||
"constructor": function(address) {
|
||||
Model.fn.constructor.call(this, address);
|
||||
|
||||
this._data = new Vocabulary();
|
||||
|
||||
this.addHandler("get");
|
||||
},
|
||||
"destructor": function() {
|
||||
this._data.destructor();
|
||||
|
||||
Model.fn.destructor.call(this);
|
||||
},
|
||||
"clear": function() {
|
||||
this._data.clear();
|
||||
|
||||
if (this._regestered) {
|
||||
this.broadcast(new Vocabulary(), "clear");
|
||||
}
|
||||
},
|
||||
"erase": function(key) {
|
||||
this._data.erase(key);
|
||||
|
||||
if (this._registered) {
|
||||
var vc = new Vocabulary();
|
||||
var insert = new Vocabulary();
|
||||
var erase = new Vector();
|
||||
|
||||
erase.push(new String(key));
|
||||
vc.insert("insert", insert);
|
||||
vc.insert("erase", erase);
|
||||
|
||||
this.broadcast(vc, "change");
|
||||
}
|
||||
},
|
||||
"_h_subscribe": function(ev) {
|
||||
Model.fn._h_subscribe.call(this, ev);
|
||||
|
||||
this._h_get(ev);
|
||||
},
|
||||
"_h_get": function(ev) {
|
||||
var vc = new Vocabulary();
|
||||
|
||||
vc.insert("data", this._data.clone());
|
||||
this.response(vc, "get", ev);
|
||||
},
|
||||
"insert": function(key, value) {
|
||||
if (this._registered) {
|
||||
var vc = new Vocabulary();
|
||||
var insert = new Vocabulary();
|
||||
var erase = new Vector();
|
||||
|
||||
if (this._data.has(key)) {
|
||||
erase.push(new String(key));
|
||||
}
|
||||
this._data.insert(key, value);
|
||||
insert.insert(key, value.clone());
|
||||
|
||||
vc.insert("insert", insert);
|
||||
vc.insert("erase", erase);
|
||||
|
||||
this.broadcast(vc, "change");
|
||||
|
||||
} else {
|
||||
this._data.insert(key, value);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = ModelVocabulary;
|
Loading…
Add table
Add a link
Reference in a new issue