refactoring of Volume Editor invocations to use a utility function, make VOLUME_LABEL...
authorphasefx <phasefx@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 11 Mar 2010 09:53:32 +0000 (09:53 +0000)
committerphasefx <phasefx@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 11 Mar 2010 09:53:32 +0000 (09:53 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@15785 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/web/opac/locale/en-US/lang.dtd
Open-ILS/xul/staff_client/server/cat/copy_browser.js
Open-ILS/xul/staff_client/server/cat/util.js
Open-ILS/xul/staff_client/server/cat/volume_editor.xul
Open-ILS/xul/staff_client/server/circ/copy_status.js
Open-ILS/xul/staff_client/server/locale/en-US/cat.properties

index 2531286..9122c68 100644 (file)
 <!ENTITY staff.cat.volume_editor.title "Volumes">
 <!ENTITY staff.cat.volume_editor.caption.label "Volume Editor">
 <!ENTITY staff.cat.volume_editor.modify.label "Modify">
+<!ENTITY staff.cat.volume_editor.modify.accesskey "M">
 <!ENTITY staff.cat.volume_editor.cancel.label "Cancel">
+<!ENTITY staff.cat.volume_editor.cancel.accesskey "C">
+<!ENTITY staff.cat.volume_editor.automerge.label "Auto-Merge on Volume Collision">
+<!ENTITY staff.cat.volume_editor.automerge.accesskey "A">
 <!ENTITY staff.cat.z3950.marc_import.label "MARC Import via Z39.50">
 <!ENTITY staff.cat.z3950.marc_import.accesskey "I">
 <!ENTITY staff.cat.z3950.service_credentials.label "Service and Credentials">
index 4dce66c..443472f 100644 (file)
@@ -516,7 +516,7 @@ cat.copy_browser.prototype = {
                             function() {
                                 try {
                                     JSAN.use('util.functional');
-                                    var list = util.functional.map_list(
+                                    var volumes = util.functional.map_list(
                                         util.functional.filter_list(
                                             obj.sel_list,
                                             function (o) {
@@ -527,102 +527,18 @@ cat.copy_browser.prototype = {
                                             return o.split(/_/)[1];
                                         }
                                     );
-                                    if (list.length == 0) return;
-
-                                    var edit = 0;
-                                    try {
-                                        edit = obj.network.request(
-                                            api.PERM_MULTI_ORG_CHECK.app,
-                                            api.PERM_MULTI_ORG_CHECK.method,
-                                            [ 
-                                                ses(), 
-                                                obj.data.list.au[0].id(), 
-                                                util.functional.map_list(
-                                                    list,
-                                                    function (o) {
-                                                        return obj.map_acn[ 'acn_' + o ].owning_lib();
-                                                    }
-                                                ),
-                                                [ 'UPDATE_VOLUME' ]
-                                            ]
-                                        ).length == 0 ? 1 : 0;
-                                    } catch(E) {
-                                        obj.error.sdump('D_ERROR','batch permission check: ' + E);
-                                    }
-
-                                    if (edit==0) {
-                                        alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.edit_volume.permission_error'));
-                                        return; // no read-only view for this interface
-                                    }
-
-                                    list = util.functional.map_list(
-                                        list,
-                                        function (o) {
-                                            var my_acn = obj.map_acn['acn_' + o];
-                                            return function(r){return r;}(my_acn);
-                                        }
-                                    );
-
-                                    var title;
-                                    if (list.length == 1) {
-                                        title = document.getElementById('catStrings').getString('staff.cat.copy_browser.edit_volume.title');
-                                    } else {
-                                        title = document.getElementById('catStrings').getString('staff.cat.copy_browser.edit_volume.title.plural');
-                                    }
-
-                                    JSAN.use('util.window'); var win = new util.window();
-                                    //obj.data.volumes_temp = js2JSON( list );
-                                    //obj.data.stash('volumes_temp');
-                                    var my_xulG = win.open(
-                                        window.xulG.url_prefix(urls.XUL_VOLUME_EDITOR),
-                                        title,
-                                        'chrome,modal,resizable',
-                                        { 'volumes' : JSON2js(js2JSON(list)) }
-                                    );
-
-                                    /* FIXME -- need to unique the temp space, and not rely on modalness of window */
-                                    //obj.data.stash_retrieve();
-                                    if (typeof my_xulG.update_these_volumes == 'undefined') { return; }
-                                    var volumes = my_xulG.volumes;
-                                    if (!volumes) return;
-                                
-                                    volumes = util.functional.filter_list(
-                                        volumes,
-                                        function (o) {
-                                            return o.ischanged() == '1';
-                                        }
-                                    );
-
                                     volumes = util.functional.map_list(
                                         volumes,
                                         function (o) {
-                                            o.record( obj.docid ); // staff client 2 did not do this.  Does it matter?
-                                            return o;
+                                            var my_acn = obj.map_acn['acn_' + o];
+                                            return function(r){return r;}(my_acn);
                                         }
                                     );
 
-                                    if (volumes.length == 0) return;
-
-                                    try {
-                                        var r = obj.network.request(
-                                            api.FM_ACN_TREE_UPDATE.app,
-                                            api.FM_ACN_TREE_UPDATE.method,
-                                            [ ses(), volumes, true ]
-                                        );
-                                        if (typeof r.ilsevent != 'undefined') {
-                                            switch(Number(r.ilsevent)) {
-                                                case 1705 /* VOLUME_LABEL_EXISTS */ :
-                                                    alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.edit_volume.failed'));
-                                                    break;
-                                                default: throw(r);
-                                            }
-                                        } else {
-                                            alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.edit_volume.success'));
-                                        }
-                                    } catch(E) {
-                                        obj.error.standard_unexpected_error_alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.edit_volume.error'),E);
+                                    JSAN.use('cat.util'); 
+                                    if ( cat.util.batch_edit_volumes( volumes ) ) {
+                                        obj.refresh_list();
                                     }
-                                    obj.refresh_list();
 
                                 } catch(E) {
                                     obj.error.standard_unexpected_error_alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.edit_volume.exception'),E);
index 1e76954..c771491 100644 (file)
@@ -8,7 +8,7 @@ cat.util = {};
 cat.util.EXPORT_OK    = [ 
     'spawn_copy_editor', 'add_copies_to_bucket', 'show_in_opac', 'spawn_spine_editor', 'transfer_copies', 
     'transfer_title_holds', 'mark_item_missing', 'mark_item_damaged', 'replace_barcode', 'fast_item_add', 
-    'make_bookable', 'edit_new_brsrc', 'edit_new_bresv'
+    'make_bookable', 'edit_new_brsrc', 'edit_new_bresv', 'batch_edit_volumes'
 ];
 cat.util.EXPORT_TAGS    = { ':all' : cat.util.EXPORT_OK };
 
@@ -626,4 +626,97 @@ cat.util.edit_new_bresv = function(booking_results) {
     }
 }
 
+cat.util.batch_edit_volumes = function(fleshed_volumes) {
+    try {
+        if (!fleshed_volumes || fleshed_volumes.length < 1) { return false; }
+
+        JSAN.use('util.functional');
+        JSAN.use('util.network'); var net = new util.network();
+        JSAN.use('util.window'); var win = new util.window();
+
+        var can_edit = net.simple_request(
+            'PERM_MULTI_ORG_CHECK',
+            [
+                ses(),
+                ses('staff_id'),
+                util.functional.map_list(
+                    fleshed_volumes,
+                    function(v) {
+                        return v.owning_lib();
+                    }
+                ),
+                ['UPDATE_VOLUME']
+            ]
+        );
+        if (!can_edit) {
+            alert(document.getElementById('catStrings').getString('staff.cat.edit_volume.permission_error'));
+            return false;
+        }
+        var title;
+        if (fleshed_volumes.length == 1) {
+            title = document.getElementById('catStrings').getString('staff.cat.edit_volume.title');
+        } else {
+            title = document.getElementById('catStrings').getString('staff.cat.edit_volume.title.plural');
+        }
+
+        function clone_list(o) {
+            var list = JSON2js( js2JSON( o ) );
+            // now that it is safe to clear copies, let's do so, otherwise may get an error from volume edit method
+            for (var i = 0; i < list.length; i++) { list[i].copies( [] ); } 
+            return list;
+        }
+
+        var my_xulG = win.open(
+            xulG.url_prefix(urls.XUL_VOLUME_EDITOR),
+            title,
+            'chrome,modal,resizable',
+            { 'volumes' : clone_list( fleshed_volumes ) }
+        );
+
+        if (typeof my_xulG.update_these_volumes == 'undefined') { return false; }
+
+        var volumes = util.functional.filter_list(
+            my_xulG.volumes,
+            function(v) {
+                return get_bool( v.ischanged() );
+            }
+        );
+
+        if (volumes.length < 1) { return false; }
+
+        var r = net.simple_request(
+            'FM_ACN_TREE_UPDATE',
+            [ ses(), volumes, false, { 'auto_merge_vols' : my_xulG.auto_merge } ],
+            null,
+            {
+                'title' : document.getElementById('catStrings').getString('staff.cat.edit_volumes.override.confirm'),
+                'overridable_events' : [
+                    1705 /* VOLUME_LABEL_EXISTS */
+                ],
+                'text' : {
+                    '1705' : function(r) {
+                        var payload_acn = util.functional.find_id_object_in_list( volumes, r.payload );
+                        return document.getElementById('catStrings').getFormattedString('staff.cat.edit_volumes.label_exists.details',[payload_acn.label()]);
+                    }
+                }
+            }
+        );
+        if (!r) { throw('Update method returned null or false.'); }
+        if (typeof r.ilsevent != 'undefined') {
+            if (r.ilsevent == 1705 /* VOLUME_LABEL_EXISTS */) {
+               /* not overriden, but otherwise handled, so ignore */
+                return false;
+            } else {
+                throw(r);
+            }
+        }
+
+        return true;
+
+    } catch(E) {
+        alert('Error in cat.util.batch_edit_volumes: ' + E);
+        return false;
+    }
+}
+
 dump('exiting cat/util.js\n');
index 28cfc26..b8f5778 100644 (file)
@@ -46,8 +46,6 @@
 
                 JSAN.use('OpenILS.data'); g.data = new OpenILS.data(); g.data.init({'via':'stash'});
 
-                JSAN.use('util.network'); g.network = new util.network();
-
                 JSAN.use('util.functional');
 
                 g.volumes = xul_param('volumes',{'stash_name':'volumes_temp','clear_xpcom':true,'modal_xulG':true}); //JSON2js( g.data.volumes_temp );
 
                 var rows = document.getElementById('rows');
 
+                var first_tb;
+
                 for (var i = 0; i < g.volumes.length; i++) {
                     var row = document.createElement('row'); rows.appendChild(row);
                     var lib_label = document.createElement('label'); row.appendChild(lib_label);
                     var tb = document.createElement('textbox'); row.appendChild(tb);
+                    if (!first_tb) { first_tb = tb; }
 
                     var lib_id = g.volumes[i].owning_lib();
                     var last_lib_seen;
@@ -72,6 +73,8 @@
                     tb.setAttribute('onchange','try { var v = g.volumes['+i+']; v.ischanged("1"); v.label( this.value ); } catch(E) { alert(E); }');
                 }
 
+                first_tb.select(); first_tb.focus();
+
             } catch(E) {
                 var err_msg = $("commonStrings").getFormattedString('common.exception', ['cat/volume_editor.xul', E]);
                 try { g.error.sdump('D_ERROR',err_msg); } catch(E) { dump(err_msg); dump(js2JSON(E)); }
@@ -86,6 +89,7 @@
                 //g.data.stash('volumes_temp');
                 xulG.volumes = g.volumes;
                 xulG.update_these_volumes = 1;
+                xulG.auto_merge = document.getElementById('auto_merge').checked;
                 update_modal_xulG(xulG);
                 window.close();
             } catch(E) {
     <groupbox flex="1" style="overflow: auto">
         <caption id="caption" label="&staff.cat.volume_editor.caption.label;"/>
         <hbox>
-            <button label="&staff.cat.volume_editor.cancel.label;" oncommand="window.close();"/>
+            <button label="&staff.cat.volume_editor.cancel.label;" accesskey="&staff.cat.volume_editor.cancel.accesskey;" oncommand="window.close();"/>
+            <spacer flex="1" />
+            <button label="&staff.cat.volume_editor.modify.label;" accesskey="&staff.cat.volume_editor.modify.accesskey;" oncommand="g.stash_and_close();"/>
+        </hbox>
+        <hbox>
             <spacer flex="1" />
-            <button label="&staff.cat.volume_editor.modify.label;" oncommand="g.stash_and_close();"/>
+            <checkbox id="auto_merge" label="&staff.cat.volume_editor.automerge.label;" accesskey="&staff.cat.volume_editor.automerge.accesskey;" oils_persist="checked"/>
         </hbox>
         <grid flex="1">
             <columns> <column /> <column /> <column flex="1"/> </columns>
index d4ddb89..d997b0e 100644 (file)
@@ -695,119 +695,24 @@ circ.copy_status.prototype = {
                                 var list = util.functional.map_list( obj.selection_list, function(o) { return o.acn_id; } );
                                 if (list.length == 0) { return; }
 
-                                var volume_hash = {}; var map_acn = {};
+                                var volumes = []; var seen = {};
 
                                 for (var i = 0; i < list.length; i++) {
                                     var volume_id = list[i];
                                     if (volume_id == -1) {
                                         continue; /* ignore magic pre-cat volume */
                                     }
-                                    if (! map_acn[volume_id]) {
-                                        map_acn[ volume_id ] = obj.network.simple_request('FM_ACN_RETRIEVE.authoritative',[ volume_id ]);
-                                        map_acn[ volume_id ].copies( [] );
-                                    }
-                                    var record_id = map_acn[ volume_id ].record();
-                                    if (!volume_hash[record_id]) {
-                                        volume_hash[record_id] = {};
+                                    if (! seen[volume_id]) {
+                                        seen[volume_id] = 1;
+                                        var volume = obj.network.simple_request('FM_ACN_RETRIEVE.authoritative',[ volume_id ]);
+                                        if (volume && typeof volume.ils_event == 'undefined') {
+                                            volumes.push( volume );
+                                        }
                                     }
-                                    volume_hash[record_id][volume_id] = 1;
                                 }
 
-                                for (var rec in volume_hash) {
-
-                                    list = [];
-                                    for (var v in volume_hash[rec]) {
-                                        list.push( map_acn[v] );
-                                    }
-
-                                    var edit = 0;
-                                    try {
-                                        edit = obj.network.request(
-                                            api.PERM_MULTI_ORG_CHECK.app,
-                                            api.PERM_MULTI_ORG_CHECK.method,
-                                            [ 
-                                                ses(), 
-                                                obj.data.list.au[0].id(), 
-                                                util.functional.map_list(
-                                                    list,
-                                                    function (o) {
-                                                        return o.owning_lib();
-                                                    }
-                                                ),
-                                                [ 'UPDATE_VOLUME' ]
-                                            ]
-                                        ).length == 0 ? 1 : 0;
-                                    } catch(E) {
-                                        obj.error.sdump('D_ERROR','batch permission check: ' + E);
-                                    }
-
-                                    if (edit==0) {
-                                        alert(document.getElementById('circStrings').getString('staff.circ.copy_status.edit_volumes.perm_failure'));
-                                        return; // no read-only view for this interface
-                                    }
-
-                                    var title;
-                                    if (list.length == 1) {
-                                        title = document.getElementById('circStrings').getFormattedString('staff.circ.copy_status.edit_volume.title', [rec]);
-                                    } else {
-                                        title = document.getElementById('circStrings').getFormattedString('staff.circ.copy_status.edit_volumes.title', [rec]);
-                                    }
-
-                                    JSAN.use('util.window'); var win = new util.window();
-                                    //obj.data.volumes_temp = js2JSON( list );
-                                    //obj.data.stash('volumes_temp');
-                                    var my_xulG = win.open(
-                                        window.xulG.url_prefix(urls.XUL_VOLUME_EDITOR),
-                                        title,
-                                        'chrome,modal,resizable',
-                                        { 'volumes' : JSON2js(js2JSON(list)) }
-                                    );
-
-                                    /* FIXME -- need to unique the temp space, and not rely on modalness of window */
-                                    //obj.data.stash_retrieve();
-                                    //var volumes = JSON2js( obj.data.volumes_temp );
-                                    if (typeof my_xulG.update_these_volumes == 'undefined') { return; }
-                                    var volumes = my_xulG.volumes;
-                                    if (!volumes) { return; }
-                                
-                                    volumes = util.functional.filter_list(
-                                        volumes,
-                                        function (o) {
-                                            return o.ischanged() == '1';
-                                        }
-                                    );
+                                JSAN.use('cat.util'); cat.util.batch_edit_volumes( volumes );
 
-                                    volumes = util.functional.map_list(
-                                        volumes,
-                                        function (o) {
-                                            o.record( rec ); // staff client 2 did not do this.  Does it matter?
-                                            return o;
-                                        }
-                                    );
-
-                                    if (volumes.length == 0) { return; }
-
-                                    try {
-                                        var r = obj.network.request(
-                                            api.FM_ACN_TREE_UPDATE.app,
-                                            api.FM_ACN_TREE_UPDATE.method,
-                                            [ ses(), volumes, false ]
-                                        );
-                                        if (typeof r.ilsevent != 'undefined') {
-                                            switch(Number(r.ilsevent)) {
-                                                case 1705 /* VOLUME_LABEL_EXISTS */ :
-                                                    alert(document.getElementById('circStrings').getString('staff.circ.copy_status.edit_volumes.duplicate'));
-                                                    break;
-                                                default: throw(r);
-                                            }
-                                        } else {
-                                            alert(document.getElementById('circStrings').getString('staff.circ.copy_status.edit_volumes.success'));
-                                        }
-                                    } catch(E) {
-                                        obj.error.standard_unexpected_error_alert('volume update error: ',E);
-                                    }
-
-                                }
                             } catch(E) {
                                 obj.error.standard_unexpected_error_alert('Copy Status -> Volume Edit',E);
                             }
index 5071a0e..b29dad1 100644 (file)
@@ -32,13 +32,11 @@ staff.cat.copy_browser.print_spine.error=copy browser -> Spine Labels
 staff.cat.copy_browser.add_volume.permission_error=You do not have permission to add volumes to that library.
 staff.cat.copy_browser.add_volume.title=Add Volume/Item
 staff.cat.copy_browser.add_volume.error=copy browser -> add volumes
-staff.cat.copy_browser.edit_volume.permission_error=You do not have permission to edit this volume.
-staff.cat.copy_browser.edit_volume.title=Volume
-staff.cat.copy_browser.edit_volume.title.plural=Volumes
-staff.cat.copy_browser.edit_volume.failed=Edit failed:  You tried to change a volume's callnumber to one that is already in use for the given library.  You should transfer the items to the desired callnumber instead.
-staff.cat.copy_browser.edit_volume.success=Volumes modified.
-staff.cat.copy_browser.edit_volume.error=volume update error: 
-staff.cat.copy_browser.edit_volume.exception=Copy Browser -> Volume Edit
+staff.cat.edit_volume.permission_error=You do not have permission to edit the volume or volumes selected.
+staff.cat.edit_volume.title=Volume
+staff.cat.edit_volume.title.plural=Volumes
+staff.cat.edit_volumes.override.confirm=Override volume re-labeling collision and merge the volumes?
+staff.cat.edit_volumes.label_exists.details=%1$s
 staff.cat.copy_browser.delete_volume.prompt=Are you sure you would like to delete this volume?
 staff.cat.copy_browser.delete_volume.prompt.plural=Are you sure you would like to delete these %1$s volumes?
 staff.cat.copy_browser.delete_volume.title=Delete Volumes?