From 7a4c9360fb48e3b17d503f59692aef7d509e7590 Mon Sep 17 00:00:00 2001
From: Jason Etheridge <jason@esilibrary.com>
Date: Fri, 27 May 2011 11:41:55 -0400
Subject: [PATCH] Integration of unified vol/copy editor and fast  add

* Wire up unified vol/copy editor for marc editor fast item add function
* Robustify callnumber vivication for unified vol/copy editor from marc editor
* Load opac after unified vol/copy with marc editor fast add.
* Various bug fixes

Signed-off-by: Jason Etheridge <jason@esilibrary.com>
Signed-off-by: Bill Erickson <berick@esilibrary.com>
---
 .../xul/staff_client/chrome/content/cat/opac.js    | 25 +++++-
 .../xul/staff_client/chrome/content/main/menu.js   |  7 ++
 Open-ILS/xul/staff_client/server/cat/util.js       | 25 +++++-
 .../staff_client/server/cat/volume_copy_creator.js | 91 +++++++++++++---------
 4 files changed, 110 insertions(+), 38 deletions(-)

diff --git a/Open-ILS/xul/staff_client/chrome/content/cat/opac.js b/Open-ILS/xul/staff_client/chrome/content/cat/opac.js
index 96847401ac..9d54056733 100644
--- a/Open-ILS/xul/staff_client/chrome/content/cat/opac.js
+++ b/Open-ILS/xul/staff_client/chrome/content/cat/opac.js
@@ -217,7 +217,30 @@ function set_marc_edit() {
                             copy_obj.ref(get_db_false());
 
                             JSAN.use('util.window'); var win = new util.window();
-                            return cat.util.spawn_copy_editor( { 'handle_update' : 1, 'edit' : 1, 'docid' : doc_id, 'copies' : [ copy_obj ] });
+
+                            var unified_interface = String( data.hash.aous['ui.unified_volume_copy_editor'] ) == 'true';
+                            if (unified_interface) {
+                                var horizontal_interface = String( data.hash.aous['ui.cat.volume_copy_editor.horizontal'] ) == 'true';
+                                var url = window.xulG.url_prefix( horizontal_interface ? urls.XUL_VOLUME_COPY_CREATOR_HORIZONTAL : urls.XUL_VOLUME_COPY_CREATOR );
+                                var w = xulG.set_tab(
+                                    url,
+                                    {
+                                        'tab_name' : document.getElementById('offlineStrings').getFormattedString(
+                                            'cat.bib_record',
+                                            [ doc_id ]
+                                        )
+                                    },
+                                    {
+                                        'doc_id' : doc_id, 
+                                        'existing_copies' : [ copy_obj ],
+                                        'load_opac_when_done' : true,
+                                        'labels_in_new_tab' : true
+                                    }
+                                );
+
+                            } else {
+                                return cat.util.spawn_copy_editor( { 'handle_update' : 1, 'edit' : 1, 'docid' : doc_id, 'copies' : [ copy_obj ] });
+                            }
 
                         } catch(E) {
                             if (error) error.standard_unexpected_error_alert('Error in chrome/content/cat/opac.js, cat.util.fast_item_add #2',E); else alert('FIXME: ' + E);
diff --git a/Open-ILS/xul/staff_client/chrome/content/main/menu.js b/Open-ILS/xul/staff_client/chrome/content/main/menu.js
index 3c3818af4e..7b3f53c022 100644
--- a/Open-ILS/xul/staff_client/chrome/content/main/menu.js
+++ b/Open-ILS/xul/staff_client/chrome/content/main/menu.js
@@ -2145,6 +2145,13 @@ commands:
                             } catch(E) {
                                 obj.error.sdump('D_ERROR', 'main.menu, set_tab, onload: ' + E);
                             }
+                            try {
+                                if (typeof params.on_tab_load == 'function') {
+                                    params.on_tab_load(cw);
+                                }
+                            } catch(E) {
+                                obj.error.sdump('D_ERROR', 'main.menu, set_tab, onload #2: ' + E);
+                            }
                         },
                         false
                     );
