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("Pausing for replicated databases... press Enter or Spacebar when ready.");
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 obj.selection_list1 = util.functional.map_list(
63 function(o) { return JSON2js(o.getAttribute('retrieve_id')); }
65 obj.error.sdump('D_TRACE','circ/copy_buckets: selection list 1 = ' + js2JSON(obj.selection_list1) );
66 if (obj.selection_list1.length == 0) {
67 obj.controller.view.copy_buckets_sel_add.disabled = true;
69 obj.controller.view.copy_buckets_sel_add.disabled = false;
79 obj.render_pending_copies();
81 obj.list2 = new util.list('copies_in_bucket_list');
85 'map_row_to_columns' : circ.util.std_map_row_to_columns(),
86 'on_select' : function(ev) {
88 JSAN.use('util.functional');
89 var sel = obj.list2.retrieve_selection();
90 document.getElementById('clip_button').disabled = sel.length < 1;
91 obj.selection_list2 = util.functional.map_list(
93 function(o) { return JSON2js(o.getAttribute('retrieve_id')); }
95 obj.error.sdump('D_TRACE','circ/copy_buckets: selection list 2 = ' + js2JSON(obj.selection_list2) );
96 if (obj.selection_list2.length == 0) {
97 obj.controller.view.copy_buckets_delete_item.disabled = true;
98 obj.controller.view.copy_buckets_delete_item.setAttribute('disabled','true');
99 obj.controller.view.copy_buckets_export.disabled = true;
100 obj.controller.view.copy_buckets_export.setAttribute('disabled','true');
102 obj.controller.view.copy_buckets_delete_item.disabled = false;
103 obj.controller.view.copy_buckets_delete_item.setAttribute('disabled','false');
104 obj.controller.view.copy_buckets_export.disabled = false;
105 obj.controller.view.copy_buckets_export.setAttribute('disabled','false');
108 alert('FIXME: ' + E);
114 JSAN.use('util.controller'); obj.controller = new util.controller();
120 function() { obj.list2.clipboard(); }
122 'copy_buckets_menulist_placeholder' : [
126 JSAN.use('util.widgets'); JSAN.use('util.functional');
127 var items = [ ['Choose a bucket...',''], ['Retrieve shared bucket...',-1] ].concat(
128 util.functional.map_list(
129 obj.network.simple_request(
130 'BUCKET_RETRIEVE_VIA_USER',
131 [ ses(), obj.data.list.au[0].id() ]
134 obj.bucket_id_name_map[ o.id() ] = o.name();
135 return [ o.name(), o.id() ];
139 obj.error.sdump('D_TRACE','items = ' + js2JSON(items));
140 util.widgets.remove_children( e );
141 var ml = util.widgets.make_menulist(
145 ml.setAttribute('id','bucket_menulist');
146 ml.setAttribute('accesskey','');
148 function change_bucket(ev) {
149 var bucket_id = ev.target.value;
150 if (bucket_id < 0 ) {
151 bucket_id = window.prompt('Enter bucket number:');
152 ev.target.value = bucket_id;
153 ev.target.setAttribute('value',bucket_id);
155 if (!bucket_id) return;
156 var bucket = obj.network.simple_request(
158 [ ses(), 'copy', bucket_id ]
160 if (typeof bucket.ilsevent != 'undefined') {
161 if (bucket.ilsevent == 1506 /* CONTAINER_NOT_FOUND */) {
162 alert('Could not find a bucket with ID = ' + bucket_id);
164 obj.error.standard_unexpected_error_alert('Error retrieving bucket. Did you use a valid bucket id?',bucket);
169 var x = document.getElementById('info_box');
170 x.setAttribute('hidden','false');
171 x = document.getElementById('bucket_number');
172 x.setAttribute('value',bucket.id());
173 x = document.getElementById('bucket_name');
174 x.setAttribute('value',bucket.name());
175 x = document.getElementById('bucket_owner');
176 var s = bucket.owner(); JSAN.use('patron.util');
177 if (s && typeof s != "object") s = patron.util.retrieve_fleshed_au_via_id(ses(),s);
178 x.setAttribute('value',s.card().barcode() + " @ " + obj.data.hash.aou[ s.home_ou() ].shortname());
183 var items = bucket.items() || [];
185 for (var i = 0; i < items.length; i++) {
186 var item = obj.flesh_item_for_list(
187 items[i].target_copy(),
190 if (item) obj.list2.append( item );
194 ml.addEventListener( 'change_bucket', change_bucket , false);
195 ml.addEventListener( 'command', function() {
196 JSAN.use('util.widgets'); util.widgets.dispatch('change_bucket',ml);
198 obj.controller.view.bucket_menulist = ml;
199 JSAN.use('util.widgets'); util.widgets.dispatch('change_bucket',ml);
200 document.getElementById('refresh').addEventListener( 'command', function() {
201 JSAN.use('util.widgets'); util.widgets.dispatch('change_bucket',ml);
207 'copy_buckets_add' : [
210 var bucket_id = obj.controller.view.bucket_menulist.value;
211 if (!bucket_id) return;
212 for (var i = 0; i < obj.copy_ids.length; i++) {
213 var bucket_item = new ccbi();
214 bucket_item.isnew('1');
215 bucket_item.bucket(bucket_id);
216 bucket_item.target_copy( obj.copy_ids[i] );
218 var robj = obj.network.simple_request('BUCKET_ITEM_CREATE',
219 [ ses(), 'copy', bucket_item ]);
221 if (typeof robj == 'object') throw robj;
223 var item = obj.flesh_item_for_list( obj.copy_ids[i], robj );
226 obj.list2.append( item );
228 obj.error.standard_unexpected_error_alert('Addition likely failed.',E);
233 'copy_buckets_sel_add' : [
236 var bucket_id = obj.controller.view.bucket_menulist.value;
237 if (!bucket_id) return;
238 for (var i = 0; i < obj.selection_list1.length; i++) {
239 var acp_id = obj.selection_list1[i][0];
240 //var barcode = obj.selection_list1[i][1];
241 var bucket_item = new ccbi();
242 bucket_item.isnew('1');
243 bucket_item.bucket(bucket_id);
244 bucket_item.target_copy( acp_id );
246 var robj = obj.network.simple_request('BUCKET_ITEM_CREATE',
247 [ ses(), 'copy', bucket_item ]);
249 if (typeof robj == 'object') throw robj;
251 var item = obj.flesh_item_for_list( acp_id, robj );
254 obj.list2.append( item );
256 obj.error.standard_unexpected_error_alert('Deletion likely failed.',E);
262 'copy_buckets_export' : [
265 for (var i = 0; i < obj.selection_list2.length; i++) {
266 var acp_id = obj.selection_list2[i][0];
267 //var barcode = obj.selection_list1[i][1];
268 //var bucket_item_id = obj.selection_list1[i][2];
269 var item = obj.flesh_item_for_list( acp_id );
271 obj.list1.append( item );
272 obj.copy_ids.push( acp_id );
278 'copy_buckets_delete_item' : [
281 for (var i = 0; i < obj.selection_list2.length; i++) {
283 //var acp_id = obj.selection_list2[i][0];
284 //var barcode = obj.selection_list2[i][1];
285 var bucket_item_id = obj.selection_list2[i][2];
286 var robj = obj.network.simple_request('BUCKET_ITEM_DELETE',
287 [ ses(), 'copy', bucket_item_id ]);
288 if (typeof robj == 'object') throw robj;
290 obj.error.standard_unexpected_error_alert('Deletion likely failed.',E);
293 alert("Pausing for replicated databases... press Enter or Spacebar when ready.");
296 JSAN.use('util.widgets');
297 util.widgets.dispatch('change_bucket',obj.controller.view.bucket_menulist);
302 'copy_buckets_delete_bucket' : [
306 var bucket = obj.controller.view.bucket_menulist.value;
307 var name = obj.bucket_id_name_map[ bucket ];
308 var conf = window.confirm('Delete the bucket named ' + name + '?');
311 var robj = obj.network.simple_request('BUCKET_DELETE',[ses(),'copy',bucket]);
312 if (typeof robj == 'object') throw robj;
313 alert("Pausing for replicated databases... press Enter or Spacebar when ready.");
314 obj.controller.render('copy_buckets_menulist_placeholder');
316 obj.error.standard_unexpected_error_alert('Bucket deletion likely failed.',E);
320 'copy_buckets_new_bucket' : [
324 var name = prompt('What would you like to name the bucket?','','Bucket Creation');
327 var bucket = new ccb();
328 bucket.btype('staff_client');
329 bucket.owner( obj.data.list.au[0].id() );
332 var robj = obj.network.simple_request('BUCKET_CREATE',[ses(),'copy',bucket]);
334 if (typeof robj == 'object') throw robj;
336 alert('Bucket "' + name + '" created.');
338 obj.controller.render('copy_buckets_menulist_placeholder');
339 obj.controller.view.bucket_menulist.value = robj;
342 JSAN.use('util.widgets');
343 util.widgets.dispatch('change_bucket',obj.controller.view.bucket_menulist);
348 obj.error.standard_unexpected_error_alert('Bucket creation failed.',E);
352 'copy_buckets_batch_copy_edit' : [
357 obj.list2.select_all();
359 JSAN.use('util.widgets'); JSAN.use('util.functional');
361 var list = util.functional.map_list(
362 obj.list2.dump_retrieve_ids(),
364 return JSON2js(o)[0]; // acp_id
368 var copies = util.functional.map_list(
371 return obj.network.simple_request('FM_ACP_RETRIEVE',[acp_id]);
377 edit = obj.network.request(
378 api.PERM_MULTI_ORG_CHECK.app,
379 api.PERM_MULTI_ORG_CHECK.method,
382 obj.data.list.au[0].id(),
383 util.functional.map_list(
386 return o.call_number() == -1 ? o.circ_lib() : obj.network.simple_request('FM_ACN_RETRIEVE',[o.call_number()]).owning_lib();
389 copies.length == 1 ? [ 'UPDATE_COPY' ] : [ 'UPDATE_COPY', 'UPDATE_BATCH_COPY' ]
391 ).length == 0 ? 1 : 0;
393 obj.error.sdump('D_ERROR','batch permission check: ' + E);
396 JSAN.use('cat.util'); cat.util.spawn_copy_editor(list,edit);
398 obj.render_pending_copies(); // FIXME -- need a generic refresh for lists
401 JSAN.use('util.widgets');
402 util.widgets.dispatch('change_bucket',obj.controller.view.bucket_menulist);
410 'copy_buckets_batch_copy_delete' : [
415 obj.list2.select_all();
417 JSAN.use('util.widgets'); JSAN.use('util.functional');
419 var list = util.functional.map_list(
420 obj.list2.dump_retrieve_ids(),
422 return JSON2js(o)[0]; // acp_id
426 var copies = util.functional.map_list(
429 return obj.network.simple_request('FM_ACP_RETRIEVE',[acp_id]);
433 for (var i = 0; i < copies.length; i++) {
434 copies[i].ischanged(1);
435 copies[i].isdeleted(1);
438 var robj = obj.network.simple_request('FM_ACP_FLESHED_BATCH_UPDATE',[ ses(), copies, true]);
439 if (typeof robj.ilsevent != 'undefined') obj.error.standard_unexpected_error_alert('Batch Item Deletion',robj);
441 obj.render_pending_copies(); // FIXME -- need a generic refresh for lists
444 JSAN.use('util.widgets');
445 util.widgets.dispatch('change_bucket',obj.controller.view.bucket_menulist);
454 'copy_buckets_transfer_to_volume' : [
458 obj.list2.select_all();
460 obj.data.stash_retrieve();
461 if (!obj.data.marked_volume) {
462 alert('Please mark a volume as the destination from within the copy browser and then try this again.');
466 var copy_ids = util.functional.map_list(
467 obj.list2.dump_retrieve_ids(),
469 return JSON2js(o)[0]; // acp_id
473 var volume = obj.network.simple_request('FM_ACN_RETRIEVE',[ obj.data.marked_volume ]);
475 var msg = 'Transfer the items in bucket "';
476 msg += obj.controller.view.bucket_menulist.getAttribute('label') + '" ';
477 msg += 'from their original volumes to ';
478 msg += obj.data.hash.aou[ volume.owning_lib() ].shortname() + "'s volume labelled ";
479 msg += '"' + volume.label() + '" on the following record?';
481 JSAN.use('cat.util'); cat.util.transfer_copies( {
482 'copy_ids' : copy_ids,
484 'docid' : volume.record(),
485 'volume_label' : volume.label(),
486 'owning_lib' : volume.owning_lib(),
489 obj.render_pending_copies(); // FIXME -- need a generic refresh for lists
492 JSAN.use('util.widgets');
493 util.widgets.dispatch('change_bucket',obj.controller.view.bucket_menulist);
498 obj.error.standard_unexpected_error_alert('Items not likely transferred.',E);
504 function() { alert('Not Yet Implemented'); }
506 'cmd_copy_buckets_print' : [
509 JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.init({'via':'stash'});
510 obj.list2.on_all_fleshed = function() {
512 dump( js2JSON( obj.list2.dump_with_keys() ) + '\n' );
513 data.stash_retrieve();
514 var lib = data.hash.aou[ data.list.au[0].ws_ou() ];
518 'staff' : data.list.au[0],
519 'header' : data.print_list_templates.item_status.header,
520 'line_item' : data.print_list_templates.item_status.line_item,
521 'footer' : data.print_list_templates.item_status.footer,
522 'type' : data.print_list_templates.item_status.type,
523 'list' : obj.list2.dump_with_keys(),
525 JSAN.use('util.print'); var print = new util.print();
526 print.tree_list( p );
527 setTimeout(function(){obj.list2.on_all_fleshed = null;},0);
532 obj.list2.full_retrieve();
535 'cmd_copy_buckets_reprint' : [
540 'cmd_copy_buckets_done' : [
546 'cmd_export_to_copy_status' : [
550 obj.list2.select_all();
551 JSAN.use('util.functional');
552 var barcodes = util.functional.map_list(
553 obj.list2.dump_retrieve_ids(),
554 function(o) { return JSON2js(o)[1]; }
556 var url = urls.XUL_COPY_STATUS + '?barcodes=' + window.escape( js2JSON(barcodes) );
557 xulG.new_tab( url, {}, {});
559 obj.error.standard_unexpected_error_alert('Copy Status from Copy Buckets',E);
566 this.controller.render();
568 if (typeof xulG == 'undefined') {
569 obj.controller.view.cmd_export_to_copy_status.disabled = true;
570 obj.controller.view.cmd_export_to_copy_status.setAttribute('disabled',true);
572 obj.controller.view.cmd_copy_buckets_done.disabled = true;
573 obj.controller.view.cmd_copy_buckets_done.setAttribute('disabled',true);
578 'flesh_item_for_list' : function(acp_id,bucket_item_id) {
581 var copy = obj.network.simple_request( 'FM_ACP_RETRIEVE', [ acp_id ]);
582 if (copy == null || typeof copy.ilsevent != 'undefined') {
586 'retrieve_id' : js2JSON( [ copy.id(), copy.barcode(), bucket_item_id ] ),
589 'mvr' : obj.network.simple_request('MODS_SLIM_RECORD_RETRIEVE_VIA_COPY', [ copy.id() ]),
597 obj.error.standard_unexpected_error_alert('List building failed.',E);
605 dump('exiting cat.copy_buckets.js\n');