Better coordination of MFHD/SRE adding/deleting
authorDan Wells <dbw2@calvin.edu>
Fri, 17 Jun 2011 19:26:39 +0000 (15:26 -0400)
committerJason Etheridge <jason@esilibrary.com>
Wed, 22 Jun 2011 13:47:20 +0000 (09:47 -0400)
Adding or deleting MFHD records from the XUL menus requires
coordinating the OPAC display, the XUL menus, and the Serial
Control distribution editors.  The previous code frequently
required some non-obvious manual refreshing to make it work.

This commit keeps them in sync using custom events instead.

Signed-off-by: Dan Wells <dbw2@calvin.edu>
Signed-off-by: Jason Etheridge <jason@esilibrary.com>

Open-ILS/xul/staff_client/chrome/content/cat/opac.js
Open-ILS/xul/staff_client/server/serial/sdist_editor.js

index 9d54056..ceef976 100644 (file)
@@ -490,6 +490,9 @@ function set_opac() {
                                 item = mfhd_delete_menu.appendItem(label);
                                 item.setAttribute('oncommand','delete_mfhd('+mfhd_details.id+')');
                             }
+                            var change_event = document.createEvent("Event");
+                            change_event.initEvent("MFHDChange",false,false);
+                            window.dispatchEvent(change_event);
                         }
                     }
                 );
@@ -558,7 +561,7 @@ function create_mfhd() {
             throw(r);
         }
         alert("MFHD record created."); //TODO: better success message
-        //TODO: refresh opac display
+        browser_frame.contentWindow.g.browser.controller.view.cmd_reload.doCommand();
     } catch(E) {
         g.error.standard_unexpected_error_alert("Create MFHD failed", E); //TODO: better error handling
     }
@@ -580,7 +583,7 @@ function delete_mfhd(sre_id) {
             alert(document.getElementById('offlineStrings').getFormattedString('cat.opac.record_deleted.error',  [docid, robj.textcode, robj.desc]) + '\n');
         } else {
             alert(document.getElementById('offlineStrings').getString('cat.opac.record_deleted'));
-            //TODO: refresh opac display
+            browser_frame.contentWindow.g.browser.controller.view.cmd_reload.doCommand();
         }
     }
 }
index 908a90e..74665d8 100644 (file)
@@ -23,24 +23,11 @@ serial.sdist_editor = function (params) {
     // setup sre arrays
     this.sre_id_map = {};
     this.sres_ou_map = {};
-    var parent_g = window.parent.g;
-    if (parent_g.mfhd) {
-        var mfhd_details = parent_g.mfhd.details;
-        for (var i = 0; i < mfhd_details.length; i++) {
-            var mfhd_detail = {};
-            for (j in mfhd_details[i]) {
-                mfhd_detail[j] = mfhd_details[i][j];
-            }
-            mfhd_detail.label = mfhd_detail.label + ' (' + (mfhd_detail.entryNum + 1) + ')';
-            var sre_id = mfhd_detail.id;
-            var org_unit_id = mfhd_detail.owning_lib;
-            this.sre_id_map[sre_id] = mfhd_detail;
-            if (!this.sres_ou_map[org_unit_id]) {
-                this.sres_ou_map[org_unit_id] = [];
-            }
-            this.sres_ou_map[org_unit_id].push(mfhd_detail);
-        }
-    }
+    this.build_sre_maps();
+
+    // update sre maps on demand
+    var obj = this;
+    window.parent.addEventListener("MFHDChange", function() {obj.build_sre_maps()}, false);
 };
 
 serial.sdist_editor.prototype = {
@@ -293,6 +280,37 @@ serial.sdist_editor.prototype = {
     'save_attributes' : serial.editor_base.editor_base_save_attributes,
 
     /******************************************************************************************************/
+    /* Build maps of sre details for both display and selection purposes */
+
+    'build_sre_maps' : function() {
+        var obj = this;
+        try {
+            obj.sre_id_map = {};
+            obj.sres_ou_map = {};
+            var parent_g = window.parent.g;
+            if (parent_g.mfhd) {
+                var mfhd_details = parent_g.mfhd.details;
+                for (var i = 0; i < mfhd_details.length; i++) {
+                    var mfhd_detail = {};
+                    for (j in mfhd_details[i]) {
+                        mfhd_detail[j] = mfhd_details[i][j];
+                    }
+                    mfhd_detail.label = mfhd_detail.label + ' (' + (mfhd_detail.entryNum + 1) + ')';
+                    var sre_id = mfhd_detail.id;
+                    var org_unit_id = mfhd_detail.owning_lib;
+                    obj.sre_id_map[sre_id] = mfhd_detail;
+                    if (!obj.sres_ou_map[org_unit_id]) {
+                        obj.sres_ou_map[org_unit_id] = [];
+                    }
+                    obj.sres_ou_map[org_unit_id].push(mfhd_detail);
+                }
+            }
+        } catch(E) {
+            obj.error.standard_unexpected_error_alert('build_sre_maps',E);
+        }
+    },
+
+    /******************************************************************************************************/
     /* This returns a list of sre details appropriate for the distributions being edited */
 
     'get_sre_details_list' : function() {