diff --git a/Open-ILS/xul/staff_client/server/cat/util.js b/Open-ILS/xul/staff_client/server/cat/util.js
index 750de178cd..ce9d492f85 100644
--- a/Open-ILS/xul/staff_client/server/cat/util.js
+++ b/Open-ILS/xul/staff_client/server/cat/util.js
@@ -557,7 +557,30 @@ cat.util.fast_item_add = function(doc_id,cn_label,cp_barcode) {
 
         JSAN.use('util.window'); var win = new util.window();
         JSAN.use('cat.util');
-        return cat.util.spawn_copy_editor( { 'handle_update' : 1, 'edit' : 1, 'docid' : doc_id, 'copies' : [ copy_obj ] });
+
+        var unified_interface = String( data.hash.aous['ui.unified_volume_copy_editor'] ) == 'true';
+        if (unified_interface) {
+            var horizontal_interface = String( data.hash.aous['ui.cat.volume_copy_editor.horizontal'] ) == 'true';
+            var url = window.xulG.url_prefix( horizontal_interface ? urls.XUL_VOLUME_COPY_CREATOR_HORIZONTAL : urls.XUL_VOLUME_COPY_CREATOR );
+            var w = xulG.set_tab(
+                url,
+                {
+                    'tab_name' : document.getElementById('offlineStrings').getFormattedString(
+                        'cat.bib_record',
+                        [ doc_id ]
+                    )
+                },
+                {
+                    'doc_id' : doc_id, 
+                    'existing_copies' : [ copy_obj ],
+                    'load_opac_when_done' : true,
+                    'labels_in_new_tab' : true
+                }
+            );
+
+        } else {
+            return cat.util.spawn_copy_editor( { 'handle_update' : 1, 'edit' : 1, 'docid' : doc_id, 'copies' : [ copy_obj ] });
+        }
 
     } catch(E) {
         if (error) error.standard_unexpected_error_alert('cat.util.fast_item_add',E); else alert('FIXME: ' + E);
diff --git a/Open-ILS/xul/staff_client/server/cat/volume_copy_creator.js b/Open-ILS/xul/staff_client/server/cat/volume_copy_creator.js
index d9c2b2ce7a..511256913a 100644
--- a/Open-ILS/xul/staff_client/server/cat/volume_copy_creator.js
+++ b/Open-ILS/xul/staff_client/server/cat/volume_copy_creator.js
@@ -118,6 +118,20 @@ function my_init() {
             var copy = g.existing_copies[i];
             g.id_copy_map[ copy.id() ] = copy;
             var call_number = copy.call_number();
+            if (typeof call_number != 'object') {
+                if (typeof g.acn_map[call_number] == 'undefined') {
+                    var temp_acn = g.network.simple_request(
+                        'FM_ACN_RETRIEVE.authoritative',
+                        [ call_number ]
+                    );
+                    if (typeof temp_acn.ilsevent != 'undefined') {
+                        alert('Error in my_init(), acn_id = ' + call_number + ' temp_acn = ' + js2JSON(temp_acn));
+                        continue;
+                    }
+                    g.acn_map[ call_number ] = temp_acn;
+                }
+                call_number = g.acn_map[call_number];
+            }
             g.doc_id = call_number.record();
             if (!g.copy_shortcut[ call_number.owning_lib() ]) {
                 ou_ids.push( call_number.owning_lib() );
@@ -1044,37 +1058,13 @@ g.vivicate_update_volumes = function() {
                             continue;
                         }
                         g.acn_map[ acn_id ] = temp_acn;
-                        if (callnumber_data.acn_id < 0) {
-                            g.acn_map[ callnumber_data.acn_id ] = temp_acn;
-                        }
                     }
 
-                }
-/*
-                var my_acn = g.acn_map[ acn_id ];
-
-                var node = g.volumes_scaffold[ou_id][composite_key].node;
-                var class_menulist = node.parentNode.previousSibling.previousSibling.firstChild;
-                var prefix_menulist = node.parentNode.previousSibling.firstChild;
-                var suffix_menulist = node.parentNode.nextSibling.firstChild;
-
-                if ( String(class_menulist.value) != String(my_acn.label_class()) {
-                    my_acn.label_class( class_menulist.value );
-                    my_acn.ischanged( get_db_true() );
-                }
-                if ( String(prefix_menulist.value) != String(my_acn.prefix()) {
-                    my_acn.prefix( prefix_menulist.value );
-                    my_acn.ischanged( get_db_true() );
-                }
-                if ( String(suffix_menulist.value) != String(my_acn.suffix()) {
-                    my_acn.suffix( suffix_menulist.value );
-                    my_acn.ischanged( get_db_true() );
-                }
+                    if (typeof g.acn_map[ callnumber_data.acn_id ] == 'undefined') {
+                        g.acn_map[ callnumber_data.acn_id ] = g.acn_map[ acn_id ];
+                    }
 
-                if (get_bool( my_acn.ischanged() )) {
-                    volumes.push( my_acn );
                 }
-*/
             }
         }
         if (volumes.length > 0) {
@@ -1125,6 +1115,7 @@ g.stash_and_close = function(param) {
             }
         }
 
