Commit fa89e89d authored by Jérome Perrin's avatar Jérome Perrin

update static version

parent 84ce9458
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
(function(window, rJS, RSVP, loopEventListener) { (function(window, rJS, RSVP, loopEventListener) {
"use strict"; "use strict";
var gadget_klass = rJS(window); var gadget_klass = rJS(window);
// TODO: save on parent gadget
function saveGraph(evt) { function saveGraph(evt) {
var gadget = this; var gadget = this;
return new RSVP.Queue().push(function() { return new RSVP.Queue().push(function() {
...@@ -11,23 +12,12 @@ ...@@ -11,23 +12,12 @@
} }
return gadget.getDeclaredGadget("productionline_graph"); return gadget.getDeclaredGadget("productionline_graph");
}).push(function(graph_gadget) { }).push(function(graph_gadget) {
return graph_gadget.getData(); return graph_gadget.getContent();
}).push(function(data) {
graph_data = data;
// Always get a fresh version, to prevent deleting spreadsheet & co
return gadget.aq_getAttachment({
_id: gadget.props.jio_key,
_attachment: "body.json"
});
}).push(function(body) { }).push(function(body) {
var data = JSON.parse(body), json_graph_data = JSON.parse(graph_data);
data.nodes = json_graph_data.nodes;
data.edges = json_graph_data.edges;
data.preference = json_graph_data.preference;
return gadget.aq_putAttachment({ return gadget.aq_putAttachment({
_id: gadget.props.jio_key, _id: gadget.props.jio_key,
_attachment: "body.json", _attachment: "body.json",
_data: JSON.stringify(data, null, 2), _data: JSON.stringify(JSON.parse(body), null, 2),
_mimetype: "application/json" _mimetype: "application/json"
}); });
}).push(function() { }).push(function() {
...@@ -56,7 +46,7 @@ ...@@ -56,7 +46,7 @@
} }
this.timeout = window.setTimeout(saveGraph.bind(this), 100); this.timeout = window.setTimeout(saveGraph.bind(this), 100);
}).declareMethod("render", function(options) { }).declareMethod("render", function(options) {
var jio_key = options.id, gadget = this; var jio_key = options.id, gadget = this, data;
gadget.props.jio_key = jio_key; gadget.props.jio_key = jio_key;
return new RSVP.Queue().push(function() { return new RSVP.Queue().push(function() {
/*jslint nomen: true*/ /*jslint nomen: true*/
...@@ -65,11 +55,12 @@ ...@@ -65,11 +55,12 @@
_attachment: "body.json" _attachment: "body.json"
}), gadget.getDeclaredGadget("productionline_graph") ]); }), gadget.getDeclaredGadget("productionline_graph") ]);
}).push(function(result_list) { }).push(function(result_list) {
return result_list[1].render(result_list[0]); data = result_list[0];
return result_list[1].render(data);
}).push(function() { }).push(function() {
return gadget.getDeclaredGadget("productionline_toolbox"); return gadget.getDeclaredGadget("productionline_toolbox");
}).push(function(toolbox_gadget) { }).push(function(toolbox_gadget) {
toolbox_gadget.render(); toolbox_gadget.render(data);
}); });
}).declareMethod("startService", function() { }).declareMethod("startService", function() {
var g = this, graph; var g = this, graph;
......
...@@ -9,47 +9,39 @@ ...@@ -9,47 +9,39 @@
// Precompile the templates while loading the first gadget instance // Precompile the templates while loading the first gadget instance
var gadget_klass = rJS(window), source = gadget_klass.__template_element.getElementById("label-template").innerHTML, label_template = Handlebars.compile(source); var gadget_klass = rJS(window), source = gadget_klass.__template_element.getElementById("label-template").innerHTML, label_template = Handlebars.compile(source);
initGadgetMixin(gadget_klass); initGadgetMixin(gadget_klass);
gadget_klass.declareMethod("render", function(property_list, data, key) { gadget_klass.declareMethod("render", function(options, node_id) {
var gadget = this, queue, value, property; // XXX node_id is added like a property so that one can change the node
gadget.key = key; // id
var gadget = this, queue;
gadget.props.key = options.key;
// used for recursive fieldsets // used for recursive fieldsets
gadget.props.field_gadget_list = []; gadget.props.field_gadget_list = [];
function addField(property, value) { function addField(property_id, property_definition, value) {
var sub_gadget; var sub_gadget;
queue.push(function() { queue.push(function() {
// XXX this is incorrect for recursive fieldsets. // XXX this is incorrect for recursive fieldsets.
// we should use nested fieldset with legend // we should use nested fieldset with legend
gadget.props.element.insertAdjacentHTML("beforeend", label_template({ gadget.props.element.insertAdjacentHTML("beforeend", label_template({
"for": property.id, "for": property_id,
name: property.name || property.id name: property_definition.name || property_id
})); }));
if (property._class === "Dream.PropertyList") { if (property_definition.type === "object") {
// Create a recursive fieldset for this key. // Create a recursive fieldset for this key.
return gadget.declareGadget("../fieldset/index.html"); return gadget.declareGadget("../fieldset/index.html");
} }
if (property.type === "number") { if (property_definition.type === "number") {
return gadget.declareGadget("../number_field/index.html"); return gadget.declareGadget("../number_field/index.html");
} }
if (property.choice) { if (property_definition.enum) {
return gadget.declareGadget("../list_field/index.html"); return gadget.declareGadget("../list_field/index.html");
} }
return gadget.declareGadget("../string_field/index.html"); return gadget.declareGadget("../string_field/index.html");
}).push(function(gg) { }).push(function(gg) {
sub_gadget = gg; sub_gadget = gg;
var choice = property.choice || [], default_opt = choice[0] ? [ choice[0][1] ] : [ "" ];
value = data[property.id] === undefined ? value : data[property.id];
if (gg.__title === "Fieldset") {
// XXX there must be a better way instead of using __title ?
return gg.render(property.property_list, value, property.id);
}
return sub_gadget.render({ return sub_gadget.render({
field_json: { key: property_id,
title: property.description || "", value: value,
key: property.id, property_definition: property_definition
value: value,
items: choice,
"default": default_opt
}
}); });
}).push(function() { }).push(function() {
return sub_gadget.getElement(); return sub_gadget.getElement();
...@@ -59,10 +51,17 @@ ...@@ -59,10 +51,17 @@
}); });
} }
queue = new RSVP.Queue().push(function() { queue = new RSVP.Queue().push(function() {
Object.keys(property_list).forEach(function(i) { if (node_id) {
property = property_list[i]; addField("id", {
value = property._default === undefined ? "" : property._default; type: "string"
addField(property, value); }, node_id);
}
Object.keys(options.property_definition.properties).forEach(function(property_name) {
var property_definition = options.property_definition.properties[property_name], value = (options.value || {})[property_name] === undefined ? property_definition._default : options.value[property_name];
// XXX some properties are not editable
if (property_name !== "coordinate" && property_name !== "_class") {
addField(property_name, property_definition, value);
}
}); });
}); });
return queue; return queue;
...@@ -75,8 +74,8 @@ ...@@ -75,8 +74,8 @@
return RSVP.all(promise_list); return RSVP.all(promise_list);
}).push(function(result_list) { }).push(function(result_list) {
var name, result = {}, content = result; var name, result = {}, content = result;
if (gadget.key) { if (gadget.props.key) {
content = result[gadget.key] = {}; content = result[gadget.props.key] = {};
} }
for (i = 0; i < result_list.length; i += 1) { for (i = 0; i < result_list.length; i += 1) {
for (name in result_list[i]) { for (name in result_list[i]) {
......
...@@ -7,9 +7,10 @@ ...@@ -7,9 +7,10 @@
<script src="../lib/jquery.js"></script> <script src="../lib/jquery.js"></script>
<script src="../lib/jquery-ui.js"></script> <script src="../lib/jquery-ui.js"></script>
<script src="../lib/jquerymobile.js"></script>
<script src="../lib/rsvp.min.js"></script> <script src="../lib/rsvp.min.js"></script>
<script src="../lib/renderjs.min.js"></script> <script src="../lib/renderjs.min.js"></script>
<script src="../lib/jquery.jsplumb.min.js"></script> <script src="../lib/jquery.jsplumb.js"></script>
<script src="../lib/handlebars.min.js"></script> <script src="../lib/handlebars.min.js"></script>
<script id="node-template" type="text/x-handlebars-template"> <script id="node-template" type="text/x-handlebars-template">
......
This diff is collapsed.
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="../lib/qunit.css">
<script src="../lib/rsvp.min.js"></script>
<script src="../lib/renderjs.min.js"></script>
<script src="../lib/qunit.js"></script>
<script src="../lib/jquery.js"></script>
<script src="../lib/jquery.simulate.js"></script>
<script src="test.js"></script>
</head>
<body>
<div id="qunit"></div>
<div id="qunit-fixture"></div>
</body>
</html>
This diff is collapsed.
...@@ -949,17 +949,17 @@ ...@@ -949,17 +949,17 @@
newFunction = newFunction || function() { }; newFunction = newFunction || function() { };
return function() { return function() {
var r = null; var r = null;
try { //try {
r = newFunction.apply(this, arguments); r = newFunction.apply(this, arguments);
} catch (e) { //} catch (e) {
jsPlumbUtil.log("jsPlumb function failed : " + e); // jsPlumbUtil.log("jsPlumb function failed : " + e);
} //}
if (returnOnThisValue == null || (r !== returnOnThisValue)) { if (returnOnThisValue == null || (r !== returnOnThisValue)) {
try { //try {
r = wrappedFunction.apply(this, arguments); r = wrappedFunction.apply(this, arguments);
} catch (e) { //} catch (e) {
jsPlumbUtil.log("wrapped function failed : " + e); // jsPlumbUtil.log("wrapped function failed : " + e);
} //}
} }
return r; return r;
}; };
......
...@@ -12,17 +12,18 @@ ...@@ -12,17 +12,18 @@
g.element = element; g.element = element;
}); });
}).declareMethod("render", function(options) { }).declareMethod("render", function(options) {
var select = this.element.getElementsByTagName("select")[0], i, template, field_json = options.field_json, tmp = ""; var select = this.element.getElementsByTagName("select")[0], i, template, tmp = "";
select.setAttribute("name", field_json.key); select.setAttribute("name", options.key);
for (i = 0; i < field_json.items.length; i += 1) { for (i = 0; i < options.property_definition.enum.length; i += 1) {
if (field_json.items[i][1] === field_json.value) { if (options.property_definition.enum[i] === options.value) {
template = selected_option_template; template = selected_option_template;
} else { } else {
template = option_template; template = option_template;
} }
// XXX value and text are always same in json schema
tmp += template({ tmp += template({
value: field_json.items[i][1], value: options.property_definition.enum[i],
text: field_json.items[i][0] text: options.property_definition.enum[i]
}); });
} }
select.innerHTML += tmp; select.innerHTML += tmp;
......
...@@ -6,10 +6,10 @@ ...@@ -6,10 +6,10 @@
gadget.element = element; gadget.element = element;
}); });
}).declareMethod("render", function(options) { }).declareMethod("render", function(options) {
var input = this.element.querySelector("input"), field_json = options.field_json || {}; var input = this.element.querySelector("input");
input.setAttribute("value", field_json.value); input.setAttribute("value", options.value);
input.setAttribute("name", field_json.key); input.setAttribute("name", options.key);
input.setAttribute("title", field_json.title); input.setAttribute("title", options.title || options.key);
}).declareMethod("getContent", function() { }).declareMethod("getContent", function() {
var input = this.element.querySelector("input"), result = {}; var input = this.element.querySelector("input"), result = {};
if (input.value !== "") { if (input.value !== "") {
......
...@@ -6,10 +6,10 @@ ...@@ -6,10 +6,10 @@
gadget.element = element; gadget.element = element;
}); });
}).declareMethod("render", function(options) { }).declareMethod("render", function(options) {
var input = this.element.querySelector("input"), field_json = options.field_json || {}; var input = this.element.querySelector("input");
input.setAttribute("value", field_json.value || ""); input.setAttribute("value", options.value || "");
input.setAttribute("name", field_json.key); input.setAttribute("name", options.key);
input.setAttribute("title", field_json.title); input.setAttribute("title", options.title || options.key);
}).declareMethod("getContent", function() { }).declareMethod("getContent", function() {
var input = this.element.querySelector("input"), result = {}; var input = this.element.querySelector("input"), result = {};
result[input.getAttribute("name")] = input.value; result[input.getAttribute("name")] = input.value;
......
...@@ -5,21 +5,8 @@ ...@@ -5,21 +5,8 @@
<link rel="stylesheet" href="../lib/jquery-ui.css"> <link rel="stylesheet" href="../lib/jquery-ui.css">
<link rel="stylesheet" href="toolbox.css"> <link rel="stylesheet" href="toolbox.css">
<script src="../lib/jquery.js"></script>
<script src="../lib/jquery-ui.js"></script>
<script src="../lib/rsvp.min.js"></script> <script src="../lib/rsvp.min.js"></script>
<script src="../lib/renderjs.min.js"></script> <script src="../lib/renderjs.min.js"></script>
<script src="../lib/handlebars.min.js"></script>
<script id="tool-template" type="text/x-handlebars-template">
<div id="{{key}}"
class="tool {{key}}"
draggable="true">
{{name}}
<ul/>
</div>
</script>
<script src="../dream/mixin_gadget.js"></script> <script src="../dream/mixin_gadget.js"></script>
<script src="../dream/mixin_promise.js"></script> <script src="../dream/mixin_promise.js"></script>
......
/*global window, document, RSVP, rJS, Handlebars, initGadgetMixin*/ /*global window, document, RSVP, rJS, initGadgetMixin*/
(function(window, document, RSVP, rJS, Handlebars, initGadgetMixin) { (function(window, document, RSVP, rJS, initGadgetMixin) {
"use strict"; "use strict";
/*jslint nomen: true*/ /*jslint nomen: true*/
var gadget_klass = rJS(window), tool_template_source = gadget_klass.__template_element.getElementById("tool-template").innerHTML, tool_template = Handlebars.compile(tool_template_source); var gadget_klass = rJS(window);
function waitForDragstart(tool) { function waitForDragstart(tool) {
var callback; var callback;
function canceller() { function canceller() {
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
function itsANonResolvableTrap(resolve, reject) { function itsANonResolvableTrap(resolve, reject) {
callback = function(evt) { callback = function(evt) {
try { try {
evt.dataTransfer.setData("text/html", tool.outerHTML); evt.dataTransfer.setData("application/json", tool.dataset.class_name);
} catch (e) { } catch (e) {
reject(e); reject(e);
} }
...@@ -24,22 +24,28 @@ ...@@ -24,22 +24,28 @@
return new RSVP.Promise(itsANonResolvableTrap, canceller); return new RSVP.Promise(itsANonResolvableTrap, canceller);
} }
initGadgetMixin(gadget_klass); initGadgetMixin(gadget_klass);
gadget_klass.declareAcquiredMethod("getConfigurationDict", "getConfigurationDict").declareMethod("render", function() { gadget_klass.declareMethod("render", function(json_data) {
var g = this; var data = JSON.parse(json_data), tools_container = document.createElement("div");
return g.getConfigurationDict().push(function(config_dict) { /* display all nodes in the palette.
var tools_container = document.createElement("div"); */
tools_container.className = "tools-container"; tools_container.className = "tools-container";
Object.keys(config_dict).forEach(function(key) { Object.keys(data.class_definition).forEach(function(key) {
var name = config_dict[key].name || key.split("-")[1]; var _class = data.class_definition[key], tool;
if (key !== "Dream-Configuration") { // XXX "expand" the json schema "allOF" etc
tools_container.innerHTML += tool_template({ if (_class._class === "node") {
key: key, tool = document.createElement("div");
name: name // XXX maybe allow to configure the class name ?
}); tool.className = "tool " + key;
} tool.textContent = _class.name || key;
}); tool.draggable = true;
g.props.element.querySelector(".tools").appendChild(tools_container); tool.dataset.class_name = JSON.stringify(key);
Object.keys(_class.css || {}).forEach(function(k) {
tool.style[k] = _class.css[k];
});
tools_container.appendChild(tool);
}
}); });
this.props.element.querySelector(".tools").appendChild(tools_container);
}).declareMethod("startService", function() { }).declareMethod("startService", function() {
var promiseArray = []; var promiseArray = [];
[].forEach.call(this.props.element.querySelectorAll(".tool"), function(tool) { [].forEach.call(this.props.element.querySelectorAll(".tool"), function(tool) {
...@@ -47,4 +53,4 @@ ...@@ -47,4 +53,4 @@
}); });
return RSVP.all(promiseArray); return RSVP.all(promiseArray);
}); });
})(window, document, RSVP, rJS, Handlebars, initGadgetMixin); })(window, document, RSVP, rJS, initGadgetMixin);
\ No newline at end of file \ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment