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 obj.error.sdump('D_TRACE','items = ' + js2JSON(items));
153 util.widgets.remove_children( e );
154 var ml = util.widgets.make_menulist(
158 ml.setAttribute('id','bucket_menulist');
159 ml.setAttribute('accesskey','');
161 function change_bucket(ev) {
162 var bucket_id = ev.target.value;
163 if (bucket_id < 0 ) {
164 bucket_id = window.prompt('Enter bucket number:');
165 ev.target.value = bucket_id;
166 ev.target.setAttribute('value',bucket_id);
168 if (!bucket_id) return;
169 var bucket = obj.network.simple_request(
171 [ ses(), 'copy', bucket_id ]
173 if (typeof bucket.ilsevent != 'undefined') {
174 if (bucket.ilsevent == 1506 /* CONTAINER_NOT_FOUND */) {
175 alert('Could not find a bucket with ID = ' + bucket_id);
177 obj.error.standard_unexpected_error_alert('Error retrieving bucket. Did you use a valid bucket id?',bucket);
182 var x = document.getElementById('info_box');
183 x.setAttribute('hidden','false');
184 x = document.getElementById('bucket_number');
185 x.setAttribute('value',bucket.id());
186 x = document.getElementById('bucket_name');
187 x.setAttribute('value',bucket.name());
188 x = document.getElementById('bucket_owner');
189 var s = bucket.owner(); JSAN.use('patron.util');
190 if (s && typeof s != "object") s = patron.util.retrieve_fleshed_au_via_id(ses(),s);
191 x.setAttribute('value',s.card().barcode() + " @ " + obj.data.hash.aou[ s.home_ou() ].shortname());
196 var items = bucket.items() || [];
198 for (var i = 0; i < items.length; i++) {
199 var item = obj.flesh_item_for_list(
200 items[i].target_copy(),
203 if (item) obj.list2.append( item );
207 ml.addEventListener( 'change_bucket', change_bucket , false);
208 ml.addEventListener( 'command', function() {
209 JSAN.use('util.widgets'); util.widgets.dispatch('change_bucket',ml);
211 obj.controller.view.bucket_menulist = ml;
212 JSAN.use('util.widgets'); util.widgets.dispatch('change_bucket',ml);
213 document.getElementById('refresh').addEventListener( 'command', function() {
214 JSAN.use('util.widgets'); util.widgets.dispatch('change_bucket',ml);
220 'copy_buckets_add' : [
223 var bucket_id = obj.controller.view.bucket_menulist.value;
224 if (!bucket_id) return;
225 for (var i = 0; i < obj.copy_ids.length; i++) {
226 var bucket_item = new ccbi();
227 bucket_item.isnew('1');
228 bucket_item.bucket(bucket_id);
229 bucket_item.target_copy( obj.copy_ids[i] );
231 var robj = obj.network.simple_request('BUCKET_ITEM_CREATE',
232 [ ses(), 'copy', bucket_item ]);
234 if (typeof robj == 'object') throw robj;
236 var item = obj.flesh_item_for_list( obj.copy_ids[i], robj );
239 obj.list2.append( item );
241 obj.error.standard_unexpected_error_alert('Addition likely failed.',E);
246 'copy_buckets_sel_add' : [
249 var bucket_id = obj.controller.view.bucket_menulist.value;
250 if (!bucket_id) return;
251 for (var i = 0; i < obj.selection_list1.length; i++) {
252 var acp_id = obj.selection_list1[i][0];
253 //var barcode = obj.selection_list1[i][1];
254 var bucket_item = new ccbi();
255 bucket_item.isnew('1');
256 bucket_item.bucket(bucket_id);
257 bucket_item.target_copy( acp_id );
259 var robj = obj.network.simple_request('BUCKET_ITEM_CREATE',
260 [ ses(), 'copy', bucket_item ]);
262 if (typeof robj == 'object') throw robj;
264 var item = obj.flesh_item_for_list( acp_id, robj );
267 obj.list2.append( item );
269 obj.error.standard_unexpected_error_alert('Deletion likely failed.',E);
275 'copy_buckets_export' : [
278 for (var i = 0; i < obj.selection_list2.length; i++) {
279 var acp_id = obj.selection_list2[i][0];
280 //var barcode = obj.selection_list1[i][1];
281 //var bucket_item_id = obj.selection_list1[i][2];
282 var item = obj.flesh_item_for_list( acp_id );
284 obj.list1.append( item );
285 obj.copy_ids.push( acp_id );
291 'copy_buckets_delete_item' : [
294 for (var i = 0; i < obj.selection_list2.length; i++) {
296 //var acp_id = obj.selection_list2[i][0];
297 //var barcode = obj.selection_list2[i][1];
298 var bucket_item_id = obj.selection_list2[i][2];
299 var robj = obj.network.simple_request('BUCKET_ITEM_DELETE',
300 [ ses(), 'copy', bucket_item_id ]);
301 if (typeof robj == 'object') throw robj;
303 obj.error.standard_unexpected_error_alert('Deletion likely failed.',E);
306 alert("Action completed.");
309 JSAN.use('util.widgets');
310 util.widgets.dispatch('change_bucket',obj.controller.view.bucket_menulist);
315 'copy_buckets_delete_bucket' : [
319 var bucket = obj.controller.view.bucket_menulist.value;
320 var name = obj.bucket_id_name_map[ bucket ];
321 var conf = window.confirm('Delete the bucket named ' + name + '?');
324 var robj = obj.network.simple_request('BUCKET_DELETE',[ses(),'copy',bucket]);
325 if (typeof robj == 'object') throw robj;
326 alert("Action completed.");
327 obj.controller.render('copy_buckets_menulist_placeholder');
329 obj.error.standard_unexpected_error_alert('Bucket deletion likely failed.',E);
333 'copy_buckets_new_bucket' : [
337 var name = prompt('What would you like to name the bucket?','','Bucket Creation');
340 var bucket = new ccb();
341 bucket.btype('staff_client');
342 bucket.owner( obj.data.list.au[0].id() );
345 var robj = obj.network.simple_request('BUCKET_CREATE',[ses(),'copy',bucket]);
347 if (typeof robj == 'object') throw robj;
349 alert('Bucket "' + name + '" created.');
351 obj.controller.render('copy_buckets_menulist_placeholder');
352 obj.controller.view.bucket_menulist.value = robj;
355 JSAN.use('util.widgets');
356 util.widgets.dispatch('change_bucket',obj.controller.view.bucket_menulist);
361 obj.error.standard_unexpected_error_alert('Bucket creation failed.',E);
365 'copy_buckets_batch_copy_edit' : [
370 obj.list2.select_all();
372 JSAN.use('util.widgets'); JSAN.use('util.functional');
374 var list = util.functional.map_list(
375 obj.list2.dump_retrieve_ids(),
377 return JSON2js(o)[0]; // acp_id
381 var copies = util.functional.map_list(
384 return obj.network.simple_request('FM_ACP_RETRIEVE',[acp_id]);
390 edit = obj.network.request(
391 api.PERM_MULTI_ORG_CHECK.app,
392 api.PERM_MULTI_ORG_CHECK.method,
395 obj.data.list.au[0].id(),
396 util.functional.map_list(
399 return o.call_number() == -1 ? o.circ_lib() : obj.network.simple_request('FM_ACN_RETRIEVE',[o.call_number()]).owning_lib();
402 copies.length == 1 ? [ 'UPDATE_COPY' ] : [ 'UPDATE_COPY', 'UPDATE_BATCH_COPY' ]
404 ).length == 0 ? 1 : 0;
406 obj.error.sdump('D_ERROR','batch permission check: ' + E);
409 JSAN.use('cat.util'); cat.util.spawn_copy_editor(list,edit);
411 obj.render_pending_copies(); // FIXME -- need a generic refresh for lists
414 JSAN.use('util.widgets');
415 util.widgets.dispatch('change_bucket',obj.controller.view.bucket_menulist);
423 'copy_buckets_batch_copy_delete' : [
428 obj.list2.select_all();
430 JSAN.use('util.widgets'); JSAN.use('util.functional');
432 var list = util.functional.map_list(
433 obj.list2.dump_retrieve_ids(),
435 return JSON2js(o)[0]; // acp_id
439 var copies = util.functional.map_list(
442 return obj.network.simple_request('FM_ACP_RETRIEVE',[acp_id]);
446 for (var i = 0; i < copies.length; i++) {
447 copies[i].ischanged(1);
448 copies[i].isdeleted(1);
451 var robj = obj.network.simple_request('FM_ACP_FLESHED_BATCH_UPDATE',[ ses(), copies, true]);
452 if (typeof robj.ilsevent != 'undefined') obj.error.standard_unexpected_error_alert('Batch Item Deletion',robj);
454 obj.render_pending_copies(); // FIXME -- need a generic refresh for lists
457 JSAN.use('util.widgets');
458 util.widgets.dispatch('change_bucket',obj.controller.view.bucket_menulist);
467 'copy_buckets_transfer_to_volume' : [
471 obj.list2.select_all();
473 obj.data.stash_retrieve();
474 if (!obj.data.marked_volume) {
475 alert('Please mark a volume as the destination from within the copy browser and then try this again.');
479 var copy_ids = util.functional.map_list(
480 obj.list2.dump_retrieve_ids(),
482 return JSON2js(o)[0]; // acp_id
486 var volume = obj.network.simple_request('FM_ACN_RETRIEVE',[ obj.data.marked_volume ]);
488 var msg = 'Transfer the items in bucket "';
489 msg += obj.controller.view.bucket_menulist.getAttribute('label') + '" ';
490 msg += 'from their original volumes to ';
491 msg += obj.data.hash.aou[ volume.owning_lib() ].shortname() + "'s volume labelled ";
492 msg += '"' + volume.label() + '" on the following record?';
494 JSAN.use('cat.util'); cat.util.transfer_copies( {
495 'copy_ids' : copy_ids,
497 'docid' : volume.record(),
498 'volume_label' : volume.label(),
499 'owning_lib' : volume.owning_lib(),
502 obj.render_pending_copies(); // FIXME -- need a generic refresh for lists
505 JSAN.use('util.widgets');
506 util.widgets.dispatch('change_bucket',obj.controller.view.bucket_menulist);
511 obj.error.standard_unexpected_error_alert('Items not likely transferred.',E);
517 function() { alert('Not Yet Implemented'); }
519 'cmd_copy_buckets_print' : [
522 JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.init({'via':'stash'});
523 obj.list2.on_all_fleshed = function() {
525 dump( js2JSON( obj.list2.dump_with_keys() ) + '\n' );
526 data.stash_retrieve();
527 var lib = data.hash.aou[ data.list.au[0].ws_ou() ];
531 'staff' : data.list.au[0],
532 'header' : data.print_list_templates.item_status.header,
533 'line_item' : data.print_list_templates.item_status.line_item,
534 'footer' : data.print_list_templates.item_status.footer,
535 'type' : data.print_list_templates.item_status.type,
536 'list' : obj.list2.dump_with_keys(),
538 JSAN.use('util.print'); var print = new util.print();
539 print.tree_list( p );
540 setTimeout(function(){obj.list2.on_all_fleshed = null;},0);
545 obj.list2.full_retrieve();
548 'cmd_copy_buckets_export' : [
551 obj.list2.on_all_fleshed = function() {
553 dump(obj.list2.dump_csv() + '\n');
554 copy_to_clipboard(obj.list2.dump_csv());
555 setTimeout(function(){obj.list2.on_all_fleshed = null;},0);
560 obj.list2.full_retrieve();
566 obj.list1.on_all_fleshed = function() {
568 dump(obj.list1.dump_csv() + '\n');
569 copy_to_clipboard(obj.list1.dump_csv());
570 setTimeout(function(){obj.list1.on_all_fleshed = null;},0);
575 obj.list1.full_retrieve();
579 'cmd_print_export1' : [
583 obj.list1.on_all_fleshed =
586 dump( obj.list1.dump_csv() + '\n' );
587 //copy_to_clipboard(obj.list.dump_csv());
588 JSAN.use('util.print'); var print = new util.print();
589 print.simple(obj.list1.dump_csv(),{'content_type':'text/plain'});
590 setTimeout(function(){ obj.list1.on_all_fleshed = null; },0);
592 obj.error.standard_unexpected_error_alert('print export',E);
595 obj.list1.full_retrieve();
597 obj.error.standard_unexpected_error_alert('print export',E);
603 'cmd_print_export2' : [
607 obj.list2.on_all_fleshed =
610 dump( obj.list2.dump_csv() + '\n' );
611 //copy_to_clipboard(obj.list.dump_csv());
612 JSAN.use('util.print'); var print = new util.print();
613 print.simple(obj.list2.dump_csv(),{'content_type':'text/plain'});
614 setTimeout(function(){ obj.list2.on_all_fleshed = null; },0);
616 obj.error.standard_unexpected_error_alert('print export',E);
619 obj.list2.full_retrieve();
621 obj.error.standard_unexpected_error_alert('print export',E);
626 'cmd_copy_buckets_reprint' : [
631 'cmd_copy_buckets_done' : [
637 'cmd_export_to_copy_status' : [
641 obj.list2.select_all();
642 JSAN.use('util.functional');
643 var barcodes = util.functional.map_list(
644 obj.list2.dump_retrieve_ids(),
645 function(o) { return JSON2js(o)[1]; }
647 var url = urls.XUL_COPY_STATUS; // + '?barcodes=' + window.escape( js2JSON(barcodes) );
648 JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.stash_retrieve();
649 data.temp_barcodes_for_copy_status = barcodes;
650 data.stash('temp_barcodes_for_copy_status');
651 xulG.new_tab( url, {}, {});
653 obj.error.standard_unexpected_error_alert('Copy Status from Copy Buckets',E);
660 this.controller.render();
662 if (typeof xulG == 'undefined') {
663 obj.controller.view.cmd_export_to_copy_status.disabled = true;
664 obj.controller.view.cmd_export_to_copy_status.setAttribute('disabled',true);
666 obj.controller.view.cmd_copy_buckets_done.disabled = true;
667 obj.controller.view.cmd_copy_buckets_done.setAttribute('disabled',true);
672 'flesh_item_for_list' : function(acp_id,bucket_item_id) {
675 var copy = obj.network.simple_request( 'FM_ACP_RETRIEVE', [ acp_id ]);
676 if (copy == null || typeof copy.ilsevent != 'undefined') {
680 'retrieve_id' : js2JSON( [ copy.id(), copy.barcode(), bucket_item_id ] ),
683 'mvr' : obj.network.simple_request('MODS_SLIM_RECORD_RETRIEVE_VIA_COPY', [ copy.id() ]),
691 obj.error.standard_unexpected_error_alert('List building failed.',E);
699 dump('exiting cat.copy_buckets.js\n');