Commit ab2056a5 authored by Thibaut Frain's avatar Thibaut Frain Committed by Jérome Perrin

publish static version

parent 3349a0fe
......@@ -7,6 +7,8 @@
<script src="../lib/rsvp.min.js" type="text/javascript"></script>
<script src="../lib/renderjs.min.js" type="text/javascript"></script>
<script src="mixin_promise.js" type="text/javascript"></script>
<script src="Input_viewProductionLine.js" type="text/javascript"></script>
</head>
<body>
......@@ -14,5 +16,9 @@
data-gadget-scope="productionline_toolbox"></div>
<div data-gadget-url="../jsplumb/index.html"
data-gadget-scope="productionline_graph"></div>
<form class="save_form">
<button type="submit" class="ui-btn ui-btn-b ui-btn-inline
ui-icon-edit ui-btn-icon-right">Save</button>
</form>
</body>
</html>
/*global window, rJS, RSVP */
(function(window, rJS, RSVP) {
/*global window, rJS, RSVP, loopEventListener*/
(function(window, rJS, RSVP, loopEventListener) {
"use strict";
var gadget_klass = rJS(window);
function saveGraph(evt) {
var gadget = this, graph_data, graph_gadget;
return new RSVP.Queue().push(function() {
// Prevent double click
evt.target.getElementsByClassName("ui-btn")[0].disabled = true;
return gadget.getDeclaredGadget("productionline_graph");
}).push(function(graphgadget) {
graph_gadget = graphgadget;
return graph_gadget.getData();
}).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) {
var data = JSON.parse(body);
data.nodes = JSON.parse(graph_data).nodes;
data.edges = JSON.parse(graph_data).edges;
data.preference = JSON.parse(graph_data).preference;
return gadget.aq_putAttachment({
_id: gadget.props.jio_key,
_attachment: "body.json",
_data: JSON.stringify(data, null, 2),
_mimetype: "application/json"
});
}).push(function() {
evt.target.getElementsByClassName("ui-btn")[0].disabled = false;
});
}
function waitForSave(gadget) {
return loopEventListener(gadget.props.element.getElementsByClassName("save_form")[0], "submit", false, saveGraph.bind(gadget));
}
gadget_klass.ready(function(g) {
g.props = {};
}).ready(function(g) {
return g.getElement().push(function(element) {
g.props.element = element;
});
}).declareAcquiredMethod("aq_getAttachment", "jio_getAttachment").declareMethod("render", function(options) {
}).declareAcquiredMethod("aq_getAttachment", "jio_getAttachment").declareAcquiredMethod("aq_putAttachment", "jio_putAttachment").declareMethod("render", function(options) {
var jio_key = options.id, gadget = this;
gadget.props.jio_key = jio_key;
return new RSVP.Queue().push(function() {
......@@ -30,7 +64,7 @@
graph = graph_gadget;
return g.getDeclaredGadget("productionline_toolbox");
}).push(function(toolbox) {
return RSVP.all([ graph.startService(), toolbox.startService() ]);
return RSVP.all([ graph.startService(), toolbox.startService(), waitForSave(g) ]);
});
});
})(window, rJS, RSVP);
\ No newline at end of file
})(window, rJS, RSVP, loopEventListener);
\ No newline at end of file
......@@ -20,7 +20,9 @@
</head>
<body>
<form class="save_form">
<fieldset class="simulation_parameters">
<fieldset>
<div data-gadget-url="../fieldset/index.html"
data-gadget-scope="fieldset"></div>
</fieldset>
<button type="submit" class="ui-btn ui-btn-b ui-btn-inline
ui-icon-refresh ui-btn-icon-right">Run Simulation</button>
......
/*global rJS, RSVP, jQuery, Handlebars,
promiseEventListener, initGadgetMixin */
/*global rJS, RSVP, jQuery, promiseEventListener, initGadgetMixin */
/*jslint nomen: true */
(function(window, rJS, RSVP, $, Handlebars, promiseEventListener, initGadgetMixin) {
(function(window, rJS, RSVP, $, promiseEventListener, initGadgetMixin) {
"use strict";
function saveForm(gadget) {
var general = {};
return new RSVP.Queue().push(function() {
var general = {}, field_gadget_list;
return gadget.getDeclaredGadget("fieldset").push(function(fieldset_gadget) {
return fieldset_gadget.getFieldGadgetList();
}).push(function(field_gadgets) {
field_gadget_list = field_gadgets;
}).push(function() {
var i, promise_list = [];
for (i = 0; i < gadget.props.gadget_list.length; i += 1) {
promise_list.push(gadget.props.gadget_list[i].getContent());
for (i = 0; i < field_gadget_list.length; i += 1) {
promise_list.push(field_gadget_list[i].getContent());
}
return RSVP.all(promise_list);
}).push(function(result_list) {
......@@ -98,57 +101,24 @@
// Handlebars
/////////////////////////////////////////////////////////////////
// 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);
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("whoWantToDisplayThisDocument", "whoWantToDisplayThisDocument").declareMethod("render", function(options) {
var i, gadget = this, property, parent_element = gadget.props.element.querySelector(".simulation_parameters"), value, queue, data;
var gadget = this, property_list, data;
this.props.jio_key = options.id;
function addField(property, value) {
var sub_gadget;
queue.push(function() {
parent_element.insertAdjacentHTML("beforeend", label_template({
label: property.name || property.id
}));
if (property.type === "number") {
return gadget.declareGadget("../number_field/index.html");
}
return gadget.declareGadget("../string_field/index.html");
}).push(function(gg) {
sub_gadget = gg;
value = data[property.id] || value;
return sub_gadget.render({
field_json: {
title: property.description || "",
key: property.id,
value: value
}
});
}).push(function() {
return sub_gadget.getElement();
}).push(function(sub_element) {
parent_element.appendChild(sub_element);
gadget.props.gadget_list.push(sub_gadget);
});
}
queue = gadget.aq_getAttachment({
return gadget.aq_getAttachment({
_id: gadget.props.jio_key,
_attachment: "body.json"
}).push(function(json) {
data = JSON.parse(json).general;
return gadget.aq_getConfigurationDict();
}).push(function(configuration_dict) {
var property_list = configuration_dict["Dream-Configuration"].property_list;
gadget.props.gadget_list = [];
for (i = 0; i < property_list.length; i += 1) {
property = property_list[i];
if (property._class === "Dream.Property") {
value = property._default || "";
addField(property, value);
}
}
property_list = configuration_dict["Dream-Configuration"].property_list;
return gadget.getDeclaredGadget("fieldset");
}).push(function(fieldset_gadget) {
return fieldset_gadget.render(property_list, data);
});
return queue;
}).declareMethod("startService", function() {
return waitForRunSimulation(this);
});
})(window, rJS, RSVP, jQuery, Handlebars, promiseEventListener, initGadgetMixin);
\ No newline at end of file
})(window, rJS, RSVP, jQuery, promiseEventListener, initGadgetMixin);
\ No newline at end of file
/*global rJS, RSVP, jQuery, Handlebars,
promiseEventListener, initGadgetMixin*/
/*jslint nomen: true */
(function(window, rJS, RSVP, Handlebars, initGadgetMixin) {
"use strict";
/////////////////////////////////////////////////////////////////
// Handlebars
/////////////////////////////////////////////////////////////////
// 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);
initGadgetMixin(gadget_klass);
gadget_klass.declareMethod("render", function(property_list, data) {
var gadget = this, queue, value, property;
gadget.props.field_gadget_list = [];
function addField(property, value) {
var sub_gadget;
queue.push(function() {
gadget.props.element.insertAdjacentHTML("beforeend", label_template({
"for": property.id,
name: property.name || property.id
}));
if (property.type === "number") {
return gadget.declareGadget("../number_field/index.html");
}
if (property.choice) {
return gadget.declareGadget("../list_field/index.html");
}
return gadget.declareGadget("../string_field/index.html");
}).push(function(gg) {
var choice = property.choice || [], default_opt = choice[0] ? [ choice[0][1] ] : [ "" ];
sub_gadget = gg;
value = data[property.id] || value;
return sub_gadget.render({
field_json: {
title: property.description || "",
key: property.id,
value: value,
items: choice,
"default": default_opt
}
});
}).push(function() {
return sub_gadget.getElement();
}).push(function(sub_element) {
gadget.props.element.appendChild(sub_element);
gadget.props.field_gadget_list.push(sub_gadget);
});
}
queue = new RSVP.Queue().push(function() {
Object.keys(property_list).forEach(function(i) {
property = property_list[i];
if (property._class === "Dream.Property") {
value = property._default || "";
addField(property, value);
}
});
});
return queue;
}).declareMethod("getFieldGadgetList", function() {
return this.props.field_gadget_list;
});
})(window, rJS, RSVP, Handlebars, initGadgetMixin);
\ No newline at end of file
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Fieldset</title>
<script src="../lib/rsvp.min.js" type="text/javascript"></script>
<script src="../lib/renderjs.min.js" type="text/javascript"></script>
<script src="../lib/handlebars.min.js" type="text/javascript"></script>
<script src="../lib/jquery.js" type="text/javascript"></script>
<script src="../lib/jquerymobile.js" type="text/javascript"></script>
<script id="label-template" type="text/x-handlebars-template">
<label for="{{for}}">{{name}}</label>
</script>
<script src="../dream/mixin_gadget.js" type="text/javascript"></script>
<script src="fieldset.js" type="text/javascript"></script>
</head>
<body>
</body>
</html>
......@@ -16,11 +16,21 @@
<div class="window {{class}}"
id="{{element_id}}"
title="{{title}}">
{{id}}
{{name}}
<div class="ep"></div>
</div>
</script>
<template id="popup-edit-template">
<div id="node-edit-popup">
<form>
<fieldset></fieldset>
<input type="button" value="Delete">
<input type="submit" value="Validate">
</form>
</div>
</template>
<script src="../dream/mixin_gadget.js"></script>
<script src="../dream/mixin_promise.js"></script>
......
This diff is collapsed.
......@@ -4,15 +4,24 @@
/*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);
function waitForDragstart(tool) {
var callback;
function canceller() {
if (callback !== undefined) {
tool.removeEventListener("dragstart", callback, false);
}
}
/*jslint unparam: true*/
var callback = function(evt) {
function itsANonResolvableTrap(resolve, reject) {
callback = function(evt) {
try {
evt.dataTransfer.setData("text/html", tool.outerHTML);
} catch (e) {
reject(e);
}
};
return new RSVP.Promise(function(resolve, reject) {
tool.addEventListener("dragstart", callback, false);
}, function() {
tool.removeEventListener("dragstart", callback, false);
});
}
return new RSVP.Promise(itsANonResolvableTrap, canceller);
}
initGadgetMixin(gadget_klass);
gadget_klass.declareAcquiredMethod("getConfigurationDict", "getConfigurationDict").declareMethod("render", function() {
......
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