diff options
| author | Alon Levy <alon@pobox.com> | 2015-02-15 20:05:51 +0200 |
|---|---|---|
| committer | Alon Levy <alon@pobox.com> | 2015-02-15 20:05:51 +0200 |
| commit | 849199bc42cab50972fd489b5f2446159fe1e3c0 (patch) | |
| tree | f5d8d1ae04a5634ecb87de126b337c9a045605cd | |
| parent | 30707a57ab89c8575bec985c8400ff0f990bce92 (diff) | |
client/node_info: track changes and commit on any field change. partially Fixes #43
| -rw-r--r-- | src/client/view/node_info.js | 30 |
1 files changed, 24 insertions, 6 deletions
diff --git a/src/client/view/node_info.js b/src/client/view/node_info.js index e98a3395..45015a90 100644 --- a/src/client/view/node_info.js +++ b/src/client/view/node_info.js @@ -15,7 +15,8 @@ var d = null, startdate: info.find("#editstartdate"), enddate: info.find("#editenddate"), description: info.find("#editdescription"), - }; + }, + change_handlers = []; function clean_url(candidate_url) @@ -52,8 +53,28 @@ function textarea_resize(text, max) text.style.height = height + 'px'; } -function setup_click_handlers(graph) +function setup_change_handlers() { + disable_change_handlers(); + // auto save style handlers + var streams = _.map(_.values(form), function (field) { + return field.asEventStream('change'); + }); + var single = _.reduce(streams, function (stream_a, stream_b) { return stream_a.merge(stream_b); }); + change_handlers = [single.debounce(100).onValue(function () { + commit(); + })]; +} + +function disable_change_handlers() +{ + _.each(change_handlers, function (unsub) { unsub(); }); + change_handlers = []; +} + +function setup_click_handlers() +{ + setup_change_handlers(); if (setup_done) { return; } @@ -83,9 +104,6 @@ function setup_click_handlers(graph) } show(graph, node); }); - - // auto save style handlers - //info. } function warning(string) @@ -111,7 +129,7 @@ function show(_graph, d) { node = d; util.assert(graph.find_node__by_id(d.id) != null); - setup_click_handlers(graph); + setup_click_handlers(); internal.edit_tab.show('node'); |
