summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlon Levy <alon@pobox.com>2014-12-22 20:23:32 +0200
committerAlon Levy <alon@pobox.com>2014-12-22 20:24:15 +0200
commit3dbebde0ad179390bd17b902c618f2d6a12cdf46 (patch)
tree291bf1edbf9b93b07705a178c526906002fbdcf2 /src
parent89be53c7ebc6d05b3c7bd0ad2ef435b0630a5ca4 (diff)
client: handle link changes via attribute diffs (adds graph.update_link copied from update_node)
Adds a copied TODO for handling id changes (i.e. same problem on nodes) plus a new TODO for a fake API (relevant to both nodes and links)
Diffstat (limited to 'src')
-rw-r--r--src/client/model/graph.js48
-rw-r--r--src/client/rz_core.js4
2 files changed, 51 insertions, 1 deletions
diff --git a/src/client/model/graph.js b/src/client/model/graph.js
index a85b6b7e..063bc3c5 100644
--- a/src/client/model/graph.js
+++ b/src/client/model/graph.js
@@ -381,6 +381,54 @@ function Graph() {
rz_bus.names.push([newname]);
}
+ this.update_link = function(link, new_link_spec, on_success, on_error) {
+ util.assert(link instanceof model_core.Link);
+
+ // TODO - fake api for client only (debug, demo, ui work)
+ if (!rz_config.backend_enabled) return;
+
+ var attr_diff = model_diff.new_attr_diff();
+ for (var key in new_link_spec){
+ attr_diff.add_link_attr_write(link.id, key, new_link_spec[key]);
+ }
+
+ var on_ajax_success = function(id_to_link_map){
+ var link_id = link.id; // original link id
+ if (id_to_link_map[link_id].id != link_id){
+ // TODO: handle incoming ID update
+ util.assert(false, 'update_link: id attr change');
+ }
+
+ var ret_link = id_to_link_map[link_id];
+ for (var key in ret_link){
+ if ('id' == key){
+ continue;
+ }
+ var matching = null;
+ link[key] = ret_link[key];
+ // this part is fucked up right now
+ if (key == '__type') {
+ matching = 'name';
+ }
+ if (key == 'name') {
+ matching = '__type';
+ }
+ if (matching) {
+ link[matching] = link[key];
+ }
+ }
+
+ // TODO: handle NAK: add problem emblem to link
+ on_success();
+ };
+
+ var on_ajax_error = function(){
+ console.log('error with commit to server: danger robinson!');
+ };
+
+ rz_api_backend.commit_diff__attr(attr_diff, on_ajax_success, on_ajax_error);
+ }
+
this.update_node = function(node, new_node_spec, on_success, on_error) {
util.assert(node instanceof model_core.Node);
diff --git a/src/client/rz_core.js b/src/client/rz_core.js
index 2361b45f..7006af36 100644
--- a/src/client/rz_core.js
+++ b/src/client/rz_core.js
@@ -76,7 +76,9 @@ var svgInput = (function() {
d = jelement.data().d;
if (e.which == 13 && newname != d.name) {
if (d.hasOwnProperty('__src')) {
- graph.editLink(d.__src.id, d.__dst.id, newname);
+ graph.update_link(d, {name: newname}, function() {
+ update_view__graph(true);
+ });
} else {
graph.update_node(d, {name: newname}, function() {
rz_bus.names.push([newname]);