1 dump('entering cat.copy_buckets.js\n');
3 if (typeof cat == 'undefined') cat = {};
4 cat.copy_buckets = function (params) {
6 JSAN.use('util.error'); this.error = new util.error();
7 JSAN.use('util.network'); this.network = new util.network();
9 JSAN.use('OpenILS.data'); this.data = new OpenILS.data(); this.data.init({'via':'stash'});
10 this.first_pause = true;
13 cat.copy_buckets.prototype = {
14 'selection_list1' : [],
15 'selection_list2' : [],
16 'bucket_id_name_map' : {},
18 'render_pending_copies' : function() {
19 if (this.first_pause) {
20 this.first_pause = false;
22 alert("Action completed.");
26 for (var i = 0; i < obj.copy_ids.length; i++) {
27 var item = obj.flesh_item_for_list( obj.copy_ids[i] );
28 if (item) obj.list1.append( item );
32 'init' : function( params ) {
36 obj.copy_ids = params['copy_ids'] || [];
38 JSAN.use('circ.util');
39 var columns = circ.util.columns(
41 'barcode' : { 'hidden' : false },
42 'title' : { 'hidden' : false },
43 'location' : { 'hidden' : false },
44 'call_number' : { 'hidden' : false },
45 'status' : { 'hidden' : false },
46 'deleted' : { 'hidden' : false },
50 JSAN.use('util.list');
52 obj.list1 = new util.list('pending_copies_list');
56 'map_row_to_columns' : circ.util.std_map_row_to_columns(),
57 'on_select' : function(ev) {
59 JSAN.use('util.functional');
60 var sel = obj.list1.retrieve_selection();
61 document.getElementById('clip_button1').disabled = sel.length < 1;
62 obj.selection_list1 = util.functional.map_list(
64 function(o) { return JSON2js(o.getAttribute('retrieve_id')); }
66 obj.error.sdump('D_TRACE','circ/copy_buckets: selection list 1 = ' + js2JSON(obj.selection_list1) );
67 if (obj.selection_list1.length == 0) {
68 obj.controller.view.copy_buckets_sel_add.disabled = true;
70 obj.controller.view.copy_buckets_sel_add.disabled = false;
80 obj.render_pending_copies();
82 obj.list2 = new util.list('copies_in_bucket_list');
86 'map_row_to_columns' : circ.util.std_map_row_to_columns(),
87 'on_select' : function(ev) {
89 JSAN.use('util.functional');
90 var sel = obj.list2.retrieve_selection();
91 document.getElementById('clip_button2').disabled = sel.length < 1;
92 obj.selection_list2 = util.functional.map_list(
94 function(o) { return JSON2js(o.getAttribute('retrieve_id')); }
96 obj.error.sdump('D_TRACE','circ/copy_buckets: selection list 2 = ' + js2JSON(obj.selection_list2) );
97 if (obj.selection_list2.length == 0) {
98 obj.controller.view.copy_buckets_delete_item.disabled = true;
99 obj.controller.view.copy_buckets_delete_item.setAttribute('disabled','true');
100 obj.controller.view.copy_buckets_export.disabled = true;
101 obj.controller.view.copy_buckets_export.setAttribute('disabled','true');
103 obj.controller.view.copy_buckets_delete_item.disabled = false;
104 obj.controller.view.copy_buckets_delete_item.setAttribute('disabled','false');
105 obj.controller.view.copy_buckets_export.disabled = false;
106 obj.controller.view.copy_buckets_export.setAttribute('disabled','false');
109 alert('FIXME: ' + E);
115 JSAN.use('util.controller'); obj.controller = new util.controller();
121 function() { obj.list2.save_columns(); }
125 function() { obj.list1.save_columns(); }
129 function() { obj.list2.clipboard(); }
133 function() { obj.list1.clipboard(); }
135 'copy_buckets_menulist_placeholder' : [
139 JSAN.use('util.widgets'); JSAN.use('util.functional');
140 var items = [ ['Choose a bucket...',''], ['Retrieve shared bucket...',-1] ].concat(
141 util.functional.map_list(
142 obj.network.simple_request(
143 'BUCKET_RETRIEVE_VIA_USER',
144 [ ses(), obj.data.list.au[0].id() ]
147 obj.bucket_id_name_map[ o.id() ] = o.name();
148 return [ o.name(), o.id() ];
152 if (a[0] < b[0]) return -1;
153 if (a[0] > b[0]) return 1;
158 obj.error.sdump('D_TRACE','items = ' + js2JSON(items));
159 util.widgets.remove_children( e );
160 var ml = util.widgets.make_menulist(
164 ml.setAttribute('id','bucket_menulist');
165 ml.setAttribute('accesskey','');
167 function change_bucket(ev) {
168 var bucket_id = ev.target.value;
169 if (bucket_id < 0 ) {
170 bucket_id = window.prompt('Enter bucket number:');
171 ev.target.value = bucket_id;
172 ev.target.setAttribute('value',bucket_id);
174 if (!bucket_id) return;
175 var bucket = obj.network.simple_request(
177 [ ses(), 'copy', bucket_id ]
179 if (typeof bucket.ilsevent != 'undefined') {
180 if (bucket.ilsevent == 1506 /* CONTAINER_NOT_FOUND */) {
181 alert('Could not find a bucket with ID = ' + bucket_id);
183 obj.error.standard_unexpected_error_alert('Error retrieving bucket. Did you use a valid bucket id?',bucket);
188 var x = document.getElementById('info_box');
189 x.setAttribute('hidden','false');
190 x = document.getElementById('bucket_number');
191 x.setAttribute('value',bucket.id());
192 x = document.getElementById('bucket_name');
193 x.setAttribute('value',bucket.name());
194 x = document.getElementById('bucket_owner');
195 var s = bucket.owner(); JSAN.use('patron.util');
196 if (s && typeof s != "object") s = patron.util.retrieve_fleshed_au_via_id(ses(),s);
197 x.setAttribute('value',s.card().barcode() + " @ " + obj.data.hash.aou[ s.home_ou() ].shortname());
202 var items = bucket.items() || [];
204 for (var i = 0; i < items.length; i++) {
205 var item = obj.flesh_item_for_list(
206 items[i].target_copy(),
209 if (item) obj.list2.append( item );
213 ml.addEventListener( 'change_bucket', change_bucket , false);
214 ml.addEventListener( 'command', function() {
215 JSAN.use('util.widgets'); util.widgets.dispatch('change_bucket',ml);
217 obj.controller.view.bucket_menulist = ml;
218 JSAN.use('util.widgets'); util.widgets.dispatch('change_bucket',ml);
219 document.getElementById('refresh').addEventListener( 'command', function() {
220 JSAN.use('util.widgets'); util.widgets.dispatch('change_bucket',ml);
226 'copy_buckets_add' : [
229 var bucket_id = obj.controller.view.bucket_menulist.value;
230 if (!bucket_id) return;
231 for (var i = 0; i < obj.copy_ids.length; i++) {
232 var bucket_item = new ccbi();
233 bucket_item.isnew('1');
234 bucket_item.bucket(bucket_id);
235 bucket_item.target_copy( obj.copy_ids[i] );
237 var robj = obj.network.simple_request('BUCKET_ITEM_CREATE',
238 [ ses(), 'copy', bucket_item ]);
240 if (typeof robj == 'object') throw robj;
242 var item = obj.flesh_item_for_list( obj.copy_ids[i], robj );
245 obj.list2.append( item );
247 obj.error.standard_unexpected_error_alert('Addition likely failed.',E);
252 'copy_buckets_sel_add' : [
255 var bucket_id = obj.controller.view.bucket_menulist.value;
256 if (!bucket_id) return;
257 for (var i = 0; i < obj.selection_list1.length; i++) {
258 var acp_id = obj.selection_list1[i][0];
259 //var barcode = obj.selection_list1[i][1];
260 var bucket_item = new ccbi();
261 bucket_item.isnew('1');
262 bucket_item.bucket(bucket_id);
263 bucket_item.target_copy( acp_id );
265 var robj = obj.network.simple_request('BUCKET_ITEM_CREATE',
266 [ ses(), 'copy', bucket_item ]);
268 if (typeof robj == 'object') throw robj;
270 var item = obj.flesh_item_for_list( acp_id, robj );
273 obj.list2.append( item );
275 obj.error.standard_unexpected_error_alert('Deletion likely failed.',E);
281 'copy_buckets_export' : [
284 for (var i = 0; i < obj.selection_list2.length; i++) {
285 var acp_id = obj.selection_list2[i][0];
286 //var barcode = obj.selection_list1[i][1];
287 //var bucket_item_id = obj.selection_list1[i][2];
288 var item = obj.flesh_item_for_list( acp_id );
290 obj.list1.append( item );
291 obj.copy_ids.push( acp_id );
297 'copy_buckets_delete_item' : [
300 for (var i = 0; i < obj.selection_list2.length; i++) {
302 //var acp_id = obj.selection_list2[i][0];
303 //var barcode = obj.selection_list2[i][1];
304 var bucket_item_id = obj.selection_list2[i][2];
305 var robj = obj.network.simple_request('BUCKET_ITEM_DELETE',
306 [ ses(), 'copy', bucket_item_id ]);
307 if (typeof robj == 'object') throw robj;
309 obj.error.standard_unexpected_error_alert('Deletion likely failed.',E);
312 alert("Action completed.");
315 JSAN.use('util.widgets');
316 util.widgets.dispatch('change_bucket',obj.controller.view.bucket_menulist);
321 'copy_buckets_delete_bucket' : [
325 var bucket = obj.controller.view.bucket_menulist.value;
326 var name = obj.bucket_id_name_map[ bucket ];
327 var conf = window.confirm('Delete the bucket named ' + name + '?');
330 var robj = obj.network.simple_request('BUCKET_DELETE',[ses(),'copy',bucket]);
331 if (typeof robj == 'object') throw robj;
332 alert("Action completed.");
333 obj.controller.render('copy_buckets_menulist_placeholder');
335 obj.error.standard_unexpected_error_alert('Bucket deletion likely failed.',E);
339 'copy_buckets_new_bucket' : [
343 var name = prompt('What would you like to name the bucket?','','Bucket Creation');
346 var bucket = new ccb();
347 bucket.btype('staff_client');
348 bucket.owner( obj.data.list.au[0].id() );
351 var robj = obj.network.simple_request('BUCKET_CREATE',[ses(),'copy',bucket]);
353 if (typeof robj == 'object') {
354 if (robj.ilsevent == 1710 /* CONTAINER_EXISTS */) {
355 alert('You already have a bucket with that name.');
361 alert('Bucket "' + name + '" created.');
363 obj.controller.render('copy_buckets_menulist_placeholder');
364 obj.controller.view.bucket_menulist.value = robj;
367 JSAN.use('util.widgets');
368 util.widgets.dispatch('change_bucket',obj.controller.view.bucket_menulist);
373 obj.error.standard_unexpected_error_alert('Bucket creation failed.',E);
377 'copy_buckets_batch_copy_edit' : [
382 obj.list2.select_all();
384 JSAN.use('util.widgets'); JSAN.use('util.functional');
386 var list = util.functional.map_list(
387 obj.list2.dump_retrieve_ids(),
389 return JSON2js(o)[0]; // acp_id
393 JSAN.use('cat.util'); cat.util.spawn_copy_editor( { 'copy_ids' : list, 'edit' : 1 } );
395 obj.render_pending_copies(); // FIXME -- need a generic refresh for lists
398 util.widgets.dispatch('change_bucket',obj.controller.view.bucket_menulist);
406 'copy_buckets_batch_copy_delete' : [
411 obj.list2.select_all();
413 JSAN.use('util.widgets'); JSAN.use('util.functional');
415 var list = util.functional.map_list(
416 obj.list2.dump_retrieve_ids(),
418 return JSON2js(o)[0]; // acp_id
422 var copies = util.functional.map_list(
425 return obj.network.simple_request('FM_ACP_RETRIEVE',[acp_id]);
429 for (var i = 0; i < copies.length; i++) {
430 copies[i].ischanged(1);
431 copies[i].isdeleted(1);
434 var robj = obj.network.simple_request('FM_ACP_FLESHED_BATCH_UPDATE',[ ses(), copies, true]);
435 if (typeof robj.ilsevent != 'undefined') {
436 switch(robj.ilsevent) {
437 case 1227 /* COPY_DELETE_WARNING */ :
439 for (var i = 0; i < copies.length; i++) { if (copies[i].id()==robj.payload) copy = function(a){return a;}(copies[i]); }
440 /* The copy in question is not in an ideal status for deleting */
441 var err = '*** ' + robj.desc + ' ***\n';
442 /* The barcode for the item is {1} */
443 err += $('catStrings').getFormattedString('cat.barcode_for_item',[ copy.barcode() ]) + '\n';
444 /* The whole batch operation failed */
445 err += $('catStrings').getString('cat.batch_operation_failed') + '\n';
448 default: obj.error.standard_unexpected_error_alert('Batch Item Deletion',robj);
452 obj.render_pending_copies(); // FIXME -- need a generic refresh for lists
455 JSAN.use('util.widgets');
456 util.widgets.dispatch('change_bucket',obj.controller.view.bucket_menulist);
465 'copy_buckets_transfer_to_volume' : [
469 obj.list2.select_all();
471 obj.data.stash_retrieve();
472 if (!obj.data.marked_volume) {
473 alert('Please mark a volume as the destination from within the copy browser and then try this again.');
477 var copy_ids = util.functional.map_list(
478 obj.list2.dump_retrieve_ids(),
480 return JSON2js(o)[0]; // acp_id
484 var volume = obj.network.simple_request('FM_ACN_RETRIEVE',[ obj.data.marked_volume ]);
486 var msg = 'Transfer the items in bucket "';
487 msg += obj.controller.view.bucket_menulist.getAttribute('label') + '" ';
488 msg += 'from their original volumes to ';
489 msg += obj.data.hash.aou[ volume.owning_lib() ].shortname() + "'s volume labelled ";
490 msg += '"' + volume.label() + '" on the following record?';
492 JSAN.use('cat.util'); cat.util.transfer_copies( {
493 'copy_ids' : copy_ids,
495 'docid' : volume.record(),
496 'volume_label' : volume.label(),
497 'owning_lib' : volume.owning_lib(),
500 obj.render_pending_copies(); // FIXME -- need a generic refresh for lists
503 JSAN.use('util.widgets');
504 util.widgets.dispatch('change_bucket',obj.controller.view.bucket_menulist);
509 obj.error.standard_unexpected_error_alert('Items not likely transferred.',E);
515 function() { alert('Not Yet Implemented'); }
517 'cmd_copy_buckets_print' : [
520 JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.init({'via':'stash'});
521 obj.list2.on_all_fleshed = function() {
523 dump( js2JSON( obj.list2.dump_with_keys() ) + '\n' );
524 data.stash_retrieve();
525 var lib = data.hash.aou[ data.list.au[0].ws_ou() ];
529 'staff' : data.list.au[0],
530 'header' : data.print_list_templates.item_status.header,
531 'line_item' : data.print_list_templates.item_status.line_item,
532 'footer' : data.print_list_templates.item_status.footer,
533 'type' : data.print_list_templates.item_status.type,
534 'list' : obj.list2.dump_with_keys(),
536 JSAN.use('util.print'); var print = new util.print();
537 print.tree_list( p );
538 setTimeout(function(){obj.list2.on_all_fleshed = null;},0);
543 obj.list2.full_retrieve();
546 'cmd_copy_buckets_export' : [
549 obj.list2.dump_csv_to_clipboard();
555 obj.list1.dump_csv_to_clipboard();
559 'cmd_print_export1' : [
563 obj.list1.on_all_fleshed =
566 dump( obj.list1.dump_csv() + '\n' );
567 //copy_to_clipboard(obj.list.dump_csv());
568 JSAN.use('util.print'); var print = new util.print();
569 print.simple(obj.list1.dump_csv(),{'content_type':'text/plain'});
570 setTimeout(function(){ obj.list1.on_all_fleshed = null; },0);
572 obj.error.standard_unexpected_error_alert('print export',E);
575 obj.list1.full_retrieve();
577 obj.error.standard_unexpected_error_alert('print export',E);
583 'cmd_print_export2' : [
587 obj.list2.on_all_fleshed =
590 dump( obj.list2.dump_csv() + '\n' );
591 //copy_to_clipboard(obj.list.dump_csv());
592 JSAN.use('util.print'); var print = new util.print();
593 print.simple(obj.list2.dump_csv(),{'content_type':'text/plain'});
594 setTimeout(function(){ obj.list2.on_all_fleshed = null; },0);
596 obj.error.standard_unexpected_error_alert('print export',E);
599 obj.list2.full_retrieve();
601 obj.error.standard_unexpected_error_alert('print export',E);
606 'cmd_copy_buckets_reprint' : [
611 'cmd_copy_buckets_done' : [
617 'cmd_export_to_copy_status' : [
621 obj.list2.select_all();
622 JSAN.use('util.functional');
623 var barcodes = util.functional.map_list(
624 obj.list2.dump_retrieve_ids(),
625 function(o) { return JSON2js(o)[1]; }
627 var url = urls.XUL_COPY_STATUS; // + '?barcodes=' + window.escape( js2JSON(barcodes) );
628 //JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.stash_retrieve();
629 //data.temp_barcodes_for_copy_status = barcodes;
630 //data.stash('temp_barcodes_for_copy_status');
631 xulG.new_tab( url, {}, { 'barcodes' : barcodes });
633 obj.error.standard_unexpected_error_alert('Copy Status from Copy Buckets',E);
640 this.controller.render();
642 if (typeof xulG == 'undefined') {
643 obj.controller.view.cmd_export_to_copy_status.disabled = true;
644 obj.controller.view.cmd_export_to_copy_status.setAttribute('disabled',true);
646 obj.controller.view.cmd_copy_buckets_done.disabled = true;
647 obj.controller.view.cmd_copy_buckets_done.setAttribute('disabled',true);
652 'flesh_item_for_list' : function(acp_id,bucket_item_id) {
655 var copy = obj.network.simple_request( 'FM_ACP_RETRIEVE', [ acp_id ]);
656 if (copy == null || typeof copy.ilsevent != 'undefined') {
660 'retrieve_id' : js2JSON( [ copy.id(), copy.barcode(), bucket_item_id ] ),
663 'mvr' : obj.network.simple_request('MODS_SLIM_RECORD_RETRIEVE_VIA_COPY', [ copy.id() ]),
671 obj.error.standard_unexpected_error_alert('List building failed.',E);
679 dump('exiting cat.copy_buckets.js\n');