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

Removed spreadsheet related datas on jsplumb gadget

Removed event callbacks non related to jsplumb rendering
Templatized creation of new nodes with Handlebars
parent 91144cc7
...@@ -10,7 +10,17 @@ ...@@ -10,7 +10,17 @@
<script src="../<%= copy.rsvp.relative_dest %>"></script> <script src="../<%= copy.rsvp.relative_dest %>"></script>
<script src="../<%= copy.renderjs.relative_dest %>"></script> <script src="../<%= copy.renderjs.relative_dest %>"></script>
<script src="../<%= curl.jsplumbjs.relative_dest %>"></script> <script src="../<%= curl.jsplumbjs.relative_dest %>"></script>
<script src="../<%= copy.handlebars.relative_dest %>"></script>
<script id="node-template" type="text/x-handlebars-template">
<div class="window {{class}}"
id="{{element_id}}"
title="{{title}}">
{{id}}
<div class="ep"></div>
</div>
</script>
<script src="jsplumb.js"></script> <script src="jsplumb.js"></script>
</head> </head>
<body> <body>
......
...@@ -17,10 +17,16 @@ ...@@ -17,10 +17,16 @@
* along with DREAM. If not, see <http://www.gnu.org/licenses/>. * along with DREAM. If not, see <http://www.gnu.org/licenses/>.
* ==========================================================================*/ * ==========================================================================*/
/*global RSVP, rJS, $, jsPlumb, confirm*/ /*global RSVP, rJS, $, jsPlumb, Handlebars*/
(function (RSVP, rJS, $, jsPlumb, confirm) { (function (RSVP, rJS, $, jsPlumb, Handlebars) {
"use strict"; "use strict";
/*jslint nomen: true*/
var gadget_klass = rJS(window),
node_template_source = gadget_klass.__template_element
.getElementById('node-template').innerHTML,
node_template = Handlebars.compile(node_template_source);
function getNodeId(node_container, element_id) { function getNodeId(node_container, element_id) {
var node_id; var node_id;
$.each(node_container, function (k, v) { $.each(node_container, function (k, v) {
...@@ -176,23 +182,23 @@ ...@@ -176,23 +182,23 @@
// listen for clicks on connections, // listen for clicks on connections,
// and offer to change values on click. // and offer to change values on click.
jsplumb_instance.bind("click", function (conn) { // jsplumb_instance.bind("click", function (conn) {
jsplumb_instance.detach(conn); // jsplumb_instance.detach(conn);
}); // });
jsplumb_instance.bind("beforeDetach", function (conn) { // jsplumb_instance.bind("beforeDetach", function (conn) {
return confirm("Delete connection?"); // return confirm("Delete connection?");
}); // });
jsplumb_instance // jsplumb_instance
.bind("connectionDrag", function (connection) { // .bind("connectionDrag", function (connection) {
return undefined; // return undefined;
}); // });
jsplumb_instance // jsplumb_instance
.bind("connectionDragStop", function (connection) { // .bind("connectionDragStop", function (connection) {
return undefined; // return undefined;
}); // });
// split in 2 methods ? one for events one for manip // split in 2 methods ? one for events one for manip
gadget.private.updateConnectionData gadget.private.updateConnectionData
= function (connection, remove, edge_data) { = function (connection, remove, edge_data) {
...@@ -210,14 +216,14 @@ ...@@ -210,14 +216,14 @@
// bind to connection/connectionDetached events, // bind to connection/connectionDetached events,
// and update the list of connections on screen. // and update the list of connections on screen.
jsplumb_instance // jsplumb_instance
.bind("connection", function (info, originalEvent) { // .bind("connection", function (info, originalEvent) {
gadget.private.updateConnectionData(info.connection); // gadget.private.updateConnectionData(info.connection);
}); // });
jsplumb_instance // jsplumb_instance
.bind("connectionDetached", function (info, originalEvent) { // .bind("connectionDetached", function (info, originalEvent) {
gadget.private.updateConnectionData(info.connection, true); // gadget.private.updateConnectionData(info.connection, true);
}); // });
onDataChange(); onDataChange();
draggable(gadget); draggable(gadget);
} }
...@@ -428,12 +434,12 @@ ...@@ -428,12 +434,12 @@
); );
} }
/*jslint nomen: true*/ /*jslint nomen: true*/
render_element.append('<div class="window ' + element._class render_element.append(node_template({
.replace('.', '-') + '" id="' + "class": element._class.replace('.', '-'),
element.element_id + '" title="' + "element_id": element.element_id,
(element.name || element.id) + '">' + "title": element.name || element.id,
element.id + "id": element.id
'<div class="ep"></div></div>'); }));
box = $(gadget.private.element).find("#" + element.element_id); box = $(gadget.private.element).find("#" + element.element_id);
absolute_position = convertToAbsolutePosition( absolute_position = convertToAbsolutePosition(
gadget, gadget,
...@@ -447,13 +453,12 @@ ...@@ -447,13 +453,12 @@
onDataChange(); onDataChange();
} }
rJS(window) gadget_klass
.ready(function (g) { .ready(function (g) {
g.private = { g.private = {
node_container: {}, node_container: {},
edge_container: {}, edge_container: {},
preference_container: {}, preference_container: {},
general_container: {},
style_attr_list: ['width', 'height', 'padding-top', 'line-height'] style_attr_list: ['width', 'height', 'padding-top', 'line-height']
}; };
}) })
...@@ -464,28 +469,11 @@ ...@@ -464,28 +469,11 @@
}) })
.declareMethod('getData', function () { .declareMethod('getData', function () {
var data = { return JSON.stringify({
"nodes": this.private.node_container, "nodes": this.private.node_container,
"edges": this.private.edge_container, "edges": this.private.edge_container,
"preference": this.private.preference_container, "preference": this.private.preference_container
"general": this.private.general_container });
},
wip_spreadsheet = $(this.private.element).find('#wip_spreadsheet'),
wip_part_spreadsheet = $(this.private.element)
.find('#wip_part_spreadsheet'),
shift_spreadsheet = $(this.private.element)
.find('#shift_spreadsheet');
if (wip_spreadsheet.length > 0) {
data.wip_spreadsheet = wip_spreadsheet.handsontable('getData');
}
if (wip_part_spreadsheet.length > 0) {
data.wip_part_spreadsheet = wip_part_spreadsheet
.handsontable('getData');
}
if (shift_spreadsheet.length > 0) {
data.shift_spreadsheet = shift_spreadsheet.handsontable('getData');
}
return JSON.stringify(data);
}) })
.declareMethod('startService', function () { .declareMethod('startService', function () {
...@@ -494,7 +482,7 @@ ...@@ -494,7 +482,7 @@
gadget.private.data.preference : {}, gadget.private.data.preference : {},
coordinates = preference.coordinates; coordinates = preference.coordinates;
return gadget.getElement() return gadget.getElement()
.push(function (el) { .then(function (el) {
gadget.private.element = el; gadget.private.element = el;
initJsPlumb(gadget); initJsPlumb(gadget);
$.each(gadget.private.data.nodes, function (key, value) { $.each(gadget.private.data.nodes, function (key, value) {
...@@ -518,15 +506,6 @@ ...@@ -518,15 +506,6 @@
addEdge(gadget, key, value); addEdge(gadget, key, value);
}); });
redraw(gadget); redraw(gadget);
})
.push(function () {
// Infinite wait, until cancelled
return new RSVP.defer().promise;
})
.push(undefined, function (error) {
$(gadget.private.element).find("#main").html("");
throw error;
}); });
}); });
}(RSVP, rJS, $, jsPlumb, confirm)); }(RSVP, rJS, $, jsPlumb, Handlebars));
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