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') {
348 if (robj.ilsevent == 1710 /* CONTAINER_EXISTS */) {
349 alert('You already have a bucket with that name.');
355 alert('Bucket "' + name + '" created.');
357 obj.controller.render('copy_buckets_menulist_placeholder');
358 obj.controller.view.bucket_menulist.value = robj;
361 JSAN.use('util.widgets');
362 util.widgets.dispatch('change_bucket',obj.controller.view.bucket_menulist);
367 obj.error.standard_unexpected_error_alert('Bucket creation failed.',E);
371 'copy_buckets_batch_copy_edit' : [
376 obj.list2.select_all();
378 JSAN.use('util.widgets'); JSAN.use('util.functional');
380 var list = util.functional.map_list(
381 obj.list2.dump_retrieve_ids(),
383 return JSON2js(o)[0]; // acp_id
387 var copies = util.functional.map_list(
390 return obj.network.simple_request('FM_ACP_RETRIEVE',[acp_id]);
396 edit = obj.network.request(
397 api.PERM_MULTI_ORG_CHECK.app,
398 api.PERM_MULTI_ORG_CHECK.method,
401 obj.data.list.au[0].id(),
402 util.functional.map_list(
405 return o.call_number() == -1 ? o.circ_lib() : obj.network.simple_request('FM_ACN_RETRIEVE',[o.call_number()]).owning_lib();
408 copies.length == 1 ? [ 'UPDATE_COPY' ] : [ 'UPDATE_COPY', 'UPDATE_BATCH_COPY' ]
410 ).length == 0 ? 1 : 0;
412 obj.error.sdump('D_ERROR','batch permission check: ' + E);
415 JSAN.use('cat.util'); cat.util.spawn_copy_editor(list,edit);
417 obj.render_pending_copies(); // FIXME -- need a generic refresh for lists
420 JSAN.use('util.widgets');
421 util.widgets.dispatch('change_bucket',obj.controller.view.bucket_menulist);
429 'copy_buckets_batch_copy_delete' : [
434 obj.list2.select_all();
436 JSAN.use('util.widgets'); JSAN.use('util.functional');
438 var list = util.functional.map_list(
439 obj.list2.dump_retrieve_ids(),
441 return JSON2js(o)[0]; // acp_id
445 var copies = util.functional.map_list(
448 return obj.network.simple_request('FM_ACP_RETRIEVE',[acp_id]);
452 for (var i = 0; i < copies.length; i++) {
453 copies[i].ischanged(1);
454 copies[i].isdeleted(1);
457 var robj = obj.network.simple_request('FM_ACP_FLESHED_BATCH_UPDATE',[ ses(), copies, true]);
458 if (typeof robj.ilsevent != 'undefined') obj.error.standard_unexpected_error_alert('Batch Item Deletion',robj);
460 obj.render_pending_copies(); // FIXME -- need a generic refresh for lists
463 JSAN.use('util.widgets');
464 util.widgets.dispatch('change_bucket',obj.controller.view.bucket_menulist);
473 'copy_buckets_transfer_to_volume' : [
477 obj.list2.select_all();
479 obj.data.stash_retrieve();
480 if (!obj.data.marked_volume) {
481 alert('Please mark a volume as the destination from within the copy browser and then try this again.');
485 var copy_ids = util.functional.map_list(
486 obj.list2.dump_retrieve_ids(),
488 return JSON2js(o)[0]; // acp_id
492 var volume = obj.network.simple_request('FM_ACN_RETRIEVE',[ obj.data.marked_volume ]);
494 var msg = 'Transfer the items in bucket "';
495 msg += obj.controller.view.bucket_menulist.getAttribute('label') + '" ';
496 msg += 'from their original volumes to ';
497 msg += obj.data.hash.aou[ volume.owning_lib() ].shortname() + "'s volume labelled ";
498 msg += '"' + volume.label() + '" on the following record?';
500 JSAN.use('cat.util'); cat.util.transfer_copies( {
501 'copy_ids' : copy_ids,
503 'docid' : volume.record(),
504 'volume_label' : volume.label(),
505 'owning_lib' : volume.owning_lib(),
508 obj.render_pending_copies(); // FIXME -- need a generic refresh for lists
511 JSAN.use('util.widgets');
512 util.widgets.dispatch('change_bucket',obj.controller.view.bucket_menulist);
517 obj.error.standard_unexpected_error_alert('Items not likely transferred.',E);
523 function() { alert('Not Yet Implemented'); }
525 'cmd_copy_buckets_print' : [
528 JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.init({'via':'stash'});
529 obj.list2.on_all_fleshed = function() {
531 dump( js2JSON( obj.list2.dump_with_keys() ) + '\n' );
532 data.stash_retrieve();
533 var lib = data.hash.aou[ data.list.au[0].ws_ou() ];
537 'staff' : data.list.au[0],
538 'header' : data.print_list_templates.item_status.header,
539 'line_item' : data.print_list_templates.item_status.line_item,
540 'footer' : data.print_list_templates.item_status.footer,
541 'type' : data.print_list_templates.item_status.type,
542 'list' : obj.list2.dump_with_keys(),
544 JSAN.use('util.print'); var print = new util.print();
545 print.tree_list( p );
546 setTimeout(function(){obj.list2.on_all_fleshed = null;},0);
551 obj.list2.full_retrieve();
554 'cmd_copy_buckets_export' : [
557 obj.list2.on_all_fleshed = function() {
559 dump(obj.list2.dump_csv() + '\n');
560 copy_to_clipboard(obj.list2.dump_csv());
561 setTimeout(function(){obj.list2.on_all_fleshed = null;},0);
566 obj.list2.full_retrieve();
572 obj.list1.on_all_fleshed = function() {
574 dump(obj.list1.dump_csv() + '\n');
575 copy_to_clipboard(obj.list1.dump_csv());
576 setTimeout(function(){obj.list1.on_all_fleshed = null;},0);
581 obj.list1.full_retrieve();
585 'cmd_print_export1' : [
589 obj.list1.on_all_fleshed =
592 dump( obj.list1.dump_csv() + '\n' );
593 //copy_to_clipboard(obj.list.dump_csv());
594 JSAN.use('util.print'); var print = new util.print();
595 print.simple(obj.list1.dump_csv(),{'content_type':'text/plain'});
596 setTimeout(function(){ obj.list1.on_all_fleshed = null; },0);
598 obj.error.standard_unexpected_error_alert('print export',E);
601 obj.list1.full_retrieve();
603 obj.error.standard_unexpected_error_alert('print export',E);
609 'cmd_print_export2' : [
613 obj.list2.on_all_fleshed =
616 dump( obj.list2.dump_csv() + '\n' );
617 //copy_to_clipboard(obj.list.dump_csv());
618 JSAN.use('util.print'); var print = new util.print();
619 print.simple(obj.list2.dump_csv(),{'content_type':'text/plain'});
620 setTimeout(function(){ obj.list2.on_all_fleshed = null; },0);
622 obj.error.standard_unexpected_error_alert('print export',E);
625 obj.list2.full_retrieve();
627 obj.error.standard_unexpected_error_alert('print export',E);
632 'cmd_copy_buckets_reprint' : [
637 'cmd_copy_buckets_done' : [
643 'cmd_export_to_copy_status' : [
647 obj.list2.select_all();
648 JSAN.use('util.functional');
649 var barcodes = util.functional.map_list(
650 obj.list2.dump_retrieve_ids(),
651 function(o) { return JSON2js(o)[1]; }
653 var url = urls.XUL_COPY_STATUS; // + '?barcodes=' + window.escape( js2JSON(barcodes) );
654 //JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.stash_retrieve();
655 //data.temp_barcodes_for_copy_status = barcodes;
656 //data.stash('temp_barcodes_for_copy_status');
657 xulG.new_tab( url, {}, { 'barcodes' : barcodes });
659 obj.error.standard_unexpected_error_alert('Copy Status from Copy Buckets',E);
666 this.controller.render();
668 if (typeof xulG == 'undefined') {
669 obj.controller.view.cmd_export_to_copy_status.disabled = true;
670 obj.controller.view.cmd_export_to_copy_status.setAttribute('disabled',true);
672 obj.controller.view.cmd_copy_buckets_done.disabled = true;
673 obj.controller.view.cmd_copy_buckets_done.setAttribute('disabled',true);
678 'flesh_item_for_list' : function(acp_id,bucket_item_id) {
681 var copy = obj.network.simple_request( 'FM_ACP_RETRIEVE', [ acp_id ]);
682 if (copy == null || typeof copy.ilsevent != 'undefined') {
686 'retrieve_id' : js2JSON( [ copy.id(), copy.barcode(), bucket_item_id ] ),
689 'mvr' : obj.network.simple_request('MODS_SLIM_RECORD_RETRIEVE_VIA_COPY', [ copy.id() ]),
697 obj.error.standard_unexpected_error_alert('List building failed.',E);
705 dump('exiting cat.copy_buckets.js\n');