diff options
| author | Alon Levy <alon@pobox.com> | 2014-12-23 14:39:25 +0200 |
|---|---|---|
| committer | Alon Levy <alon@pobox.com> | 2014-12-23 14:40:26 +0200 |
| commit | 7f309f2207ce03a3079700176ebcd30161fe10ac (patch) | |
| tree | 6a6e3b0174eab57857845804176228850299485c /src/client/model/graph.js | |
| parent | 1312392667fd700fb423cd1c42238a2eccaa3d0a (diff) | |
client: removal of links through server; Fixes #228
Code is ugly on too many counts, but mainly:
1. repeats local change twice, once for temp and once for non-temp that
goes through server.
2. handles topo_diff reply expecting a single id instead of having a
general topo_diff reply handler that will take care of it, possibly
hanging a callback on it for graph update.
Diffstat (limited to 'src/client/model/graph.js')
| -rw-r--r-- | src/client/model/graph.js | 36 |
1 files changed, 34 insertions, 2 deletions
diff --git a/src/client/model/graph.js b/src/client/model/graph.js index 063bc3c5..b671671e 100644 --- a/src/client/model/graph.js +++ b/src/client/model/graph.js @@ -542,13 +542,45 @@ function Graph() { } } - this.removeLink = function(link) { + var linkGetIndexFromId = function(link_id) { + for (var i = 0 ; i < links.length ; ++i) { + if (links[i].id == link_id) { + return i; + } + } + } + + this.removeLink = function(link, on_success, on_error) { var i; + if (link.id === undefined) { + console.log('bug: link without an id'); + } + + function graph_on_success(ret) { + var link_id = ret[0][0]; + links.splice(linkGetIndexFromId(link_id), 1); + if (on_success) { + on_success(); + } + } + for (i = 0 ; i < links.length; ++i) { if (link.id !== undefined) { if (link.id === links[i].id) { - links.splice(i, 1); + if (link.state == 'temp') { + links.splice(i, 1); + if (on_success) { + on_success(); + } + } else { + if (rz_config.backend_enabled) { + var topo_diff = model_diff.new_topo_diff({ + link_set_rm: [link.id] + }); + rz_api_backend.commit_diff__topo(topo_diff, graph_on_success, on_error); + } + } return; } } else { |
