From: phasefx Date: Sun, 22 Feb 2009 00:50:31 +0000 (+0000) Subject: backporting from staff-client-experiment: refactor standard list actions (the ones... X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=14c2ad2ddd7afb1e782c32542052d0f2cbc1c604;p=evergreen%2Ftadl.git backporting from staff-client-experiment: refactor standard list actions (the ones applicable to all lists) git-svn-id: svn://svn.open-ils.org/ILS/trunk@12245 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- diff --git a/Open-ILS/xul/staff_client/chrome/content/util/list.js b/Open-ILS/xul/staff_client/chrome/content/util/list.js index a1a14539f3..7629368dde 100644 --- a/Open-ILS/xul/staff_client/chrome/content/util/list.js +++ b/Open-ILS/xul/staff_client/chrome/content/util/list.js @@ -74,7 +74,7 @@ util.list.prototype = { } if (obj.row_count.total != obj.row_count.fleshed && (obj.row_count.total - obj.row_count.fleshed) > 50) { - var r = window.confirm('WARNING: Only ' + obj.row_count.fleshed + ' out of ' + obj.row_count.total + ' rows in this list have been retrieved for immediate viewing. Sorting this list requires that all these rows be retrieved, and this may take some time and lag the staff client. Would you like to proceed?'); + var r = window.confirm(document.getElementById('offlineStrings').getFormattedString('list.row_fetch_warning',[obj.row_count.fleshed,obj.row_count.total])); if (r) { setTimeout( do_it, 0 ); @@ -94,13 +94,20 @@ util.list.prototype = { this.node.appendChild(treechildren); this.treechildren = treechildren; } - if (typeof params.on_select == 'function') { - this.node.addEventListener( - 'select', - params.on_select, - false - ); - } + this.node.addEventListener( + 'select', + function(ev) { + if (typeof params.on_select == 'function') { + params.on_select(ev); + } + var x = document.getElementById(obj.node.id + '_clipfield'); + if (x) { + var sel = obj.retrieve_selection(); + x.setAttribute('disabled', sel.length == 0); + } + }, + false + ); if (typeof params.on_click == 'function') { this.node.addEventListener( 'click', @@ -203,7 +210,7 @@ util.list.prototype = { JSAN.use('util.file'); var file = new util.file('tree_columns_for_'+window.escape(id)); file.set_object(my_cols); file.close(); - alert('Columns saved.'); + alert(document.getElementById('offlineStrings').getString('list.columns_saved')); } catch(E) { obj.error.standard_unexpected_error_alert('_save_columns_tree',E); } @@ -658,7 +665,7 @@ util.list.prototype = { } */ for (var i = 0; i < obj.columns.length; i++) { - var treecell = document.createElement('treecell'); treecell.setAttribute('label','Retrieving...'); + var treecell = document.createElement('treecell'); treecell.setAttribute('label',document.getElementById('offlineStrings').getString('list.row_retrieving')); treerow.appendChild(treecell); } /* @@ -1105,14 +1112,14 @@ util.list.prototype = { if (params.no_full_retrieve) { params.data = obj.dump_csv( params ); params.not_json = true; - if (!params.title) params.title = 'Save List CSV As'; + if (!params.title) params.title = document.getElementById('offlineStrings').getString('list.save_csv_as'); f.export_file( params ); } else { obj.wrap_in_full_retrieve( function() { params.data = obj.dump_csv( params ); params.not_json = true; - if (!params.title) params.title = 'Save List CSV As'; + if (!params.title) params.title = document.getElementById('offlineStrings').getString('list.save_csv_as'); f.export_file( params ); } ); @@ -1188,7 +1195,7 @@ util.list.prototype = { return dump; }, - 'clipboard' : function() { + 'clipboard' : function(params) { try { var obj = this; var dump = obj.dump_selected_with_keys({'skip_hidden_columns':true,'labels_instead_of_ids':true}); @@ -1296,7 +1303,142 @@ util.list.prototype = { } catch(E) { obj.error.standard_unexpected_error_alert('pre sorting', E); } - } + }, + + 'render_list_actions' : function(params) { + var obj = this; + switch(this.node.nodeName) { + case 'tree' : return this._render_list_actions_for_tree(params); break; + default: throw('NYI: Need ._render_list_actions() for ' + this.node.nodeName); break; + } + }, + + '_render_list_actions_for_tree' : function(params) { + var obj = this; + try { + var btn = document.createElement('button'); + btn.setAttribute('id',obj.node.id + '_list_actions'); + btn.setAttribute('type','menu'); + btn.setAttribute('allowevents','true'); + //btn.setAttribute('oncommand','this.firstChild.showPopup();'); + btn.setAttribute('label',document.getElementById('offlineStrings').getString('list.actions.menu.label')); + btn.setAttribute('accesskey',document.getElementById('offlineStrings').getString('list.actions.menu.accesskey')); + var mp = document.createElement('menupopup'); + btn.appendChild(mp); + var mi = document.createElement('menuitem'); + mi.setAttribute('id',obj.node.id + '_clipfield'); + mi.setAttribute('disabled','true'); + mi.setAttribute('label',document.getElementById('offlineStrings').getString('list.actions.field_to_clipboard.label')); + mi.setAttribute('accesskey',document.getElementById('offlineStrings').getString('list.actions.field_to_clipboard.accesskey')); + mp.appendChild(mi); + mi = document.createElement('menuitem'); + mi.setAttribute('id',obj.node.id + '_csv_to_clipboard'); + mi.setAttribute('label',document.getElementById('offlineStrings').getString('list.actions.csv_to_clipboard.label')); + mi.setAttribute('accesskey',document.getElementById('offlineStrings').getString('list.actions.csv_to_clipboard.accesskey')); + mp.appendChild(mi); + mi = document.createElement('menuitem'); + mi.setAttribute('id',obj.node.id + '_csv_to_printer'); + mi.setAttribute('label',document.getElementById('offlineStrings').getString('list.actions.csv_to_printer.label')); + mi.setAttribute('accesskey',document.getElementById('offlineStrings').getString('list.actions.csv_to_printer.accesskey')); + mp.appendChild(mi); + mi = document.createElement('menuitem'); + mi.setAttribute('id',obj.node.id + '_csv_to_file'); + mi.setAttribute('label',document.getElementById('offlineStrings').getString('list.actions.csv_to_file.label')); + mi.setAttribute('accesskey',document.getElementById('offlineStrings').getString('list.actions.csv_to_file.accesskey')); + mp.appendChild(mi); + mi = document.createElement('menuitem'); + mi.setAttribute('id',obj.node.id + '_save_columns'); + mi.setAttribute('label',document.getElementById('offlineStrings').getString('list.actions.save_column_configuration.label')); + mi.setAttribute('accesskey',document.getElementById('offlineStrings').getString('list.actions.save_column_configuration.accesskey')); + mp.appendChild(mi); + return btn; + } catch(E) { + obj.error.standard_unexpected_error_alert('rendering list actions',E); + } + }, + + 'set_list_actions' : function(params) { + var obj = this; + switch(this.node.nodeName) { + case 'tree' : return this._set_list_actions_for_tree(params); break; + default: throw('NYI: Need ._set_list_actions() for ' + this.node.nodeName); break; + } + }, + + '_set_list_actions_for_tree' : function(params) { + // This should be called after the button element from render_list_actions has been appended to the DOM + var obj = this; + try { + var x = document.getElementById(obj.node.id + '_clipfield'); + if (x) { + x.addEventListener( + 'command', + function() { + obj.clipboard(params); + if (params && typeof params.on_complete == 'function') { + params.on_complete(params); + } + }, + false + ); + } + x = document.getElementById(obj.node.id + '_csv_to_clipboard'); + if (x) { + x.addEventListener( + 'command', + function() { + obj.dump_csv_to_clipboard(params); + if (params && typeof params.on_complete == 'function') { + params.on_complete(params); + } + }, + false + ); + } + x = document.getElementById(obj.node.id + '_csv_to_printer'); + if (x) { + x.addEventListener( + 'command', + function() { + obj.dump_csv_to_printer(params); + if (params && typeof params.on_complete == 'function') { + params.on_complete(params); + } + }, + false + ); + } + x = document.getElementById(obj.node.id + '_csv_to_file'); + if (x) { + x.addEventListener( + 'command', + function() { + obj.dump_csv_to_file(params); + if (params && typeof params.on_complete == 'function') { + params.on_complete(params); + } + }, + false + ); + } + x = document.getElementById(obj.node.id + '_save_columns'); + if (x) { + x.addEventListener( + 'command', + function() { + obj.save_columns(params); + if (params && typeof params.on_complete == 'function') { + params.on_complete(params); + } + }, + false + ); + } + + } catch(E) { + obj.error.standard_unexpected_error_alert('setting list actions',E); + } + } } dump('exiting util.list.js\n'); diff --git a/Open-ILS/xul/staff_client/chrome/locale/en-US/offline.properties b/Open-ILS/xul/staff_client/chrome/locale/en-US/offline.properties index 3fc2aad7f0..f72b3fb9c2 100644 --- a/Open-ILS/xul/staff_client/chrome/locale/en-US/offline.properties +++ b/Open-ILS/xul/staff_client/chrome/locale/en-US/offline.properties @@ -137,6 +137,7 @@ menu.close_all_tabs.error=Error closing all tabs menu.new_tab.tab=Tab main.session_cookie.error=Error setting session cookie: %1$s menu.set_tab.error=pause for error +menu.reset_network_stats=Reset network activity summary? main.testing=Testing main.transaction_export.title=Save Transaction File As main.transaction_export.prompt=Would you like to overwrite the existing file %1$s? @@ -187,4 +188,19 @@ openils.global_util.clipboard=Copied "%1$s" to clipboard. openils.global_util.content_window_jsobject.error=Error with get_contentWindow(%1$s) and wrappedJSObject: %2$s openils.global_util.content_window.error=Error with get_contentWindow(%1$s): %2$s openils.global_util.font_size.error=Error adjusting the font size: %1$s - +list.row_fetch_warning=WARNING: Only %1$s out of %2$s rows in this list have been retrieved for immediate viewing. Sorting this list requires that all these rows be retrieved, and this may take some time and lag the staff client. Would you like to proceed? +list.columns_saved=Column configuration saved. +list.row_retrieving=Retrieving... +list.save_csv_as=Save List CSV As... +list.actions.menu.label=List Actions +list.actions.menu.accesskey=L +list.actions.field_to_clipboard.label=Copy Field from Selected Row to Clipboard +list.actions.field_to_clipboard.accesskey=C +list.actions.csv_to_clipboard.label=Copy List CSV to Clipboard +list.actions.csv_to_clipboard.accesskey=L +list.actions.csv_to_printer.label=Print List CSV +list.actions.csv_to_printer.accesskey=P +list.actions.csv_to_file.label=Save List CSV to File +list.actions.csv_to_file.accesskey=F +list.actions.save_column_configuration.label=Save Column Configuration +list.actions.save_column_configuration.accesskey=S 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 373c840b8b..df99a443de 100644 --- a/Open-ILS/xul/staff_client/server/cat/copy_buckets.js +++ b/Open-ILS/xul/staff_client/server/cat/copy_buckets.js @@ -14,6 +14,7 @@ cat.copy_buckets.prototype = { 'selection_list1' : [], 'selection_list2' : [], 'bucket_id_name_map' : {}, + 'copy_hash' : {}, 'render_pending_copies' : function() { var obj = this; @@ -47,24 +48,27 @@ cat.copy_buckets.prototype = { function retrieve_row(params) { var row = params.row; try { - obj.network.simple_request('FM_ACP_DETAILS', [ ses(), row.my.copy_id ], - function(blob_req) { - try { - var blob = blob_req.getResultObject(); - if (typeof blob.ilsevent != 'undefined') throw(blob); - row.my.acp = blob.copy; - row.my.mvr = blob.mvr; - row.my.acn = blob.volume; - row.my.ahr = blob.hold; - row.my.circ = blob.circ; - params.row_node.setAttribute('retrieve_id', js2JSON( [ blob.copy.id(), blob.copy.barcode(), row.my.bucket_item_id ] )); - if (typeof params.on_retrieve == 'function') { params.on_retrieve(row); } - - } catch(E) { - obj.error.standard_unexpected_error_alert($('catStrings').getFormattedString('staff.cat.copy_buckets.retrieve_row.error', [row.my.acp_id]), E); - } + function handle_details(blob_req) { + try { + var blob = blob_req.getResultObject(); + if (typeof blob.ilsevent != 'undefined') throw(blob); + row.my.acp = blob.copy; + row.my.mvr = blob.mvr; + row.my.acn = blob.volume; + row.my.ahr = blob.hold; + row.my.circ = blob.circ; + params.row_node.setAttribute('retrieve_id', js2JSON( [ blob.copy.id(), blob.copy.barcode(), row.my.bucket_item_id ] )); + if (typeof params.on_retrieve == 'function') { params.on_retrieve(row); } + + } catch(E) { + obj.error.standard_unexpected_error_alert($('catStrings').getFormattedString('staff.cat.copy_buckets.retrieve_row.error', [row.my.acp_id]), E); } - ); + } + if (obj.copy_hash[ row.my.copy_id ]) { + handle_details( { 'getResultObject' : function() { var copy_obj = obj.copy_hash[ row.my.copy_id ]; delete obj.copy_hash[ row.my.copy_id ]; return copy_obj; } } ); + } else { + obj.network.simple_request( 'FM_ACP_DETAILS', [ ses(), row.my.copy_id ], handle_details ); + } } catch(E) { obj.error.sdump('D_ERROR','retrieve_row: ' + E ); } @@ -81,7 +85,6 @@ cat.copy_buckets.prototype = { try { JSAN.use('util.functional'); var sel = obj.list1.retrieve_selection(); - document.getElementById('clip_button1').disabled = sel.length < 1; obj.selection_list1 = util.functional.map_list( sel, function(o) { return JSON2js(o.getAttribute('retrieve_id')); } @@ -112,7 +115,6 @@ cat.copy_buckets.prototype = { try { JSAN.use('util.functional'); var sel = obj.list2.retrieve_selection(); - document.getElementById('clip_button2').disabled = sel.length < 1; obj.selection_list2 = util.functional.map_list( sel, function(o) { return JSON2js(o.getAttribute('retrieve_id')); } @@ -140,22 +142,46 @@ cat.copy_buckets.prototype = { obj.controller.init( { 'control_map' : { - 'save_columns2' : [ - ['command'], - function() { obj.list2.save_columns(); } - ], - 'save_columns1' : [ - ['command'], - function() { obj.list1.save_columns(); } - ], - 'sel_clip2' : [ - ['command'], - function() { obj.list2.clipboard(); } - ], - 'sel_clip1' : [ - ['command'], - function() { obj.list1.clipboard(); } + 'list_actions1' : [ + ['render'], + function(e) { + return function() { + e.appendChild( obj.list1.render_list_actions() ); + obj.list1.set_list_actions( + { + 'on_complete' : function() { } + } + ); + }; + } + ], + 'list_actions2' : [ + ['render'], + function(e) { + return function() { + e.appendChild( obj.list2.render_list_actions() ); + obj.list2.set_list_actions( + { + 'on_complete' : function() { } + } + ); + }; + } + ], + 'copy_bucket_barcode_entry_textbox' : [ + ['keypress'], + function(ev) { + if (ev.keyCode && ev.keyCode == 13) { + obj.scan_barcode(); + } + } ], + 'cmd_copy_bucket_submit_barcode' : [ + ['command'], + function() { + obj.scan_barcode(); + } + ], 'copy_buckets_menulist_placeholder' : [ ['render'], function(e) { @@ -253,27 +279,31 @@ cat.copy_buckets.prototype = { 'copy_buckets_add' : [ ['command'], function() { - var bucket_id = obj.controller.view.bucket_menulist.value; - if (!bucket_id) return; - for (var i = 0; i < obj.copy_ids.length; i++) { - var bucket_item = new ccbi(); - bucket_item.isnew('1'); - bucket_item.bucket(bucket_id); - bucket_item.target_copy( obj.copy_ids[i] ); - try { - var robj = obj.network.simple_request('BUCKET_ITEM_CREATE', - [ ses(), 'copy', bucket_item ]); - - if (typeof robj == 'object') throw robj; - - var item = obj.prep_item_for_list( obj.copy_ids[i], robj ); - if (!item) continue; - - obj.list2.append( item ); - } catch(E) { - obj.error.standard_unexpected_error_alert($('catStrings').getString('staff.cat.copy_buckets.copy_buckets_add.error'), E); - } - } + try { + var bucket_id = obj.controller.view.bucket_menulist.value; + if (!bucket_id) return; + for (var i = 0; i < obj.copy_ids.length; i++) { + var bucket_item = new ccbi(); + bucket_item.isnew('1'); + bucket_item.bucket(bucket_id); + bucket_item.target_copy( obj.copy_ids[i] ); + try { + var robj = obj.network.simple_request('BUCKET_ITEM_CREATE', + [ ses(), 'copy', bucket_item ]); + + if (typeof robj == 'object') throw robj; + + var item = obj.prep_item_for_list( obj.copy_ids[i], robj ); + if (!item) continue; + + obj.list2.append( item ); + } catch(E) { + obj.error.standard_unexpected_error_alert($('catStrings').getString('staff.cat.copy_buckets.copy_buckets_add.error'), E); + } + } + } catch(E) { + alert(E); + } } ], 'copy_buckets_sel_add' : [ @@ -580,71 +610,11 @@ cat.copy_buckets.prototype = { obj.list2.dump_csv_to_clipboard(); } ], - 'cmd_export1' : [ - ['command'], - function() { - obj.list1.dump_csv_to_clipboard(); - } - ], - - 'cmd_print_export1' : [ - ['command'], - function() { - try { - obj.list1.on_all_fleshed = - function() { - try { - dump( obj.list1.dump_csv() + '\n' ); - //copy_to_clipboard(obj.list.dump_csv()); - JSAN.use('util.print'); var print = new util.print(); - print.simple(obj.list1.dump_csv(),{'content_type':'text/plain'}); - setTimeout(function(){ obj.list1.on_all_fleshed = null; },0); - } catch(E) { - obj.error.standard_unexpected_error_alert('print export',E); - } - } - obj.list1.full_retrieve(); - } catch(E) { - obj.error.standard_unexpected_error_alert('print export',E); - } - } - ], - - - 'cmd_print_export2' : [ - ['command'], - function() { - try { - obj.list2.on_all_fleshed = - function() { - try { - dump( obj.list2.dump_csv() + '\n' ); - //copy_to_clipboard(obj.list.dump_csv()); - JSAN.use('util.print'); var print = new util.print(); - print.simple(obj.list2.dump_csv(),{'content_type':'text/plain'}); - setTimeout(function(){ obj.list2.on_all_fleshed = null; },0); - } catch(E) { - obj.error.standard_unexpected_error_alert('print export',E); - } - } - obj.list2.full_retrieve(); - } catch(E) { - obj.error.standard_unexpected_error_alert('print export',E); - } - } - ], - 'cmd_copy_buckets_reprint' : [ ['command'], function() { } ], - 'cmd_copy_buckets_done' : [ - ['command'], - function() { - window.close(); - } - ], 'cmd_export_to_copy_status' : [ ['command'], function() { @@ -678,9 +648,6 @@ cat.copy_buckets.prototype = { if (typeof xulG == 'undefined') { obj.controller.view.cmd_export_to_copy_status.disabled = true; obj.controller.view.cmd_export_to_copy_status.setAttribute('disabled',true); - } else { - obj.controller.view.cmd_copy_buckets_done.disabled = true; - obj.controller.view.cmd_copy_buckets_done.setAttribute('disabled',true); } }, @@ -705,7 +672,54 @@ cat.copy_buckets.prototype = { } }, - + + 'scan_barcode' : function() { + var obj = this; + try { + var barcode = obj.controller.view.copy_bucket_barcode_entry_textbox.value; + var copy_obj = obj.network.simple_request('FM_ACP_DETAILS_VIA_BARCODE',[ses(),barcode]); + if (copy_obj == null) { + throw(document.getElementById('circStrings').getString('staff.circ.copy_status.status.null_result')); + } else if (copy_obj.ilsevent) { + switch(Number(copy_obj.ilsevent)) { + case -1: + obj.error.standard_network_error_alert(); + obj.controller.view.copy_bucket_barcode_entry_textbox.select(); + obj.controller.view.copy_bucket_barcode_entry_textbox.focus(); + return; + break; + case 1502 /* ASSET_COPY_NOT_FOUND */ : + obj.error.yns_alert( + document.getElementById('circStrings').getFormattedString('staff.circ.copy_status.status.copy_not_found', [barcode]), + document.getElementById('circStrings').getString('staff.circ.copy_status.status.not_cataloged'), + document.getElementById('circStrings').getString('staff.circ.copy_status.ok'), + null, + null, + document.getElementById('circStrings').getString('staff.circ.confirm.msg') + ); + obj.controller.view.copy_bucket_barcode_entry_textbox.select(); + obj.controller.view.copy_bucket_barcode_entry_textbox.focus(); + return; + break; + default: + throw(details); + break; + } + } + var item = obj.prep_item_for_list( copy_obj.copy.id() ); + if (item) { + obj.copy_ids.push( copy_obj.copy.id() ); + obj.copy_hash[ copy_obj.copy.id() ] = copy_obj; + obj.list1.append( item ); + } + obj.controller.view.copy_bucket_barcode_entry_textbox.value = ''; + obj.controller.view.copy_bucket_barcode_entry_textbox.focus(); + } catch(E) { + obj.controller.view.copy_bucket_barcode_entry_textbox.select(); + obj.controller.view.copy_bucket_barcode_entry_textbox.focus(); + alert(E); + } + } } dump('exiting cat.copy_buckets.js\n'); diff --git a/Open-ILS/xul/staff_client/server/cat/copy_buckets.xul b/Open-ILS/xul/staff_client/server/cat/copy_buckets.xul index a5c3cb0c7b..a73453dee3 100644 --- a/Open-ILS/xul/staff_client/server/cat/copy_buckets.xul +++ b/Open-ILS/xul/staff_client/server/cat/copy_buckets.xul @@ -70,6 +70,7 @@ } } + function default_focus() { try { setTimeout( function() { document.getElementById('copy_bucket_barcode_entry_textbox').focus(); }, 0); } catch(E) {} } ]]> @@ -77,18 +78,7 @@ - - - - - - - - - - - - + diff --git a/Open-ILS/xul/staff_client/server/cat/copy_buckets_overlay.xul b/Open-ILS/xul/staff_client/server/cat/copy_buckets_overlay.xul index 6c3e06291e..1c357d016b 100644 --- a/Open-ILS/xul/staff_client/server/cat/copy_buckets_overlay.xul +++ b/Open-ILS/xul/staff_client/server/cat/copy_buckets_overlay.xul @@ -30,11 +30,20 @@ + +