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

graph_editor: support re-rendering graph

This is required with ERP5JS, where every save call render with new data.
parent 907a6138
......@@ -225,8 +225,8 @@
function updateConnectionData(gadget, connection, remove) {
if (connection.ignoreEvent) {
// this hack is for edge edition. Maybe there I missed one thing and
// there is a better way.
// this hack is for edge edition and when the graph is re-rendered.
// Maybe there I missed one thing and there is a better way.
return;
}
if (remove) {
......@@ -815,6 +815,20 @@
}
});
*/
// reset previous graph, if any.
if ($(".window", this.props.element).length) {
$.each(
// disable the "delete" event, otherwise after render load the
// graph, loopJsplumbBind events will process the connection deleted
// events
this.props.jsplumb_instance.getAllConnections(),
function (i, connection) {
connection.ignoreEvent = true;
});
this.props.jsplumb_instance.reset();
$(".window", this.props.element).remove();
}
if (data) {
this.props.data = JSON.parse(data);
......
......@@ -591,5 +591,24 @@
});
}).fail(error_handler).always(start);
});
test("Gadget can be rendered multiple times", function () {
var jsplumb_gadget;
stop();
g.declareGadget("./index.html", {
element: document.querySelector("#test-element")
}).then(function (new_gadget) {
jsplumb_gadget = new_gadget;
return jsplumb_gadget.render(sample_data_graph);
}).then(function () {
return jsplumb_gadget.getContent();
}).then(function () {
return jsplumb_gadget.render(sample_data_graph);
}).then(function () {
return jsplumb_gadget.getContent();
}).then(function (content) {
equal(sample_data_graph, content);
equal($(".window", document.querySelector("#test-element")).length, 2, "Graph is rendered only once");
}).fail(error_handler).always(start);
});
});
}(rJS, JSON, QUnit, RSVP, jQuery));
\ 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