From: phasefx Date: Tue, 8 Jan 2008 19:12:45 +0000 (+0000) Subject: refactor spawn_copy_editor and perm check X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=98abd9195a09fc03dec417f85d7b490ea0c51871;p=Evergreen.git refactor spawn_copy_editor and perm check git-svn-id: svn://svn.open-ils.org/ILS/branches/rel_1_2@8351 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- diff --git a/Open-ILS/xul/staff_client/server/admin/transit_list.js b/Open-ILS/xul/staff_client/server/admin/transit_list.js index 46ab60a4eb..2f48ce8327 100644 --- a/Open-ILS/xul/staff_client/server/admin/transit_list.js +++ b/Open-ILS/xul/staff_client/server/admin/transit_list.js @@ -433,11 +433,9 @@ admin.transit_list.prototype = { 'spawn_copy_editor' : function(which_list) { - /* FIXME - a lot of redundant calls here */ - var obj = this; - JSAN.use('util.widgets'); JSAN.use('util.functional'); + JSAN.use('util.functional'); var list = which_list == 0 ? obj.selection_list : obj.selection_list2; @@ -448,35 +446,7 @@ admin.transit_list.prototype = { } ); - var copies = util.functional.map_list( - list, - function (acp_id) { - return obj.network.simple_request('FM_ACP_RETRIEVE',[acp_id]); - } - ); - - 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( - copies, - function (o) { - return o.call_number() == -1 ? o.circ_lib() : obj.network.simple_request('FM_ACN_RETRIEVE',[o.call_number()]).owning_lib(); - } - ), - copies.length == 1 ? [ 'UPDATE_COPY' ] : [ 'UPDATE_COPY', 'UPDATE_BATCH_COPY' ] - ] - ).length == 0 ? 1 : 0; - } catch(E) { - obj.error.sdump('D_ERROR','batch permission check: ' + E); - } - - JSAN.use('cat.util'); cat.util.spawn_copy_editor(list,edit); + JSAN.use('cat.util'); cat.util.spawn_copy_editor( { 'copy_ids' : list, 'edit' : 1 } ); }, 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 da235d4659..ec56a8466a 100644 --- a/Open-ILS/xul/staff_client/server/cat/copy_browser.js +++ b/Open-ILS/xul/staff_client/server/cat/copy_browser.js @@ -295,33 +295,7 @@ cat.copy_browser.prototype = { } ); - 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) { - var o_acp = obj.map_acp[ 'acp_' + o ]; - if (o_acp.call_number() == -1) { - return o_acp.circ_lib(); - } else { - return obj.map_acn[ 'acn_' + o_acp.call_number() ].owning_lib(); - } - } - ), - list.length == 1 ? [ 'UPDATE_COPY' ] : [ 'UPDATE_COPY', 'UPDATE_BATCH_COPY' ] - ] - ).length == 0 ? 1 : 0; - } catch(E) { - obj.error.sdump('D_ERROR','batch permission check: ' + E); - } - - JSAN.use('cat.util'); cat.util.spawn_copy_editor(list,edit); + JSAN.use('cat.util'); cat.util.spawn_copy_editor( { 'copy_ids' : list, 'edit' : 1 } ); obj.refresh_list(); } catch(E) { diff --git a/Open-ILS/xul/staff_client/server/cat/copy_buckets.js b/Open-ILS/xul/staff_client/server/cat/copy_buckets.js index e37725c4f9..658c509efa 100644 --- a/Open-ILS/xul/staff_client/server/cat/copy_buckets.js +++ b/Open-ILS/xul/staff_client/server/cat/copy_buckets.js @@ -390,40 +390,11 @@ cat.copy_buckets.prototype = { } ); - var copies = util.functional.map_list( - list, - function (acp_id) { - return obj.network.simple_request('FM_ACP_RETRIEVE',[acp_id]); - } - ); - - 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( - copies, - function (o) { - return o.call_number() == -1 ? o.circ_lib() : obj.network.simple_request('FM_ACN_RETRIEVE',[o.call_number()]).owning_lib(); - } - ), - copies.length == 1 ? [ 'UPDATE_COPY' ] : [ 'UPDATE_COPY', 'UPDATE_BATCH_COPY' ] - ] - ).length == 0 ? 1 : 0; - } catch(E) { - obj.error.sdump('D_ERROR','batch permission check: ' + E); - } - - JSAN.use('cat.util'); cat.util.spawn_copy_editor(list,edit); + JSAN.use('cat.util'); cat.util.spawn_copy_editor( { 'copy_ids' : list, 'edit' : 1 } ); obj.render_pending_copies(); // FIXME -- need a generic refresh for lists setTimeout( function() { - JSAN.use('util.widgets'); util.widgets.dispatch('change_bucket',obj.controller.view.bucket_menulist); }, 0 ); diff --git a/Open-ILS/xul/staff_client/server/cat/copy_editor.js b/Open-ILS/xul/staff_client/server/cat/copy_editor.js index bd16a9d73a..0e40842497 100644 --- a/Open-ILS/xul/staff_client/server/cat/copy_editor.js +++ b/Open-ILS/xul/staff_client/server/cat/copy_editor.js @@ -1,4 +1,5 @@ var g = {}; +g.map_acn = {}; var xulG = {}; @@ -54,10 +55,47 @@ function my_init() { /* Is the interface an editor or a viewer, single or multi copy, existing copies or new copies? */ if (xul_param('edit',{'modal_xulG':true}) == '1') { - g.edit = true; - document.getElementById('caption').setAttribute('label','Copy Editor'); - document.getElementById('save').setAttribute('hidden','false'); - g.retrieve_templates(); + + // Editor desired, but let's check permissions + g.edit = false; + + try { + var check = g.network.simple_request( + 'PERM_MULTI_ORG_CHECK', + [ + ses(), + g.data.list.au[0].id(), + util.functional.map_list( + g.copies, + function (o) { + var lib; + var cn_id = o.call_number(); + if (cn_id == -1) { + lib = o.circ_lib(); // base perms on circ_lib instead of owning_lib if pre-cat + } else { + if (! g.map_acn[ cn_id ]) { + g.map_acn[ cn_id ] = g.network.simple_request('FM_ACN_RETRIEVE',[ cn_id ]); + } + lib = g.map_acn[ cn_id ].owning_lib(); + } + return lib; + } + ), + g.copies.length == 1 ? [ 'UPDATE_COPY' ] : [ 'UPDATE_COPY', 'UPDATE_BATCH_COPY' ] + ] + ); + g.edit = check.length == 0; + } catch(E) { + g.error.standard_unexpected_error_alert('batch permission check',E); + } + + if (g.edit) { + document.getElementById('caption').setAttribute('label','Copy Editor'); + document.getElementById('save').setAttribute('hidden','false'); + g.retrieve_templates(); + } else { + $('top_nav').setAttribute('hidden','true'); + } } else { $('top_nav').setAttribute('hidden','true'); } @@ -381,7 +419,6 @@ g.apply_stat_cat = function(sc_id,entry_id) { /******************************************************************************************************/ /* Apply an "owning lib" to all the copies being edited. That is, change and auto-vivicating volumes */ -g.map_acn = {}; g.apply_owning_lib = function(ou_id) { g.error.sdump('D_TRACE','ou_id = ' + ou_id + '\n'); for (var i = 0; i < g.copies.length; i++) { diff --git a/Open-ILS/xul/staff_client/server/cat/util.js b/Open-ILS/xul/staff_client/server/cat/util.js index 715fc994f2..11dc97a327 100644 --- a/Open-ILS/xul/staff_client/server/cat/util.js +++ b/Open-ILS/xul/staff_client/server/cat/util.js @@ -217,39 +217,36 @@ cat.util.add_copies_to_bucket = function(selection_list) { ); } -cat.util.spawn_copy_editor = function(list,edit) { +cat.util.spawn_copy_editor = function(params) { try { + if (!params.copy_ids && !params.copies) return; + if (params.copy_ids && params.copy_ids.length == 0) return; + if (params.copies && params.copies.length == 0) return; + if (params.copy_ids) params.copy_ids = js2JSON(params.copy_ids); // legacy + if (!params.caller_handles_update) params.handle_update = 1; // legacy + var obj = {}; JSAN.use('util.network'); obj.network = new util.network(); JSAN.use('util.error'); obj.error = new util.error(); - if (list.length == 0) return; - - var title = list.length == 1 ? '' : 'Batch '; - title += edit == 1 ? 'Edit' : 'View'; + var title = ''; + if ((params.copy_ids && params.copy_ids.length > 1) || (params.copies && params.copies.length > 1 )) title += 'Batch '; + title += params.edit == 1 ? 'Edit' : 'View'; title += ' Copy Attributes'; JSAN.use('util.window'); var win = new util.window(); - //JSAN.use('OpenILS.data'); obj.data = new OpenILS.data(); obj.data.init({'via':'stash'}); - //obj.data.temp_copies = undefined; obj.data.stash('temp_copies'); - //obj.data.temp_callnumbers = undefined; obj.data.stash('temp_callnumbers'); - //obj.data.temp_copy_ids = js2JSON(list); obj.data.stash('temp_copy_ids'); var my_xulG = win.open( - //window.xulG.url_prefix(urls.XUL_COPY_EDITOR), (urls.XUL_COPY_EDITOR), - // +'?handle_update=1&edit='+edit, title, 'chrome,modal,resizable', - { - 'handle_update' : 1, - 'edit' : edit, - 'copy_ids' : js2JSON(list), - } + params ); - //obj.data.stash_retrieve(); - if (!my_xulG.copies) alert('Copies not modified.'); - //if (!obj.data.temp_copies) alert('Copies not modified.'); - //obj.data.temp_copies = undefined; obj.data.stash('temp_copies'); + if (!my_xulG.copies && params.edit) { + alert(typeof params.no_copies_modified_msg != 'undefined' ? params.no_copies_modified_msg : 'Copies not modified.'); + } else { + return my_xulG.copies; + } + return []; } catch(E) { JSAN.use('util.error'); var error = new util.error(); error.standard_unexpected_error_alert('error in cat.util.spawn_copy_editor',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 53573bd465..865081fc0a 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 @@ -1,3 +1,5 @@ +var g = {}; + function my_init() { try { @@ -374,46 +376,24 @@ g.stash_and_close = function() { JSAN.use('util.window'); var win = new util.window(); if (copies.length > 0) { - //g.data.temp_copies = js2JSON(copies); g.data.stash('temp_copies'); - //g.data.temp_copy_ids = undefined; g.data.stash('temp_copy_ids'); - ////g.data.temp_callnumbers = js2JSON(volume_labels); g.data.stash('temp_callnumbers'); - //g.data.temp_callnumbers = undefined; g.data.stash('temp_callnumbers'); - var my_xulG = win.open( - urls.XUL_COPY_EDITOR, - //+'?edit=1&handle_update=1&docid='+window.escape(g.doc_id), - title, - 'chrome,modal,resizable', - { 'edit' : 1, 'handle_update' : 1, 'docid' : g.doc_id, 'copies' : copies } - ); - /* FIXME -- need to unique the temp space, and not rely on modalness of window */ - //g.data.stash_retrieve(); - //copies = JSON2js( g.data.temp_copies ); - copies = my_xulG.copies; - //g.data.temp_copy_ids = undefined; g.data.stash('temp_copy_ids'); - //g.data.temp_copies = undefined; g.data.stash('temp_copies'); - //g.data.temp_callnumbers = undefined; g.data.stash('temp_callnumbers'); - if (!copies) { - alert('Items were not created.'); - return; - } else { - try { - //case 1706 /* ITEM_BARCODE_EXISTS */ : - if (copies.length > 0 && $('print_labels').checked) { - JSAN.use('util.functional'); - JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.stash_retrieve(); - data.temp_barcodes_for_labels = util.functional.map_list( copies, function(o){return o.barcode();}) ; - data.stash('temp_barcodes_for_labels'); - var w = win.open( - urls.XUL_SPINE_LABEL, - 'spine_labels', - 'chrome,resizable,width=750,height=550' - ); - } - } catch(E) { - g.error.standard_unexpected_error_alert('volume tree update 2',E); - } - - } + JSAN.use('cat.util'); + copies = cat.util.spawn_copy_editor( { 'edit' : 1, 'docid' : g.doc_id, 'copies' : copies }); + try { + //case 1706 /* ITEM_BARCODE_EXISTS */ : + if (copies && copies.length > 0 && $('print_labels').checked) { + JSAN.use('util.functional'); + JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.stash_retrieve(); + data.temp_barcodes_for_labels = util.functional.map_list( copies, function(o){return o.barcode();}) ; + data.stash('temp_barcodes_for_labels'); + var w = win.open( + urls.XUL_SPINE_LABEL, + 'spine_labels', + 'chrome,resizable,width=750,height=550' + ); + } + } catch(E) { + g.error.standard_unexpected_error_alert('volume tree update 2',E); + } } if (typeof window.refresh == 'function') window.refresh(); diff --git a/Open-ILS/xul/staff_client/server/cat/volume_copy_creator.xul b/Open-ILS/xul/staff_client/server/cat/volume_copy_creator.xul index 085d6191e3..f6ad7735af 100644 --- a/Open-ILS/xul/staff_client/server/cat/volume_copy_creator.xul +++ b/Open-ILS/xul/staff_client/server/cat/volume_copy_creator.xul @@ -27,7 +27,7 @@ diff --git a/Open-ILS/xul/staff_client/server/circ/checkin.js b/Open-ILS/xul/staff_client/server/circ/checkin.js index 50688213d6..1809617282 100644 --- a/Open-ILS/xul/staff_client/server/circ/checkin.js +++ b/Open-ILS/xul/staff_client/server/circ/checkin.js @@ -418,11 +418,9 @@ circ.checkin.prototype = { 'spawn_copy_editor' : function() { - /* FIXME - a lot of redundant calls here */ - var obj = this; - JSAN.use('util.widgets'); JSAN.use('util.functional'); + JSAN.use('util.functional'); var list = obj.selection_list; @@ -433,35 +431,7 @@ circ.checkin.prototype = { } ); - var copies = util.functional.map_list( - list, - function (acp_id) { - return obj.network.simple_request('FM_ACP_RETRIEVE',[acp_id]); - } - ); - - 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( - copies, - function (o) { - return o.call_number() == -1 ? o.circ_lib() : obj.network.simple_request('FM_ACN_RETRIEVE',[o.call_number()]).owning_lib(); - } - ), - copies.length == 1 ? [ 'UPDATE_COPY' ] : [ 'UPDATE_COPY', 'UPDATE_BATCH_COPY' ] - ] - ).length == 0 ? 1 : 0; - } catch(E) { - obj.error.sdump('D_ERROR','batch permission check: ' + E); - } - - JSAN.use('cat.util'); cat.util.spawn_copy_editor(list,edit); + JSAN.use('cat.util'); cat.util.spawn_copy_editor( { 'copy_ids' : list, 'edit' : 1 } ); }, diff --git a/Open-ILS/xul/staff_client/server/circ/copy_status.js b/Open-ILS/xul/staff_client/server/circ/copy_status.js index ab8f8f0f17..1038e821e3 100644 --- a/Open-ILS/xul/staff_client/server/circ/copy_status.js +++ b/Open-ILS/xul/staff_client/server/circ/copy_status.js @@ -1017,11 +1017,9 @@ circ.copy_status.prototype = { 'spawn_copy_editor' : function() { - /* FIXME - a lot of redundant calls here */ - var obj = this; - JSAN.use('util.widgets'); JSAN.use('util.functional'); + JSAN.use('util.functional'); var list = obj.selection_list; @@ -1032,35 +1030,7 @@ circ.copy_status.prototype = { } ); - var copies = util.functional.map_list( - list, - function (acp_id) { - return obj.network.simple_request('FM_ACP_RETRIEVE',[acp_id]); - } - ); - - 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( - copies, - function (o) { - return o.call_number() == -1 ? o.circ_lib() : obj.network.simple_request('FM_ACN_RETRIEVE',[o.call_number()]).owning_lib(); - } - ), - copies.length == 1 ? [ 'UPDATE_COPY' ] : [ 'UPDATE_COPY', 'UPDATE_BATCH_COPY' ] - ] - ).length == 0 ? 1 : 0; - } catch(E) { - obj.error.sdump('D_ERROR','batch permission check: ' + E); - } - - JSAN.use('cat.util'); cat.util.spawn_copy_editor(list,edit); + JSAN.use('cat.util'); cat.util.spawn_copy_editor( { 'copy_ids' : list, 'edit' : 1 } ); },