restore ability to rename existing items (and change associated call number)
authorJason Etheridge <jason@esilibrary.com>
Fri, 11 Mar 2011 04:57:04 +0000 (23:57 -0500)
committerJason Etheridge <jason@esilibrary.com>
Fri, 11 Mar 2011 04:57:04 +0000 (23:57 -0500)
Open-ILS/xul/staff_client/server/cat/volume_copy_creator.js

index 593a467..cb3fa41 100644 (file)
@@ -86,9 +86,9 @@ function my_init() {
 
         /***********************************************************************************************************/
         /* If we're passed existing_copies, rig up a copy_shortcut object to leverage existing code for rendering the volume labels, etc.
-         * Also make a lookup object for existing copies keyed on org id and callnumber label, and another keyed on copy id. */
+         * Also make a lookup object for existing copies keyed on org id and callnumber composite key, and another keyed on copy id. */
 
-        // g.org_label_existing_copy_map = { ou_id : { callnumber_label : [ copy1, copy2, ... ] }, ... }
+        // g.org_label_existing_copy_map = { ou_id : { callnumber_composite_key : [ copy1, copy2, ... ] }, ... }
         g.org_label_existing_copy_map = {};
         // g.id_copy_map = { acp_id : acp, ... }
         g.id_copy_map = {};
@@ -103,11 +103,17 @@ function my_init() {
                 g.copy_shortcut[ call_number.owning_lib() ] = {};
                 g.org_label_existing_copy_map[ call_number.owning_lib() ] = {};
             }
-            g.copy_shortcut[ call_number.owning_lib() ][ call_number.label() ] = call_number.id();
-            if (! g.org_label_existing_copy_map[ call_number.owning_lib() ][ call_number.label() ]) {
-                g.org_label_existing_copy_map[ call_number.owning_lib() ][ call_number.label() ] = [];
+            var acnc_id = call_number.label_class() ?
+                ( typeof call_number.label_class() == 'object' ? call_number.label_class().id() : call_number.label_class() )
+                : g.label_class;
+            var acnp_id = typeof call_number.prefix() == 'object' ? call_number.prefix().id() : call_number.prefix();
+            var acns_id = typeof call_number.suffix() == 'object' ? call_number.suffix().id() : call_number.suffix();
+            var callnumber_composite_key = acnc_id + ':' + acnp_id + ':' + call_number.label() + ':' + acns_id;
+            g.copy_shortcut[ call_number.owning_lib() ][ callnumber_composite_key ] = call_number.id();
+            if (! g.org_label_existing_copy_map[ call_number.owning_lib() ][ callnumber_composite_key ]) {
+                g.org_label_existing_copy_map[ call_number.owning_lib() ][ callnumber_composite_key ] = [];
             }
-            g.org_label_existing_copy_map[ call_number.owning_lib() ][ call_number.label() ].push( copy );
+            g.org_label_existing_copy_map[ call_number.owning_lib() ][ callnumber_composite_key ].push( copy );
         }
 
         /***********************************************************************************************************/
@@ -450,20 +456,27 @@ g.render_callnumber_copy_count_entry = function(row,ou_id,count) {
                     try {
                         JSAN.use('util.functional');
                         if (g.copy_shortcut) {
-                            var label = util.functional.map_object_to_list(
+                            var callnumber_composite_key = util.functional.map_object_to_list(
                                 g.copy_shortcut[ou_id],
                                 function(o,i) {
                                     return i;
                                 }
                             )[idx];
                             if (g.org_label_existing_copy_map[ou_id]) {
-                                var num_of_copies = g.org_label_existing_copy_map[ou_id][label].length;
+                                var num_of_copies = g.org_label_existing_copy_map[ou_id][callnumber_composite_key].length;
                                 if (num_of_copies>0) {
                                     number_of_copies_column_textbox.value = num_of_copies;
                                     number_of_copies_column_textbox.disabled = true;
                                 }
                             }
-                            call_number_column_textbox.value = label;
+                            var acn_label = callnumber_composite_key.split(/:/).slice(2,-1).join(':');
+                            var acnc_id = callnumber_composite_key.split(/:/)[0];
+                            var acnp_id = callnumber_composite_key.split(/:/)[1];
+                            var acns_id = callnumber_composite_key.split(/:/).slice(-1)[0];
+                            call_number_column_textbox.value = acn_label;
+                            classification_column_menulist.value = acnc_id;
+                            prefix_column_menulist.value = acnp_id;
+                            suffix_column_menulist.value = acns_id;
                             handle_change_to_callnumber_data({'target':call_number_column_textbox});
                         } else {
 
@@ -599,8 +612,8 @@ g.render_barcode_entry = function(node,callnumber_composite_key,count,ou_id) {
             tb.setAttribute('rel_vert_pos',rel_vert_pos_barcode);
             part_menu.firstChild.setAttribute('rel_vert_pos',rel_vert_pos_part);
             if (!tb.value && g.org_label_existing_copy_map[ ou_id ]) {
-                tb.value = g.org_label_existing_copy_map[ ou_id ][ callnumber ][i].barcode();
-                tb.setAttribute('acp_id', g.org_label_existing_copy_map[ ou_id ][ callnumber ][i].id());
+                tb.value = g.org_label_existing_copy_map[ ou_id ][ callnumber_composite_key ][i].barcode();
+                tb.setAttribute('acp_id', g.org_label_existing_copy_map[ ou_id ][ callnumber_composite_key ][i].id());
                 tb.select();
                 if (! g.first_focus) { g.first_focus = tb; }
             }