From be9ffe1b85528556b1adad806efa6dd9923ca64f Mon Sep 17 00:00:00 2001 From: phasefx Date: Thu, 11 Mar 2010 09:53:32 +0000 Subject: [PATCH] refactoring of Volume Editor invocations to use a utility function, make VOLUME_LABEL_EXISTS event overridable, provide an upfront checkbox for auto-merge functionality on volume collision, and some accesskeys and default textbox focus 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 | 4 + .../staff_client/server/cat/copy_browser.js | 96 +-------------- Open-ILS/xul/staff_client/server/cat/util.js | 95 ++++++++++++++- .../staff_client/server/cat/volume_editor.xul | 16 ++- .../staff_client/server/circ/copy_status.js | 111 ++---------------- .../server/locale/en-US/cat.properties | 12 +- 6 files changed, 129 insertions(+), 205 deletions(-) diff --git a/Open-ILS/web/opac/locale/en-US/lang.dtd b/Open-ILS/web/opac/locale/en-US/lang.dtd index 25312867a5..9122c68120 100644 --- a/Open-ILS/web/opac/locale/en-US/lang.dtd +++ b/Open-ILS/web/opac/locale/en-US/lang.dtd @@ -2516,7 +2516,11 @@ + + + + diff --git a/Open-ILS/xul/staff_client/server/cat/copy_browser.js b/Open-ILS/xul/staff_client/server/cat/copy_browser.js index 4dce66c545..443472f52d 100644 --- a/Open-ILS/xul/staff_client/server/cat/copy_browser.js +++ b/Open-ILS/xul/staff_client/server/cat/copy_browser.js @@ -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); diff --git a/Open-ILS/xul/staff_client/server/cat/util.js b/Open-ILS/xul/staff_client/server/cat/util.js index 1e76954b43..c771491b1a 100644 --- a/Open-ILS/xul/staff_client/server/cat/util.js +++ b/Open-ILS/xul/staff_client/server/cat/util.js @@ -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'); diff --git a/Open-ILS/xul/staff_client/server/cat/volume_editor.xul b/Open-ILS/xul/staff_client/server/cat/volume_editor.xul index 28cfc2658f..b8f57783e7 100644 --- a/Open-ILS/xul/staff_client/server/cat/volume_editor.xul +++ b/Open-ILS/xul/staff_client/server/cat/volume_editor.xul @@ -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 ); @@ -55,10 +53,13 @@ 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) { @@ -102,9 +106,13 @@ -