an ability to create panes actions, player frontend draft
This commit is contained in:
parent
2d2ad3085f
commit
b2ddc804c7
16 changed files with 304 additions and 28 deletions
|
@ -4,26 +4,97 @@ var Address = require("../wType/address");
|
|||
|
||||
var Vocabulary = require("./vocabulary");
|
||||
var File = require("./file/file");
|
||||
var LM = require("./localModel");
|
||||
|
||||
var ImagePane = Vocabulary.inherit({
|
||||
"className": "ImagePane",
|
||||
"constructor": function(addr) {
|
||||
Vocabulary.fn.constructor.call(this, addr);
|
||||
|
||||
this._actions = [];
|
||||
this._hasPageLink = false;
|
||||
this._hasImage = false;
|
||||
this.image = null;
|
||||
},
|
||||
"addElement": function(key, element) {
|
||||
if (key === "image" && !this._hasImage) {
|
||||
this._hasImage = true;
|
||||
this.image = new File(new Address(["images", element.toString()]));
|
||||
this.addForeignController("Corax", this.image);
|
||||
"_actionActivate": function(name) {
|
||||
var actObj = standardActions[name];
|
||||
|
||||
actObj.handler(this);
|
||||
},
|
||||
"addAction": function(action) {
|
||||
var type = action.at("type").valueOf();
|
||||
var obj = Object.create(null);
|
||||
var supported = true;
|
||||
|
||||
obj.type = type;
|
||||
|
||||
switch (type) {
|
||||
case 0:
|
||||
var act = action.at("action").toString();
|
||||
var actObj = standardActions[act];
|
||||
if (actObj === undefined) {
|
||||
this.trigger("seviceMessage", "Action " + act + " is not supported in ImagePanel, skipping");
|
||||
supported = false;
|
||||
}
|
||||
var model = new LM("");
|
||||
model.enabled = true;
|
||||
model.hasLabel = true;
|
||||
model.label = new LM(actObj.name);
|
||||
model.addController(model.label);
|
||||
model.activate = this._actionActivate.bind(this, act);
|
||||
|
||||
obj.model = model;
|
||||
obj.action = act;
|
||||
break;
|
||||
}
|
||||
|
||||
if (supported) {
|
||||
this._actions.push(obj);
|
||||
this.trigger("addAction", obj.model);
|
||||
}
|
||||
},
|
||||
"addElement": function(key, element) {
|
||||
switch (key) {
|
||||
case "image":
|
||||
if (!this._hasImage) {
|
||||
this._hasImage = true;
|
||||
this.image = new File(new Address(["images", element.toString()]));
|
||||
this.addForeignController("Corax", this.image);
|
||||
}
|
||||
break;
|
||||
case "hasPageLink":
|
||||
this._hasPageLink = element.valueOf();
|
||||
break;
|
||||
case "actions":
|
||||
var size = element.length();
|
||||
for (var i = 0; i < size; ++i) {
|
||||
this.addAction(element.at(i));
|
||||
}
|
||||
}
|
||||
|
||||
Vocabulary.fn.addElement.call(this, key, element);
|
||||
},
|
||||
"getActions": function() {
|
||||
var models = [];
|
||||
for (var i = 0; i < this._actions.length; ++i) {
|
||||
models.push(this._actions[i].model);
|
||||
}
|
||||
|
||||
return models;
|
||||
},
|
||||
"getPageLink": function() {
|
||||
if (this._hasPageLink) {
|
||||
return this.data.at("pageLink").clone();
|
||||
} else {
|
||||
throw new Error("An attempt to request a page link from pane which doesn't have it");
|
||||
}
|
||||
},
|
||||
"hasImage": function() {
|
||||
return this._hasImage;
|
||||
},
|
||||
"hasPageLink": function() {
|
||||
return this._hasPageLink;
|
||||
},
|
||||
"removeElement": function(key) {
|
||||
Vocabulary.fn.removeElement.call(this, key);
|
||||
|
||||
|
@ -37,4 +108,13 @@ var ImagePane = Vocabulary.inherit({
|
|||
}
|
||||
});
|
||||
|
||||
var standardActions = {
|
||||
"play": {
|
||||
handler: function (obj) {
|
||||
window.play(obj);
|
||||
},
|
||||
name: "Play"
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = ImagePane;
|
||||
|
|
|
@ -24,6 +24,16 @@ var LocalModel = Subscribable.inherit({
|
|||
this.initialized = true;
|
||||
}
|
||||
},
|
||||
"destructor": function() {
|
||||
for (var i = 0; i < this._controllers.length; ++i) {
|
||||
this._controllers[i].destructor();
|
||||
}
|
||||
|
||||
Subscribable.fn.destructor.call(this);
|
||||
},
|
||||
"addController": function(ctrl) {
|
||||
this._controllers.push(ctrl);
|
||||
},
|
||||
"setData": function(data) {
|
||||
this.data = data;
|
||||
this.initialized = true;
|
||||
|
|
|
@ -9,15 +9,28 @@ var PanesList = List.inherit({
|
|||
"constructor": function PanesListModel(addr) {
|
||||
List.fn.constructor.call(this, addr);
|
||||
|
||||
this.actions = null;
|
||||
|
||||
this._subscriptionStart = 0;
|
||||
this._subscriptionEnd = Infinity;
|
||||
},
|
||||
"destructor": function() {
|
||||
if (this.initialized) {
|
||||
this.actions.destructor();
|
||||
}
|
||||
|
||||
List.fn.destructor.call(this);
|
||||
},
|
||||
"addElement": function(element) {
|
||||
var size = this.data.length();
|
||||
List.fn.addElement.call(this, element);
|
||||
|
||||
if (size >= this._subscriptionStart && size < this._subscriptionEnd) {
|
||||
var controller = new ImagePane(this._pairAddress["+"](new Address([element.toString()])));
|
||||
var size = this.actions.length();
|
||||
for (var i = 0; i < size; ++i) {
|
||||
controller.addAction(this.actions.at(i));
|
||||
}
|
||||
this.addController(controller);
|
||||
}
|
||||
},
|
||||
|
@ -25,6 +38,24 @@ var PanesList = List.inherit({
|
|||
List.fn.clear.call(this);
|
||||
this.clearChildren();
|
||||
},
|
||||
"_h_get": function(ev) {
|
||||
this.clear();
|
||||
|
||||
var root = ev.getData();
|
||||
var data = root.at("data");
|
||||
|
||||
if (this.initialized) {
|
||||
this.actions.destructor();
|
||||
}
|
||||
this.actions = root.at("actions").clone();
|
||||
|
||||
var size = data.length();
|
||||
for (var i = 0; i < size; ++i) {
|
||||
this.addElement(data.at(i).clone());
|
||||
}
|
||||
this.initialized = true;
|
||||
this.trigger("data");
|
||||
},
|
||||
"setSubscriptionRange": function(s, e) {
|
||||
var needStart = s !== this._subscriptionStart;
|
||||
var needEnd = e !== this._subscriptionEnd;
|
||||
|
@ -33,7 +64,8 @@ var PanesList = List.inherit({
|
|||
var oe = this._subscriptionEnd;
|
||||
this._subscriptionStart = s;
|
||||
this._subscriptionEnd = e;
|
||||
if (this._subscribed) {
|
||||
if (this._subscribed && this.initialized) {
|
||||
var size = this.actions.length();
|
||||
this.trigger("rangeStart");
|
||||
if (needStart) {
|
||||
if (s > os) {
|
||||
|
@ -47,6 +79,9 @@ var PanesList = List.inherit({
|
|||
var limit = Math.min(os, e) - s;
|
||||
for (var i = 0; i < limit; ++i) {
|
||||
var ctrl = new ImagePane(this._pairAddress["+"](new Address([this.data.at(i + s).toString()])));
|
||||
for (var a = 0; a < size; ++a) {
|
||||
ctrl.addAction(this.actions.at(a));
|
||||
}
|
||||
this.addController(ctrl, i);
|
||||
}
|
||||
}
|
||||
|
@ -59,6 +94,9 @@ var PanesList = List.inherit({
|
|||
var amount = ce - start; //it can be negative, it's fine
|
||||
for (var i = 0; i < amount; ++i) {
|
||||
var ctrl = new ImagePane(this._pairAddress["+"](new Address([this.data.at(start + i).toString()])));
|
||||
for (var a = 0; a < size; ++a) {
|
||||
ctrl.addAction(this.actions.at(a));
|
||||
}
|
||||
this.addController(ctrl);
|
||||
}
|
||||
} else if (ce < coe) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue