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

GUI: update static version

parent 389c6681
...@@ -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;
......
...@@ -84,20 +84,22 @@ ...@@ -84,20 +84,22 @@
// Precompile the templates while loading the first gadget instance // Precompile the templates while loading the first gadget instance
var gadget_klass = rJS(window); var gadget_klass = rJS(window);
initGadgetMixin(gadget_klass); initGadgetMixin(gadget_klass);
gadget_klass.declareAcquiredMethod("aq_getAttachment", "jio_getAttachment").declareAcquiredMethod("aq_putAttachment", "jio_putAttachment").declareAcquiredMethod("aq_ajax", "jio_ajax").declareAcquiredMethod("aq_getConfigurationDict", "getConfigurationDict").declareAcquiredMethod("pleaseRedirectMyHash", "pleaseRedirectMyHash").declareAcquiredMethod("whoWantsToDisplayThisDocument", "whoWantsToDisplayThisDocument").declareMethod("render", function(options) { gadget_klass.declareAcquiredMethod("aq_getAttachment", "jio_getAttachment").declareAcquiredMethod("aq_putAttachment", "jio_putAttachment").declareAcquiredMethod("aq_ajax", "jio_ajax").declareAcquiredMethod("pleaseRedirectMyHash", "pleaseRedirectMyHash").declareAcquiredMethod("whoWantsToDisplayThisDocument", "whoWantsToDisplayThisDocument").declareMethod("render", function(options) {
var gadget = this, property_list, data; var gadget = this, data;
this.props.jio_key = options.id; this.props.jio_key = options.id;
return gadget.aq_getAttachment({ return gadget.aq_getAttachment({
_id: gadget.props.jio_key, _id: gadget.props.jio_key,
_attachment: "body.json" _attachment: "body.json"
}).push(function(json) { }).push(function(json) {
data = JSON.parse(json).general; var application_configuration = {};
return gadget.aq_getConfigurationDict(); data = JSON.parse(json);
}).push(function(configuration_dict) { application_configuration = data.application_configuration.general || {};
property_list = configuration_dict["Dream-Configuration"].property_list; return gadget.getDeclaredGadget("fieldset").push(function(fieldset_gadget) {
return gadget.getDeclaredGadget("fieldset"); return fieldset_gadget.render({
}).push(function(fieldset_gadget) { value: data.general,
return fieldset_gadget.render(property_list, data); property_definition: application_configuration
});
});
}); });
}).declareMethod("startService", function() { }).declareMethod("startService", function() {
return waitForRunSimulation(this); return waitForRunSimulation(this);
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
title: "Create Document" title: "Create Document"
} }
}, },
// TODO: remove this once everything is merged.
Input: { Input: {
view: { view: {
gadget: "Input_viewProductionLine", gadget: "Input_viewProductionLine",
...@@ -35,50 +36,32 @@ ...@@ -35,50 +36,32 @@
view_wip_part_spreadsheet: { view_wip_part_spreadsheet: {
gadget: "Input_viewWipPartSpreadsheet", gadget: "Input_viewWipPartSpreadsheet",
type: "object_view", type: "object_view",
title: "WIP Part Spreadsheet", title: "WIP Part Spreadsheet"
condition: function(gadget) {
return gadget.props.configuration_dict["Dream-Configuration"].gui.wip_part_spreadsheet;
}
}, },
view_shift_spreadsheet: { view_shift_spreadsheet: {
gadget: "Input_viewShiftSpreadsheet", gadget: "Input_viewShiftSpreadsheet",
type: "object_view", type: "object_view",
title: "Shift Spreadsheet", title: "Shift Spreadsheet"
condition: function(gadget) {
return gadget.props.configuration_dict["Dream-Configuration"].gui.shift_spreadsheet;
}
}, },
view_available_capacity_spreadsheet: { view_available_capacity_spreadsheet: {
gadget: "Input_viewAvailableCapacitySpreadsheet", gadget: "Input_viewAvailableCapacitySpreadsheet",
type: "object_view", type: "object_view",
title: "Available Capacity Spreadsheet", title: "Available Capacity Spreadsheet"
condition: function(gadget) {
return gadget.props.configuration_dict["Dream-Configuration"].gui.capacity_by_project_spreadsheet;
}
}, },
view_required_capacity_spreadsheet: { view_required_capacity_spreadsheet: {
gadget: "Input_viewRequiredCapacitySpreadsheet", gadget: "Input_viewRequiredCapacitySpreadsheet",
type: "object_view", type: "object_view",
title: "Required Capacity Spreadsheet", title: "Required Capacity Spreadsheet"
condition: function(gadget) {
return gadget.props.configuration_dict["Dream-Configuration"].gui.capacity_by_station_spreadsheet;
}
}, },
view_dp_capacity_spreadsheet: { view_dp_capacity_spreadsheet: {
gadget: "Input_viewDemandPlanningCapacitySpreadsheet", gadget: "Input_viewDemandPlanningCapacitySpreadsheet",
type: "object_view", type: "object_view",
title: "Demand Planning Required Capacity Spreadsheet", title: "Demand Planning Required Capacity Spreadsheet"
condition: function(gadget) {
return gadget.props.configuration_dict["Dream-Configuration"].gui.dp_capacity_spreadsheet;
}
}, },
view_dp_route_spreadsheet: { view_dp_route_spreadsheet: {
gadget: "Input_viewDemandPlanningRouteSpreadsheet", gadget: "Input_viewDemandPlanningRouteSpreadsheet",
type: "object_view", type: "object_view",
title: "Demand Planning Route Spreadsheet", title: "Demand Planning Route Spreadsheet"
condition: function(gadget) {
return gadget.props.configuration_dict["Dream-Configuration"].gui.dp_route_spreadsheet;
}
}, },
view_simu: { view_simu: {
gadget: "Input_viewSimulation", gadget: "Input_viewSimulation",
...@@ -100,66 +83,42 @@ ...@@ -100,66 +83,42 @@
view: { view: {
gadget: "Output_viewStationUtilisationGraph", gadget: "Output_viewStationUtilisationGraph",
type: "object_view", type: "object_view",
title: "Stations Utilization", title: "Stations Utilization"
condition: function(gadget) {
return gadget.props.configuration_dict["Dream-Configuration"].gui.station_utilisation_graph;
}
}, },
download_excel_spreadsheet: { download_excel_spreadsheet: {
gadget: "Output_viewDownloadExcelSpreadsheet", gadget: "Output_viewDownloadExcelSpreadsheet",
type: "object_view", type: "object_view",
title: "Download Excel Spreadsheet", title: "Download Excel Spreadsheet"
condition: function(gadget) {
return gadget.props.configuration_dict["Dream-Configuration"].gui.download_excel_spreadsheet;
}
}, },
view_capacity_utilization: { view_capacity_utilization: {
gadget: "Output_viewCapacityUtilisationGraph", gadget: "Output_viewCapacityUtilisationGraph",
type: "object_view", type: "object_view",
title: "Capacity Utilization", title: "Capacity Utilization"
condition: function(gadget) {
return gadget.props.configuration_dict["Dream-Configuration"].gui.capacity_utilisation_graph;
}
}, },
view_queue_stat: { view_queue_stat: {
gadget: "Output_viewQueueStatGraph", gadget: "Output_viewQueueStatGraph",
type: "object_view", type: "object_view",
title: "Queues Statistics", title: "Queues Statistics"
condition: function(gadget) {
return gadget.props.configuration_dict["Dream-Configuration"].gui.queue_stat;
}
}, },
view_exit_stat: { view_exit_stat: {
gadget: "Output_viewExitStatistics", gadget: "Output_viewExitStatistics",
type: "object_view", type: "object_view",
title: "Exit Statistics", title: "Exit Statistics"
condition: function(gadget) {
return gadget.props.configuration_dict["Dream-Configuration"].gui.exit_stat;
}
}, },
view_gantt: { view_gantt: {
gadget: "Output_viewJobGantt", gadget: "Output_viewJobGantt",
type: "object_view", type: "object_view",
title: "Job Gantt", title: "Job Gantt"
condition: function(gadget) {
return gadget.props.configuration_dict["Dream-Configuration"].gui.job_gantt;
}
}, },
view_schedule: { view_schedule: {
gadget: "Output_viewJobScheduleSpreadsheet", gadget: "Output_viewJobScheduleSpreadsheet",
type: "object_view", type: "object_view",
title: "Job Schedule", title: "Job Schedule"
condition: function(gadget) {
return gadget.props.configuration_dict["Dream-Configuration"].gui.job_schedule_spreadsheet;
}
}, },
view_debug: { view_debug: {
gadget: "Output_viewDebugJson", gadget: "Output_viewDebugJson",
type: "object_view", type: "object_view",
title: "Debug JSON", title: "Debug JSON"
condition: function(gadget) {
return gadget.props.configuration_dict["Dream-Configuration"].gui.debug_json;
}
} }
} }
}, panel_template, navigation_template, active_navigation_template, error_template, gadget_klass = rJS(window); }, panel_template, navigation_template, active_navigation_template, error_template, gadget_klass = rJS(window);
...@@ -328,8 +287,6 @@ ...@@ -328,8 +287,6 @@
id: param_list[0], id: param_list[0],
result: param_list[1] result: param_list[1]
}); });
}).allowPublicAcquisition("getConfigurationDict", function() {
return this.props.configuration_dict;
}).ready(function() { }).ready(function() {
if (panel_template === undefined) { if (panel_template === undefined) {
// XXX Only works as root gadget // XXX Only works as root gadget
...@@ -354,21 +311,12 @@ ...@@ -354,21 +311,12 @@
$(panel).trigger("create"); $(panel).trigger("create");
}); });
}).ready(function(g) { }).ready(function(g) {
var jio_gadget;
return g.getDeclaredGadget("jio").push(function(gadget) { return g.getDeclaredGadget("jio").push(function(gadget) {
jio_gadget = gadget; return gadget.createJio({
return jio_gadget.createJio({
type: "local", type: "local",
username: "dream", username: "dream",
applicationname: "dream" applicationname: "dream"
}); });
}).push(function() {
// XXX Hardcoded relative URL
return jio_gadget.ajax({
url: "../../getConfigurationDict"
});
}).push(function(evt) {
g.props.configuration_dict = JSON.parse(evt.target.responseText);
}); });
}).declareMethod("render", function(options) { }).declareMethod("render", function(options) {
var gadget = this, back_kw = { var gadget = this, back_kw = {
...@@ -389,8 +337,24 @@ ...@@ -389,8 +337,24 @@
back_kw.id = options.id; back_kw.id = options.id;
} }
} }
return gadget.getDeclaredGadget("jio").push(function(jio_gadget) {
if (options.id) {
return jio_gadget.getAttachment({
_id: options.id,
_attachment: "body.json"
});
}
}).push(function(result) {
var data;
if (result) {
data = JSON.parse(result);
gadget.props.data = data;
portal_types.Input = data.application_configuration.input;
portal_types.Output = data.application_configuration.output;
}
// Get the action information // Get the action information
return gadget.declareGadget(portal_types[portal_type][options.action].gadget + ".html").push(function(g) { return gadget.declareGadget(portal_types[portal_type][options.action].gadget + ".html");
}).push(function(g) {
page_gadget = g; page_gadget = g;
if (page_gadget.render !== undefined) { if (page_gadget.render !== undefined) {
return page_gadget.render(options); return page_gadget.render(options);
......
...@@ -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_definition.description || 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 || "",
key: property.id,
value: value, value: value,
items: choice, property_definition: property_definition
"default": default_opt
}
}); });
}).push(function() { }).push(function() {
return sub_gadget.getElement(); return sub_gadget.getElement();
...@@ -59,10 +51,18 @@ ...@@ -59,10 +51,18 @@
}); });
} }
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
// XXX should not be defined here
if (property_name !== "coordinate" && property_name !== "_class") {
addField(property_name, property_definition, value);
}
}); });
}); });
return queue; return queue;
...@@ -75,8 +75,8 @@ ...@@ -75,8 +75,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]) {
......
...@@ -3,13 +3,15 @@ ...@@ -3,13 +3,15 @@
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<link rel="stylesheet" href="../lib/jquery-ui.css"> <link rel="stylesheet" href="../lib/jquery-ui.css">
<link rel="stylesheet" href="../lib/jquerymobile.css">
<link rel="stylesheet" href="jsplumb.css"> <link rel="stylesheet" href="jsplumb.css">
<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">
...@@ -22,9 +24,9 @@ ...@@ -22,9 +24,9 @@
</script> </script>
<template id="popup-edit-template"> <template id="popup-edit-template">
<div id="node-edit-popup" data-position-to="origin"> <div id="edit-popup" data-position-to="origin">
<div data-role="header" data-theme="a"> <div data-role="header" data-theme="a">
<h1 class="node_class">Node edition</h1> <h1 class="node_class">Edit properties</h1>
<a href="#" data-rel="back" class="ui-btn ui-corner-all ui-shadow ui-btn-a ui-icon-delete ui-btn-icon-notext ui-btn-right">Close</a> <a href="#" data-rel="back" class="ui-btn ui-corner-all ui-shadow ui-btn-a ui-icon-delete ui-btn-icon-notext ui-btn-right">Close</a>
</div> </div>
<br/> <br/>
......
This diff is collapsed.
This diff is collapsed.
...@@ -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;
tool.dataset.class_name = JSON.stringify(key);
Object.keys(_class.css || {}).forEach(function(k) {
tool.style[k] = _class.css[k];
}); });
tools_container.appendChild(tool);
} }
}); });
g.props.element.querySelector(".tools").appendChild(tools_container); 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