Serial Control: Refresh node map on edit
authorDan Wells <dbw2@calvin.edu>
Mon, 26 Mar 2012 20:07:58 +0000 (16:07 -0400)
committerDan Wells <dbw2@calvin.edu>
Mon, 26 Mar 2012 21:10:22 +0000 (17:10 -0400)
While it would be nice to redraw any affected tree nodes when
editing, we should at least replace the map data in case it is
used in other functions.

Signed-off-by: Dan Wells <dbw2@calvin.edu>

Open-ILS/xul/staff_client/server/serial/manage_subs.js

index 74ca397..9b1a85b 100644 (file)
@@ -53,16 +53,40 @@ serial.manage_subs.prototype = {
 
             params.do_edit = true;
             params.handle_update = true;
+            params.trigger_refresh = true;
             if (mode == 'add') {
-                params.trigger_refresh = true;
                 params.refresh_command = function () {obj.refresh_list();};
+            } else {
+                params.refresh_command = function () {obj.remap_node(type, this);};
             }
+   
             obj[editor_type].init(params);
         } catch(E) {
             obj.error.standard_unexpected_error_alert('editor_init() error',E);
         }
     },
 
+    // while not a true tree node repace, this should at least prevent
+    // non-display side-effects.  True node replace is TODO
+    'remap_node' : function(type, editor_obj) {
+        var obj = this;
+        try {
+            for (i = 0; i < editor_obj[editor_obj.fm_type_plural].length; i++) {
+                var new_obj = editor_obj[editor_obj.fm_type_plural][i];
+                var old_obj = obj['map_' + type][type + '_' + new_obj.id()];
+                if (type == 'ssub') { // add children back on
+                    new_obj.distributions(old_obj.distributions());
+                    new_obj.issuances(old_obj.issuances());
+                    new_obj.scaps(old_obj.scaps());
+                }
+                obj['map_' + type][type + '_' + new_obj.id()] = new_obj;
+            }
+            editor_obj.render();
+        } catch(E) {
+            obj.error.standard_unexpected_error_alert('remap_node() error',E);
+        }
+    },
+
     'do_delete' : function(type, method, overridable_events) {
         var obj = this;
         try {