+        var label_editor_func;
         if (copies.length > 0) {
             if (param == 'edit') {
                 JSAN.use('cat.util');
@@ -1144,15 +1135,19 @@ g.stash_and_close = function(param) {
             try {
                 //case 1706 /* ITEM_BARCODE_EXISTS */ :
                 if (copies && copies.length > 0 && $('print_labels').checked) {
-                    JSAN.use('util.functional');
                     dont_close = true;
-                    xulG.set_tab(
-                        urls.XUL_SPINE_LABEL,
-                        { 'tab_name' : $("catStrings").getString('staff.cat.util.spine_editor.tab_name') },
-                        {
-                            'barcodes' : util.functional.map_list( copies, function(o){return o.barcode();})
-                        }
-                    );
+                    var tab_name = $("catStrings").getString('staff.cat.util.spine_editor.tab_name');
+                    var tab_method = xul_param('labels_in_new_tab') ? 'new_tab' : 'set_tab';
+                    label_editor_func = function() {
+                        JSAN.use('util.functional');
+                        xulG[tab_method](
+                            urls.XUL_SPINE_LABEL,
+                            { 'tab_name' : tab_name },
+                            {
+                                'barcodes' : util.functional.map_list( copies, function(o){return o.barcode();})
+                            }
+                        );
+                    };
                 }
             } catch(E) {
                 alert('2: Error in volume_copy_creator.js with g.stash_and_close(): ' + E);
@@ -1166,7 +1161,31 @@ g.stash_and_close = function(param) {
             xulG.unlock_copy_editor();
         }
 
-        if (! dont_close) { xulG.close_tab(); }
+        if (xul_param('load_opac_when_done')) {
+            var opac_url = xulG.url_prefix( urls.opac_rdetail ) + '?r=' + g.doc_id;
+            var content_params = {
+                'session' : ses(),
+                'authtime' : ses('authtime'),
+                'opac_url' : opac_url
+            };
+            xulG.set_tab(
+                xulG.url_prefix(urls.XUL_OPAC_WRAPPER),
+                {
+                    'tab_name':'Retrieving title...',
+                    'on_tab_load' : function(cw) {
+                        if (typeof label_editor_func == 'function') {
+                            label_editor_func();
+                        }
+                    }
+                },
+                content_params
+            );
+        } else {
+            if (typeof label_editor_func == 'function') {
+                label_editor_func();
+            }
+            if (! dont_close) { xulG.close_tab(); }
+        }
 
     } catch(E) {
         alert('3: Error in volume_copy_creator.js with g.stash_and_close(): ' + E);
-- 
2.11.0