From: phasefx Date: Fri, 15 Jun 2007 10:11:31 +0000 (+0000) Subject: Batch upload function and refresh-row-in-place behavior X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=b9592134c2df33fb437df728d3a718496b1b701b;p=Evergreen.git Batch upload function and refresh-row-in-place behavior git-svn-id: svn://svn.open-ils.org/ILS/branches/rel_1_0@7430 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- 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 0cc79cf358..7aa5c277e0 100644 --- a/Open-ILS/xul/staff_client/server/circ/copy_status.js +++ b/Open-ILS/xul/staff_client/server/circ/copy_status.js @@ -8,10 +8,12 @@ circ.copy_status = function (params) { JSAN.use('util.barcode'); JSAN.use('util.date'); JSAN.use('OpenILS.data'); this.data = new OpenILS.data(); this.data.init({'via':'stash'}); + JSAN.use('util.sound'); this.sound = new util.sound(); } circ.copy_status.prototype = { 'selection_list' : [], + 'list_barcode_map' : {}, 'init' : function( params ) { @@ -121,10 +123,10 @@ circ.copy_status.prototype = { for (var i = 0; i < obj.selection_list.length; i++) { var barcode = obj.selection_list[i].barcode; var checkin = circ.util.checkin_via_barcode( ses(), { 'barcode' : barcode } ); - funcs.push( function(a) { return function() { obj.copy_status( a ); }; }(barcode) ); + funcs.push( function(a) { return function() { obj.copy_status( a, true ); }; }(barcode) ); } - alert('Action complete.'); for (var i = 0; i < funcs.length; i++) { funcs[i](); } + alert('Action complete.'); } catch(E) { obj.error.standard_unexpected_error_alert('Checkin did not likely happen.',E); } @@ -140,13 +142,13 @@ circ.copy_status.prototype = { try { var barcode = obj.selection_list[i].barcode; var new_bc = cat.util.replace_barcode( barcode ); - funcs.push( function(a) { return function() { obj.copy_status( a ); }; }(new_bc) ); + funcs.push( function(a) { return function() { obj.copy_status( a, true ); }; }(new_bc) ); } catch(E) { obj.error.standard_unexpected_error_alert('Barcode ' + barcode + ' was not likely replaced.',E); } } - alert('Action complete.'); for (var i = 0; i < funcs.length; i++) { funcs[i](); } + alert('Action complete.'); } catch(E) { obj.error.standard_unexpected_error_alert('Barcode replacements did not likely happen.',E); } @@ -160,7 +162,7 @@ circ.copy_status.prototype = { obj.spawn_copy_editor(); for (var i = 0; i < obj.selection_list.length; i++) { var barcode = obj.selection_list[i].barcode; - funcs.push( function(a) { return function() { obj.copy_status( a ); }; }(barcode) ); + funcs.push( function(a) { return function() { obj.copy_status( a, true ); }; }(barcode) ); } for (var i = 0; i < funcs.length; i++) { funcs[i](); } } catch(E) { @@ -190,10 +192,10 @@ circ.copy_status.prototype = { circ.util.abort_transits(obj.selection_list); for (var i = 0; i < obj.selection_list.length; i++) { var barcode = obj.selection_list[i].barcode; - funcs.push( function(a) { return function() { obj.copy_status( a ); }; }(barcode) ); + funcs.push( function(a) { return function() { obj.copy_status( a, true ); }; }(barcode) ); } - alert('Action complete.'); for (var i = 0; i < funcs.length; i++) { funcs[i](); } + alert('Action complete.'); } ], 'sel_patron' : [ @@ -222,13 +224,13 @@ circ.copy_status.prototype = { var barcode = obj.selection_list[i].barcode; if (test == 't') { circ.util.renew_via_barcode( barcode ); - funcs.push( function(a) { return function() { obj.copy_status( a ); }; }(barcode) ); + funcs.push( function(a) { return function() { obj.copy_status( a, true ); }; }(barcode) ); } else { alert('Item with barcode ' + barcode + ' is not circulating.'); } } - alert('Action complete.'); for (var i = 0; i < funcs.length; i++) { funcs[i](); } + alert('Action complete.'); } ], @@ -240,7 +242,7 @@ circ.copy_status.prototype = { cat.util.mark_item_damaged( util.functional.map_list( obj.selection_list, function(o) { return o.copy_id; } ) ); for (var i = 0; i < obj.selection_list.length; i++) { var barcode = obj.selection_list[i].barcode; - funcs.push( function(a) { return function() { obj.copy_status( a ); }; }(barcode) ); + funcs.push( function(a) { return function() { obj.copy_status( a, true ); }; }(barcode) ); } for (var i = 0; i < funcs.length; i++) { funcs[i](); } } @@ -253,7 +255,7 @@ circ.copy_status.prototype = { cat.util.mark_item_missing( util.functional.map_list( obj.selection_list, function(o) { return o.copy_id; } ) ); for (var i = 0; i < obj.selection_list.length; i++) { var barcode = obj.selection_list[i].barcode; - funcs.push( function(a) { return function() { obj.copy_status( a ); }; }(barcode) ); + funcs.push( function(a) { return function() { obj.copy_status( a, true ); }; }(barcode) ); } for (var i = 0; i < funcs.length; i++) { funcs[i](); } } @@ -283,6 +285,52 @@ circ.copy_status.prototype = { obj.copy_status(); } ], + 'cmd_copy_status_upload_file' : [ + ['command'], + function() { + function pick_file(mode) { + netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect UniversalBrowserWrite'); + var nsIFilePicker = Components.interfaces.nsIFilePicker; + var fp = Components.classes["@mozilla.org/filepicker;1"].createInstance( nsIFilePicker ); + fp.init( + window, + mode == 'open' ? "Import Barcode File" : "Save Barcode File As", + mode == 'open' ? nsIFilePicker.modeOpen : nsIFilePicker.modeSave + ); + fp.appendFilters( nsIFilePicker.filterAll ); + if ( fp.show( ) == nsIFilePicker.returnOK && fp.file ) { + return fp.file; + } else { + return null; + } + } + netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect UniversalBrowserWrite'); + JSAN.use('util.file'); + var f = pick_file('open'); + var i_file = new util.file(''); i_file._file = f; + var content = i_file.get_content(); + i_file.close(); + var barcodes = content.split(/\s+/); + if (barcodes.length > 0) { + JSAN.use('util.exec'); var exec = new util.exec(); + var funcs = []; + for (var i = 0; i < barcodes.length; i++) { + funcs.push( + function(b){ + return function() { + obj.copy_status(b); + } + }(barcodes[i]) + ); + } + funcs.push( function() { alert('File uploaded.'); } ); + exec.chain( funcs ); + } else { + alert('No barcodes found in file.'); + } + + } + ], 'cmd_copy_status_print' : [ ['command'], function() { @@ -894,7 +942,7 @@ circ.copy_status.prototype = { } }, - 'copy_status' : function(barcode) { + 'copy_status' : function(barcode,refresh) { var obj = this; try { try { document.getElementById('last_scanned').setAttribute('value',''); } catch(E) {} @@ -904,7 +952,7 @@ circ.copy_status.prototype = { if ( obj.test_barcode(barcode) ) { /* good */ } else { /* bad */ return; } } JSAN.use('circ.util'); - obj.network.simple_request('FM_ACP_DETAILS_VIA_BARCODE', [ ses(), barcode ], function(req) { + function handle_req(req) { try { var details = req.getResultObject(); if (details == null) { @@ -939,39 +987,55 @@ circ.copy_status.prototype = { var x = document.getElementById('trim_list'); if (x.checked) { obj.list.trim_list = 20; } else { obj.list.trim_list = null; } } - obj.list.append( - { - 'retrieve_id' : js2JSON( - { - 'renewable' : details.circ ? 't' : 'f', - 'copy_id' : details.copy.id(), - 'acn_id' : details.volume ? details.volume.id() : -1, - 'barcode' : barcode, - 'doc_id' : details.mvr ? details.mvr.doc_id() : null - } - ), - 'row' : { - 'my' : { - 'mvr' : details.mvr, - 'acp' : details.copy, - 'acn' : details.volume, - 'atc' : details.transit, - 'circ' : details.circ, - 'ahr' : details.hold, - } - }, - 'to_top' : true, + var params = { + 'retrieve_id' : js2JSON( + { + 'renewable' : details.circ ? 't' : 'f', + 'copy_id' : details.copy.id(), + 'acn_id' : details.volume ? details.volume.id() : -1, + 'barcode' : barcode, + 'doc_id' : details.mvr ? details.mvr.doc_id() : null + } + ), + 'row' : { + 'my' : { + 'mvr' : details.mvr, + 'acp' : details.copy, + 'acn' : details.volume, + 'atc' : details.transit, + 'circ' : details.circ, + 'ahr' : details.hold, + } + }, + 'to_top' : true, + }; + if (!refresh) { + var nparams = obj.list.append(params); + if (!document.getElementById('trim_list').checked) { + if (typeof obj.list_barcode_map[barcode] == 'undefined') obj.list_barcode_map[barcode] =[]; + obj.list_barcode_map[barcode].push(nparams); + } + } else { + if (!document.getElementById('trim_list').checked) { + for (var i = 0; i < obj.list_barcode_map[barcode].length; i++) { + params.my_node = obj.list_barcode_map[barcode][i].my_node; + obj.list.refresh_row(params); + } + } else { + obj.list.append(params); } - ); + } } catch(E) { - obj.error.standard_unexpected_error_alert('',E); + obj.error.standard_unexpected_error_alert('barcode = ' + barcode,E); } - } ); + } + var result = obj.network.simple_request('FM_ACP_DETAILS_VIA_BARCODE', [ ses(), barcode ]); + handle_req({'getResultObject':function(){return result;}}); // used to be async obj.controller.view.copy_status_barcode_entry_textbox.value = ''; obj.controller.view.copy_status_barcode_entry_textbox.focus(); } catch(E) { - obj.error.standard_unexpected_error_alert('',E); + obj.error.standard_unexpected_error_alert('barcode = ' + barcode,E); obj.controller.view.copy_status_barcode_entry_textbox.select(); obj.controller.view.copy_status_barcode_entry_textbox.focus(); } diff --git a/Open-ILS/xul/staff_client/server/circ/copy_status.xul b/Open-ILS/xul/staff_client/server/circ/copy_status.xul index c012f87868..436c0d6e04 100644 --- a/Open-ILS/xul/staff_client/server/circ/copy_status.xul +++ b/Open-ILS/xul/staff_client/server/circ/copy_status.xul @@ -93,6 +93,7 @@ + diff --git a/Open-ILS/xul/staff_client/server/circ/copy_status_overlay.xul b/Open-ILS/xul/staff_client/server/circ/copy_status_overlay.xul index 16460e70f9..ad406a9b61 100644 --- a/Open-ILS/xul/staff_client/server/circ/copy_status_overlay.xul +++ b/Open-ILS/xul/staff_client/server/circ/copy_status_overlay.xul @@ -98,7 +98,12 @@