Commit 7d22f9be authored by Jérome Perrin's avatar Jérome Perrin

Reimplement automatic saving in a more renderjs friendly way

Graph editor gadget calls an acquired method "notifyDataChanged" on its
parent gadget.
parent 7f1e82b8
...@@ -6,8 +6,6 @@ ...@@ -6,8 +6,6 @@
<title>Edit table</title> <title>Edit table</title>
<script src="../<%= copy.rsvp.relative_dest %>" type="text/javascript"></script> <script src="../<%= copy.rsvp.relative_dest %>" type="text/javascript"></script>
<script src="../<%= copy.renderjs.relative_dest %>" type="text/javascript"></script> <script src="../<%= copy.renderjs.relative_dest %>" type="text/javascript"></script>
<script src="../lib/pubsub.js" type="text/javascript"></script>
<script src="mixin_promise.js" type="text/javascript"></script> <script src="mixin_promise.js" type="text/javascript"></script>
<script src="Input_viewProductionLine.js" type="text/javascript"></script> <script src="Input_viewProductionLine.js" type="text/javascript"></script>
......
...@@ -72,6 +72,19 @@ ...@@ -72,6 +72,19 @@
.declareAcquiredMethod("aq_getAttachment", "jio_getAttachment") .declareAcquiredMethod("aq_getAttachment", "jio_getAttachment")
.declareAcquiredMethod("aq_putAttachment", "jio_putAttachment") .declareAcquiredMethod("aq_putAttachment", "jio_putAttachment")
.allowPublicAcquisition("notifyDataChanged", function () {
// We are notified by an included gadget that the data has changed.
// Here we save automatically. We could mark a dirty flag to warn the
// user if she leaves the page without saving.
// Since we are notified quite often and saving is resource expensive, we
// use this trick to prevent saving too many times
if (this.timeout) {
window.clearTimeout(this.timeout);
}
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;
gadget.props.jio_key = jio_key; gadget.props.jio_key = jio_key;
...@@ -98,13 +111,6 @@ ...@@ -98,13 +111,6 @@
.declareMethod("startService", function () { .declareMethod("startService", function () {
var g = this, var g = this,
graph; graph;
// save automatically
window.$.subscribe("Dream.Gui.onDataChange", function () {
if (g.timeout) {
window.clearTimeout(g.timeout);
}
g.timeout = window.setTimeout(saveGraph.bind(g), 100);
});
return g.getDeclaredGadget("productionline_graph") return g.getDeclaredGadget("productionline_graph")
.push(function (graph_gadget) { .push(function (graph_gadget) {
graph = graph_gadget; graph = graph_gadget;
......
...@@ -11,7 +11,6 @@ ...@@ -11,7 +11,6 @@
<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 src="../<%= copy.handlebars.relative_dest %>"></script>
<script src="../lib/pubsub.js" type="text/javascript"></script>
<script id="node-template" type="text/x-handlebars-template"> <script id="node-template" type="text/x-handlebars-template">
<div class="window {{class}}" <div class="window {{class}}"
......
...@@ -110,12 +110,6 @@ ...@@ -110,12 +110,6 @@
return 'DreamNode_' + n; return 'DreamNode_' + n;
} }
function onDataChange(g) {
g.getData().then(function (data) {
$.publish("Dream.Gui.onDataChange", data);
});
}
function updateConnectionData(gadget, connection, remove, edge_data) { function updateConnectionData(gadget, connection, remove, edge_data) {
if (remove) { if (remove) {
delete gadget.props.edge_container[connection.id]; delete gadget.props.edge_container[connection.id];
...@@ -126,7 +120,7 @@ ...@@ -126,7 +120,7 @@
edge_data || {} edge_data || {}
]; ];
} }
onDataChange(gadget); gadget.notifyDataChanged();
} }
// bind to connection/connectionDetached events, // bind to connection/connectionDetached events,
...@@ -202,7 +196,7 @@ ...@@ -202,7 +196,7 @@
} }
coordinates[node_id] = coordinate; coordinates[node_id] = coordinate;
gadget.props.preference_container.coordinates = coordinates; gadget.props.preference_container.coordinates = coordinates;
onDataChange(gadget); gadget.notifyDataChanged();
return coordinate; return coordinate;
} }
...@@ -283,7 +277,7 @@ ...@@ -283,7 +277,7 @@
// }); // });
// split in 2 methods ? one for events one for manip // split in 2 methods ? one for events one for manip
onDataChange(gadget); gadget.notifyDataChanged();
draggable(gadget); draggable(gadget);
} }
...@@ -372,7 +366,7 @@ ...@@ -372,7 +366,7 @@
// 1.1111; // 1.1111;
// setZoom(gadget, zoom_level); // setZoom(gadget, zoom_level);
// gadget.props.preference_container.zoom_level = zoom_level; // gadget.props.preference_container.zoom_level = zoom_level;
// onDataChange(); // gadget.notifyDataChanged();
// redraw(gadget); // redraw(gadget);
// } // }
...@@ -381,7 +375,7 @@ ...@@ -381,7 +375,7 @@
// 0.9; // 0.9;
// setZoom(gadget, zoom_level); // setZoom(gadget, zoom_level);
// gadget.props.preference_container.zoom_level = zoom_level; // gadget.props.preference_container.zoom_level = zoom_level;
// onDataChange(); // gadget.notifyDataChanged();
// redraw(gadget); // redraw(gadget);
// } // }
...@@ -399,7 +393,7 @@ ...@@ -399,7 +393,7 @@
delete gadget.props.edge_container[k]; delete gadget.props.edge_container[k];
} }
}); });
onDataChange(gadget); gadget.notifyDataChanged();
} }
function updateElementData(gadget, node_id, data) { function updateElementData(gadget, node_id, data) {
...@@ -429,7 +423,7 @@ ...@@ -429,7 +423,7 @@
= gadget.props.preference_container.coordinates[node_id]; = gadget.props.preference_container.coordinates[node_id];
delete gadget.props.preference_container.coordinates[node_id]; delete gadget.props.preference_container.coordinates[node_id];
} }
onDataChange(gadget); gadget.notifyDataChanged();
} }
// function clearAll(gadget) { // function clearAll(gadget) {
...@@ -475,16 +469,6 @@ ...@@ -475,16 +469,6 @@
// setZoom(gadget, zoom_level); // setZoom(gadget, zoom_level);
// } // }
// function setGeneralProperties(gadget, properties) {
// gadget.props.general_container = properties;
// onDataChange();
// }
// function updateGeneralProperties(gadget, properties) {
// $.extend(gadget.props.general_container, properties);
// onDataChange();
// }
function openNodeDialog(gadget, element, config_dict) { function openNodeDialog(gadget, element, config_dict) {
var node_id = getNodeId(gadget.props.node_container, element.id), var node_id = getNodeId(gadget.props.node_container, element.id),
node_data = gadget.props.node_container[node_id], node_data = gadget.props.node_container[node_id],
...@@ -642,7 +626,7 @@ ...@@ -642,7 +626,7 @@
box.css("left", absolute_position[0]); box.css("left", absolute_position[0]);
updateNodeStyle(gadget, element.element_id); updateNodeStyle(gadget, element.element_id);
draggable(gadget); draggable(gadget);
onDataChange(gadget); gadget.notifyDataChanged();
} }
function waitForDragover(gadget) { function waitForDragover(gadget) {
...@@ -705,6 +689,7 @@ ...@@ -705,6 +689,7 @@
gadget_klass gadget_klass
.declareAcquiredMethod('getConfigurationDict', 'getConfigurationDict') .declareAcquiredMethod('getConfigurationDict', 'getConfigurationDict')
.declareAcquiredMethod('notifyDataChanged', 'notifyDataChanged')
.ready(function (g) { .ready(function (g) {
g.props.edge_container = {}; g.props.edge_container = {};
...@@ -737,6 +722,7 @@ ...@@ -737,6 +722,7 @@
g.props.data.preference : {}, g.props.data.preference : {},
coordinates = preference.coordinates, coordinates = preference.coordinates,
config; config;
g.notifyDataChanged();
return g.getConfigurationDict() return g.getConfigurationDict()
.push(function (config_dict) { .push(function (config_dict) {
config = config_dict; config = config_dict;
......
/*global jQuery */
/* jQuery Tiny Pub/Sub - v0.7 - 10/27/2011
* http://benalman.com/
* Copyright (c) 2011 "Cowboy" Ben Alman; Licensed MIT, GPL */
(function ($) {
"use strict";
var o = $({});
$.subscribe = function () {
o.on.apply(o, arguments);
};
$.unsubscribe = function () {
o.off.apply(o, arguments);
};
$.publish = function () {
o.trigger.apply(o, arguments);
};
}(jQuery));
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