]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/xul/staff_client/server/circ/copy_status.js
0cc79cf35827f1f9fe4f39a53a7810e231717946
[Evergreen.git] / Open-ILS / xul / staff_client / server / circ / copy_status.js
1 dump('entering circ.copy_status.js\n');
2
3 if (typeof circ == 'undefined') circ = {};
4 circ.copy_status = function (params) {
5
6         JSAN.use('util.error'); this.error = new util.error();
7         JSAN.use('util.network'); this.network = new util.network();
8         JSAN.use('util.barcode');
9         JSAN.use('util.date');
10         JSAN.use('OpenILS.data'); this.data = new OpenILS.data(); this.data.init({'via':'stash'});
11 }
12
13 circ.copy_status.prototype = {
14         'selection_list' : [],
15
16         'init' : function( params ) {
17
18                 var obj = this;
19
20                 JSAN.use('circ.util');
21                 var columns = circ.util.columns( 
22                         { 
23                                 'barcode' : { 'hidden' : false },
24                                 'title' : { 'hidden' : false },
25                                 'location' : { 'hidden' : false },
26                                 'call_number' : { 'hidden' : false },
27                                 'status' : { 'hidden' : false },
28                                 'alert_message' : { 'hidden' : false },
29                                 'due_date' : { 'hidden' : false },
30                         },
31                         {
32                                 'except_these' : [
33                                         'checkin_time', 'checkin_time_full', 'route_to', 'message', 'uses', 'xact_finish',
34                                 ],
35                         }
36                 );
37
38                 JSAN.use('util.list'); obj.list = new util.list('copy_status_list');
39                 obj.list.init(
40                         {
41                                 'columns' : columns,
42                                 'map_row_to_columns' : circ.util.std_map_row_to_columns(),
43                                 'on_select' : function(ev) {
44                                         try {
45                                                 JSAN.use('util.functional');
46                                                 var sel = obj.list.retrieve_selection();
47                                                 obj.selection_list = util.functional.map_list(
48                                                         sel,
49                                                         function(o) { return JSON2js(o.getAttribute('retrieve_id')); }
50                                                 );
51                                                 obj.error.sdump('D_TRACE','circ/copy_status: selection list = ' + js2JSON(obj.selection_list) );
52                                                 if (obj.selection_list.length == 0) {
53                                                         obj.controller.view.sel_checkin.setAttribute('disabled','true');
54                                                         obj.controller.view.cmd_replace_barcode.setAttribute('disabled','true');
55                                                         obj.controller.view.sel_edit.setAttribute('disabled','true');
56                                                         obj.controller.view.sel_opac.setAttribute('disabled','true');
57                                                         obj.controller.view.sel_bucket.setAttribute('disabled','true');
58                                                         obj.controller.view.sel_copy_details.setAttribute('disabled','true');
59                                                         obj.controller.view.sel_mark_items_damaged.setAttribute('disabled','true');
60                                                         obj.controller.view.sel_mark_items_missing.setAttribute('disabled','true');
61                                                         obj.controller.view.sel_patron.setAttribute('disabled','true');
62                                                         obj.controller.view.sel_spine.setAttribute('disabled','true');
63                                                         obj.controller.view.sel_transit_abort.setAttribute('disabled','true');
64                                                         obj.controller.view.sel_clip.setAttribute('disabled','true');
65                                                         obj.controller.view.sel_renew.setAttribute('disabled','true');
66                                                         obj.controller.view.cmd_add_items.setAttribute('disabled','true');
67                                                         obj.controller.view.cmd_delete_items.setAttribute('disabled','true');
68                                                         obj.controller.view.cmd_transfer_items.setAttribute('disabled','true');
69                                                         obj.controller.view.cmd_add_volumes.setAttribute('disabled','true');
70                                                         obj.controller.view.cmd_edit_volumes.setAttribute('disabled','true');
71                                                         obj.controller.view.cmd_delete_volumes.setAttribute('disabled','true');
72                                                         obj.controller.view.cmd_mark_volume.setAttribute('disabled','true');
73                                                         obj.controller.view.cmd_mark_library.setAttribute('disabled','true');
74                                                         obj.controller.view.cmd_transfer_volume.setAttribute('disabled','true');
75                                                 } else {
76                                                         obj.controller.view.sel_checkin.setAttribute('disabled','false');
77                                                         obj.controller.view.cmd_replace_barcode.setAttribute('disabled','false');
78                                                         obj.controller.view.sel_edit.setAttribute('disabled','false');
79                                                         obj.controller.view.sel_opac.setAttribute('disabled','false');
80                                                         obj.controller.view.sel_patron.setAttribute('disabled','false');
81                                                         obj.controller.view.sel_bucket.setAttribute('disabled','false');
82                                                         obj.controller.view.sel_copy_details.setAttribute('disabled','false');
83                                                         obj.controller.view.sel_mark_items_damaged.setAttribute('disabled','false');
84                                                         obj.controller.view.sel_mark_items_missing.setAttribute('disabled','false');
85                                                         obj.controller.view.sel_spine.setAttribute('disabled','false');
86                                                         obj.controller.view.sel_transit_abort.setAttribute('disabled','false');
87                                                         obj.controller.view.sel_clip.setAttribute('disabled','false');
88                                                         obj.controller.view.sel_renew.setAttribute('disabled','false');
89                                                         obj.controller.view.cmd_add_items.setAttribute('disabled','false');
90                                                         obj.controller.view.cmd_delete_items.setAttribute('disabled','false');
91                                                         obj.controller.view.cmd_transfer_items.setAttribute('disabled','false');
92                                                         obj.controller.view.cmd_add_volumes.setAttribute('disabled','false');
93                                                         obj.controller.view.cmd_edit_volumes.setAttribute('disabled','false');
94                                                         obj.controller.view.cmd_delete_volumes.setAttribute('disabled','false');
95                                                         obj.controller.view.cmd_mark_volume.setAttribute('disabled','false');
96                                                         obj.controller.view.cmd_mark_library.setAttribute('disabled','false');
97                                                         obj.controller.view.cmd_transfer_volume.setAttribute('disabled','false');
98                                                 }
99                                         } catch(E) {
100                                                 alert('FIXME: ' + E);
101                                         }
102                                 },
103                         }
104                 );
105                 
106                 JSAN.use('util.controller'); obj.controller = new util.controller();
107                 obj.controller.init(
108                         {
109                                 'control_map' : {
110                                         'save_columns' : [ [ 'command' ], function() { obj.list.save_columns(); } ],
111                                         'sel_clip' : [
112                                                 ['command'],
113                                                 function() { obj.list.clipboard(); }
114                                         ],
115                                         'sel_checkin' : [
116                                                 ['command'],
117                                                 function() {
118                                                         try {
119                                                                 var funcs = [];
120                                                                 JSAN.use('circ.util');
121                                                                 for (var i = 0; i < obj.selection_list.length; i++) {
122                                                                         var barcode = obj.selection_list[i].barcode;
123                                                                         var checkin = circ.util.checkin_via_barcode( ses(), { 'barcode' : barcode } );
124                                                                         funcs.push( function(a) { return function() { obj.copy_status( a ); }; }(barcode) );
125                                                                 }
126                                                                 alert('Action complete.');
127                                                                 for (var i = 0; i < funcs.length; i++) { funcs[i](); }
128                                                         } catch(E) {
129                                                                 obj.error.standard_unexpected_error_alert('Checkin did not likely happen.',E);
130                                                         }
131                                                 }
132                                         ],
133                                         'cmd_replace_barcode' : [
134                                                 ['command'],
135                                                 function() {
136                                                         try {
137                                                                 var funcs = [];
138                                                                 JSAN.use('cat.util');
139                                                                 for (var i = 0; i < obj.selection_list.length; i++) {
140                                                                         try { 
141                                                                                 var barcode = obj.selection_list[i].barcode;
142                                                                                 var new_bc = cat.util.replace_barcode( barcode );
143                                                                                 funcs.push( function(a) { return function() { obj.copy_status( a ); }; }(new_bc) );
144                                                                         } catch(E) {
145                                                                                 obj.error.standard_unexpected_error_alert('Barcode ' + barcode + ' was not likely replaced.',E);
146                                                                         }
147                                                                 }
148                                                                 alert('Action complete.');
149                                                                 for (var i = 0; i < funcs.length; i++) { funcs[i](); }
150                                                         } catch(E) {
151                                                                 obj.error.standard_unexpected_error_alert('Barcode replacements did not likely happen.',E);
152                                                         }
153                                                 }
154                                         ],
155                                         'sel_edit' : [
156                                                 ['command'],
157                                                 function() {
158                                                         try {
159                                                                 var funcs = [];
160                                                                 obj.spawn_copy_editor();
161                                                                 for (var i = 0; i < obj.selection_list.length; i++) {
162                                                                                 var barcode = obj.selection_list[i].barcode;
163                                                                                 funcs.push( function(a) { return function() { obj.copy_status( a ); }; }(barcode) );
164                                                                 }
165                                                                 for (var i = 0; i < funcs.length; i++) { funcs[i](); }
166                                                         } catch(E) {
167                                                                 obj.error.standard_unexpected_error_alert('with copy editor',E);
168                                                         }
169                                                 }
170                                         ],
171                                         'sel_spine' : [
172                                                 ['command'],
173                                                 function() {
174                                                         JSAN.use('cat.util');
175                                                         cat.util.spawn_spine_editor(obj.selection_list);
176                                                 }
177                                         ],
178                                         'sel_opac' : [
179                                                 ['command'],
180                                                 function() {
181                                                         JSAN.use('cat.util');
182                                                         cat.util.show_in_opac(obj.selection_list);
183                                                 }
184                                         ],
185                                         'sel_transit_abort' : [
186                                                 ['command'],
187                                                 function() {
188                                                         var funcs = [];
189                                                         JSAN.use('circ.util');
190                                                         circ.util.abort_transits(obj.selection_list);
191                                                         for (var i = 0; i < obj.selection_list.length; i++) {
192                                                                 var barcode = obj.selection_list[i].barcode;
193                                                                 funcs.push( function(a) { return function() { obj.copy_status( a ); }; }(barcode) );
194                                                         }
195                                                         alert('Action complete.');
196                                                         for (var i = 0; i < funcs.length; i++) { funcs[i](); }
197                                                 }
198                                         ],
199                                         'sel_patron' : [
200                                                 ['command'],
201                                                 function() {
202                                                         JSAN.use('circ.util');
203                                                         circ.util.show_last_few_circs(obj.selection_list);
204                                                 }
205                                         ],
206                                         'sel_copy_details' : [
207                                                 ['command'],
208                                                 function() {
209                                                         JSAN.use('circ.util');
210                                                         for (var i = 0; i < obj.selection_list.length; i++) {
211                                                                 circ.util.show_copy_details( obj.selection_list[i].copy_id );
212                                                         }
213                                                 }
214                                         ],
215                                         'sel_renew' : [
216                                                 ['command'],
217                                                 function() {
218                                                         var funcs = [];
219                                                         JSAN.use('circ.util');
220                                                         for (var i = 0; i < obj.selection_list.length; i++) {
221                                                                 var test = obj.selection_list[i].renewable;
222                                                                 var barcode = obj.selection_list[i].barcode;
223                                                                 if (test == 't') {
224                                                                         circ.util.renew_via_barcode( barcode );
225                                                                         funcs.push( function(a) { return function() { obj.copy_status( a ); }; }(barcode) );
226                                                                 } else {
227                                                                         alert('Item with barcode ' + barcode + ' is not circulating.');
228                                                                 }
229                                                         }
230                                                         alert('Action complete.');
231                                                         for (var i = 0; i < funcs.length; i++) { funcs[i](); }
232                                                 }
233                                         ],
234
235                                         'sel_mark_items_damaged' : [
236                                                 ['command'],
237                                                 function() {
238                                                         var funcs = [];
239                                                         JSAN.use('cat.util'); JSAN.use('util.functional');
240                                                         cat.util.mark_item_damaged( util.functional.map_list( obj.selection_list, function(o) { return o.copy_id; } ) );
241                                                         for (var i = 0; i < obj.selection_list.length; i++) {
242                                                                 var barcode = obj.selection_list[i].barcode;
243                                                                 funcs.push( function(a) { return function() { obj.copy_status( a ); }; }(barcode) );
244                                                         }
245                                                         for (var i = 0; i < funcs.length; i++) { funcs[i](); }
246                                                 }
247                                         ],
248                                         'sel_mark_items_missing' : [
249                                                 ['command'],
250                                                 function() {
251                                                         var funcs = [];
252                                                         JSAN.use('cat.util'); JSAN.use('util.functional');
253                                                         cat.util.mark_item_missing( util.functional.map_list( obj.selection_list, function(o) { return o.copy_id; } ) );
254                                                         for (var i = 0; i < obj.selection_list.length; i++) {
255                                                                 var barcode = obj.selection_list[i].barcode;
256                                                                 funcs.push( function(a) { return function() { obj.copy_status( a ); }; }(barcode) );
257                                                         }
258                                                         for (var i = 0; i < funcs.length; i++) { funcs[i](); }
259                                                 }
260                                         ],
261                                         'sel_bucket' : [
262                                                 ['command'],
263                                                 function() {
264                                                         JSAN.use('cat.util');
265                                                         cat.util.add_copies_to_bucket(obj.selection_list);
266                                                 }
267                                         ],
268                                         'copy_status_barcode_entry_textbox' : [
269                                                 ['keypress'],
270                                                 function(ev) {
271                                                         if (ev.keyCode && ev.keyCode == 13) {
272                                                                 obj.copy_status();
273                                                         }
274                                                 }
275                                         ],
276                                         'cmd_broken' : [
277                                                 ['command'],
278                                                 function() { alert('Not Yet Implemented'); }
279                                         ],
280                                         'cmd_copy_status_submit_barcode' : [
281                                                 ['command'],
282                                                 function() {
283                                                         obj.copy_status();
284                                                 }
285                                         ],
286                                         'cmd_copy_status_print' : [
287                                                 ['command'],
288                                                 function() {
289                                                         try {
290                                                                 obj.list.on_all_fleshed =
291                                                                         function() {
292                                                                                 try {
293                                                                                         dump( js2JSON( obj.list.dump_with_keys() ) + '\n' );
294                                                                                         obj.data.stash_retrieve();
295                                                                                         var lib = obj.data.hash.aou[ obj.data.list.au[0].ws_ou() ];
296                                                                                         lib.children(null);
297                                                                                         var p = { 
298                                                                                                 'lib' : lib,
299                                                                                                 'staff' : obj.data.list.au[0],
300                                                                                                 'header' : obj.data.print_list_templates.item_status.header,
301                                                                                                 'line_item' : obj.data.print_list_templates.item_status.line_item,
302                                                                                                 'footer' : obj.data.print_list_templates.item_status.footer,
303                                                                                                 'type' : obj.data.print_list_templates.item_status.type,
304                                                                                                 'list' : obj.list.dump_with_keys(),
305                                                                                         };
306                                                                                         JSAN.use('util.print'); var print = new util.print();
307                                                                                         print.tree_list( p );
308                                                                                         setTimeout(function(){ obj.list.on_all_fleshed = null; },0);
309                                                                                 } catch(E) {
310                                                                                         obj.error.standard_unexpected_error_alert('print',E); 
311                                                                                 }
312                                                                         }
313                                                                 obj.list.full_retrieve();
314                                                         } catch(E) {
315                                                                 obj.error.standard_unexpected_error_alert('print',E); 
316                                                         }
317                                                 }
318                                         ],
319                                         'cmd_copy_status_export' : [
320                                                 ['command'],
321                                                 function() {
322                                                         try {
323                                                                 obj.list.on_all_fleshed =
324                                                                         function() {
325                                                                                 try {
326                                                                                         dump( obj.list.dump_csv() + '\n' );
327                                                                                         copy_to_clipboard(obj.list.dump_csv());
328                                                                                         setTimeout(function(){ obj.list.on_all_fleshed = null; },0);
329                                                                                 } catch(E) {
330                                                                                         obj.error.standard_unexpected_error_alert('export',E); 
331                                                                                 }
332                                                                         }
333                                                                 obj.list.full_retrieve();
334                                                         } catch(E) {
335                                                                 obj.error.standard_unexpected_error_alert('export',E); 
336                                                         }
337                                                 }
338                                         ],
339                                         'cmd_copy_status_print_export' : [
340                                                 ['command'],
341                                                 function() {
342                                                         try {
343                                                                 obj.list.on_all_fleshed =
344                                                                         function() {
345                                                                                 try {
346                                                                                         dump( obj.list.dump_csv() + '\n' );
347                                                                                         //copy_to_clipboard(obj.list.dump_csv());
348                                                                                         JSAN.use('util.print'); var print = new util.print();
349                                                                                         print.simple(obj.list.dump_csv(),{'content_type':'text/plain'});
350                                                                                         setTimeout(function(){ obj.list.on_all_fleshed = null; },0);
351                                                                                 } catch(E) {
352                                                                                         obj.error.standard_unexpected_error_alert('export',E); 
353                                                                                 }
354                                                                         }
355                                                                 obj.list.full_retrieve();
356                                                         } catch(E) {
357                                                                 obj.error.standard_unexpected_error_alert('export',E); 
358                                                         }
359                                                 }
360                                         ],
361
362                                         'cmd_add_items' : [
363                                                 ['command'],
364                                                 function() {
365                                                         try {
366
367                                                                 JSAN.use('util.functional');
368                                                                 var list = util.functional.map_list( obj.selection_list, function(o) { return o.acn_id; } );
369                                                                 if (list.length == 0) return;
370
371                                                                 var copy_shortcut = {}; var map_acn = {};
372
373                                                                 for (var i = 0; i < list.length; i++) {
374                                                                         var volume_id = list[i];
375                                                                         if (volume_id == -1) continue; /* ignore magic pre-cat volume */
376                                                                         if (! map_acn[volume_id]) {
377                                                                                 map_acn[ volume_id ] = obj.network.simple_request('FM_ACN_RETRIEVE',[ volume_id ]);
378                                                                         }
379                                                                         var record_id = map_acn[ volume_id ].record();
380                                                                         var ou_id = map_acn[ volume_id ].owning_lib();
381                                                                         var label = map_acn[ volume_id ].label();
382                                                                         if (!copy_shortcut[record_id]) copy_shortcut[record_id] = {};
383                                                                         if (!copy_shortcut[record_id][ou_id]) copy_shortcut[record_id][ou_id] = {};
384                                                                         copy_shortcut[record_id][ou_id][ label ] = volume_id;
385
386                                                                 }
387
388                                                                 for (var r in copy_shortcut) {
389
390                                                                         /* quick fix */  /* what was this fixing? */
391                                                                         list = []; for (var i in copy_shortcut[r]) { list.push( i ); }
392
393                                                                         var edit = 0;
394                                                                         try {
395                                                                                 edit = obj.network.request(
396                                                                                         api.PERM_MULTI_ORG_CHECK.app,
397                                                                                         api.PERM_MULTI_ORG_CHECK.method,
398                                                                                         [ 
399                                                                                                 ses(), 
400                                                                                                 obj.data.list.au[0].id(), 
401                                                                                                 list,
402                                                                                                 [ 'CREATE_COPY' ]
403                                                                                         ]
404                                                                                 ).length == 0 ? 1 : 0;
405                                                                         } catch(E) {
406                                                                                 obj.error.sdump('D_ERROR','batch permission check: ' + E);
407                                                                         }
408         
409                                                                         if (edit==0) return; // no read-only view for this interface
410         
411                                                                         var title = 'Add Item for record #' + r;
412         
413                                                                         JSAN.use('util.window'); var win = new util.window();
414                                                                         var w = win.open(
415                                                                                 window.xulG.url_prefix(urls.XUL_VOLUME_COPY_CREATOR)
416                                                                                         +'?doc_id=' + window.escape(r)
417                                                                                         +'&ou_ids=' + window.escape( js2JSON(list) )
418                                                                                         +'&copy_shortcut=' + window.escape( js2JSON(copy_shortcut[r]) ),
419                                                                                 title,
420                                                                                 'chrome,resizable'
421                                                                         );
422                                                                 }
423
424                                                         } catch(E) {
425                                                                 obj.error.standard_unexpected_error_alert('copy status -> add copies',E);
426                                                         }
427                                                 }
428
429                                         ],
430                                         'cmd_delete_items' : [
431                                                 ['command'],
432                                                 function() {
433                                                         try {
434
435                                 JSAN.use('util.functional');
436
437                                                                 var list = util.functional.map_list( obj.selection_list, function(o) { return o.copy_id; } );
438
439                                 var copies = util.functional.map_list(
440                                     list,
441                                     function (acp_id) {
442                                         return obj.network.simple_request('FM_ACP_RETRIEVE',[acp_id]);
443                                     }
444                                 );
445
446                                 for (var i = 0; i < copies.length; i++) {
447                                     copies[i].ischanged(1);
448                                     copies[i].isdeleted(1);
449                                 }
450
451                                                                 if (! window.confirm('Are you sure sure you want to delete these items? ' + util.functional.map_list( copies, function(o) { return o.barcode(); }).join(", ")) ) return;
452
453                                 var robj = obj.network.simple_request('FM_ACP_FLESHED_BATCH_UPDATE',[ ses(), copies, true]);
454                                                                 var robj = obj.network.simple_request(
455                                                                         'FM_ACP_FLESHED_BATCH_UPDATE', 
456                                                                         [ ses(), copies, true ], 
457                                                                         null,
458                                                                         {
459                                                                                 'title' : 'Override Delete Failure?',
460                                                                                 'overridable_events' : [
461                                                                                         1208 /* TITLE_LAST_COPY */,
462                                                                                         1227 /* COPY_DELETE_WARNING */,
463                                                                                 ]
464                                                                         }
465                                                                 );
466         
467                                 if (typeof robj.ilsevent != 'undefined') {
468                                                                         switch(robj.ilsevent) {
469                                                                                 case 1208 /* TITLE_LAST_COPY */:
470                                                                                 case 1227 /* COPY_DELETE_WARNING */:
471                                                                                 break;
472                                                                                 default:
473                                                                                         obj.error.standard_unexpected_error_alert('Batch Item Deletion',robj);
474                                                                                 break;
475                                                                         }
476                                                                 } else { alert('Items Deleted'); }
477
478                                                         } catch(E) {
479                                                                 obj.error.standard_unexpected_error_alert('copy status -> delete items',E);
480                                                         }
481                                                 }
482                                         ],
483                                         'cmd_transfer_items' : [
484                                                 ['command'],
485                                                 function() {
486                                                                 try {
487                                                                         obj.data.stash_retrieve();
488                                                                         if (!obj.data.marked_volume) {
489                                                                                 alert('Please mark a volume as the destination and then try this again.');
490                                                                                 return;
491                                                                         }
492                                                                         
493                                                                         JSAN.use('util.functional');
494
495                                                                         var list = util.functional.map_list( obj.selection_list, function(o) { return o.copy_id; } );
496
497                                                                         var volume = obj.network.simple_request('FM_ACN_RETRIEVE',[ obj.data.marked_volume ]);
498
499                                                                         JSAN.use('cat.util'); cat.util.transfer_copies( { 
500                                                                                 'copy_ids' : list, 
501                                                                                 'docid' : volume.record(),
502                                                                                 'volume_label' : volume.label(),
503                                                                                 'owning_lib' : volume.owning_lib(),
504                                                                         } );
505
506                                                                 } catch(E) {
507                                                                         obj.error.standard_unexpected_error_alert('All copies not likely transferred.',E);
508                                                                 }
509                                                         }
510
511                                         ],
512                                         'cmd_add_volumes' : [
513                                                 ['command'],
514                                                 function() {
515                                                         try {
516                                                                 JSAN.use('util.functional');
517                                                                 var list = util.functional.map_list( obj.selection_list, function(o) { return o.acn_id; } );
518                                                                 if (list.length == 0) return;
519
520                                                                 var aou_hash = {}; var map_acn = {};
521
522                                                                 for (var i = 0; i < list.length; i++) {
523                                                                         var volume_id = list[i];
524                                                                         if (volume_id == -1) continue; /* ignore magic pre-cat volume */
525                                                                         if (! map_acn[volume_id]) {
526                                                                                 map_acn[ volume_id ] = obj.network.simple_request('FM_ACN_RETRIEVE',[ volume_id ]);
527                                                                         }
528                                                                         var record_id = map_acn[ volume_id ].record();
529                                                                         var ou_id = map_acn[ volume_id ].owning_lib();
530                                                                         var label = map_acn[ volume_id ].label();
531                                                                         if (!aou_hash[record_id]) aou_hash[record_id] = {};
532                                                                         aou_hash[record_id][ou_id] = 1;
533
534                                                                 }
535
536                                                                 for (var r in aou_hash) {
537
538                                                                         list = []; for (var org in aou_hash[r]) list.push(org);
539
540                                                                         var edit = 0;
541                                                                         try {
542                                                                                 edit = obj.network.request(
543                                                                                         api.PERM_MULTI_ORG_CHECK.app,
544                                                                                         api.PERM_MULTI_ORG_CHECK.method,
545                                                                                         [ 
546                                                                                                 ses(), 
547                                                                                                 obj.data.list.au[0].id(), 
548                                                                                                 list,
549                                                                                                 [ 'CREATE_VOLUME', 'CREATE_COPY' ]
550                                                                                         ]
551                                                                                 ).length == 0 ? 1 : 0;
552                                                                         } catch(E) {
553                                                                                 obj.error.sdump('D_ERROR','batch permission check: ' + E);
554                                                                         }
555
556                                                                         if (edit==0) {
557                                                                                 alert("You don't have permission to add volumes to that library.");
558                                                                                 return; // no read-only view for this interface
559                                                                         }
560
561                                                                         var title = 'Add Volume/Item for Record # ' + r;
562
563                                                                         JSAN.use('util.window'); var win = new util.window();
564                                                                         var w = win.open(
565                                                                                 window.xulG.url_prefix(urls.XUL_VOLUME_COPY_CREATOR)
566                                                                                         +'?doc_id=' + window.escape(r)
567                                                                                         +'&ou_ids=' + window.escape( js2JSON(list) ),
568                                                                                 title,
569                                                                                 'chrome,resizable'
570                                                                         );
571
572                                                                 }
573
574                                                         } catch(E) {
575                                                                 obj.error.standard_unexpected_error_alert('copy status -> add volumes',E);
576                                                         }
577                                                 }
578
579                                         ],
580                                         'cmd_edit_volumes' : [
581                                                 ['command'],
582                                                 function() {
583                                                         try {
584                                                                 JSAN.use('util.functional');
585                                                                 var list = util.functional.map_list( obj.selection_list, function(o) { return o.acn_id; } );
586                                                                 if (list.length == 0) return;
587
588                                                                 var volume_hash = {}; var map_acn = {};
589
590                                                                 for (var i = 0; i < list.length; i++) {
591                                                                         var volume_id = list[i];
592                                                                         if (volume_id == -1) continue; /* ignore magic pre-cat volume */
593                                                                         if (! map_acn[volume_id]) {
594                                                                                 map_acn[ volume_id ] = obj.network.simple_request('FM_ACN_RETRIEVE',[ volume_id ]);
595                                                                                 map_acn[ volume_id ].copies( [] );
596                                                                         }
597                                                                         var record_id = map_acn[ volume_id ].record();
598                                                                         if (!volume_hash[record_id]) volume_hash[record_id] = {};
599                                                                         volume_hash[record_id][volume_id] = 1;
600                                                                 }
601
602                                                                 for (var rec in volume_hash) {
603
604                                                                         list = []; for (var v in volume_hash[rec]) list.push( map_acn[v] );
605
606                                                                         var edit = 0;
607                                                                         try {
608                                                                                 edit = obj.network.request(
609                                                                                         api.PERM_MULTI_ORG_CHECK.app,
610                                                                                         api.PERM_MULTI_ORG_CHECK.method,
611                                                                                         [ 
612                                                                                                 ses(), 
613                                                                                                 obj.data.list.au[0].id(), 
614                                                                                                 util.functional.map_list(
615                                                                                                         list,
616                                                                                                         function (o) {
617                                                                                                                 return o.owning_lib();
618                                                                                                         }
619                                                                                                 ),
620                                                                                                 [ 'UPDATE_VOLUME' ]
621                                                                                         ]
622                                                                                 ).length == 0 ? 1 : 0;
623                                                                         } catch(E) {
624                                                                                 obj.error.sdump('D_ERROR','batch permission check: ' + E);
625                                                                         }
626
627                                                                         if (edit==0) {
628                                                                                 alert("You don't have permission to edit this volume.");
629                                                                                 return; // no read-only view for this interface
630                                                                         }
631
632                                                                         var title = (list.length == 1 ? 'Volume' : 'Volumes') + ' for record # ' + rec;
633
634                                                                         JSAN.use('util.window'); var win = new util.window();
635                                                                         obj.data.volumes_temp = js2JSON( list );
636                                                                         obj.data.stash('volumes_temp');
637                                                                         var w = win.open(
638                                                                                 window.xulG.url_prefix(urls.XUL_VOLUME_EDITOR),
639                                                                                 title,
640                                                                                 'chrome,modal,resizable'
641                                                                         );
642
643                                                                         /* FIXME -- need to unique the temp space, and not rely on modalness of window */
644                                                                         obj.data.stash_retrieve();
645                                                                         var volumes = JSON2js( obj.data.volumes_temp );
646                                                                         obj.error.sdump('D_CAT','in browse, obj.data.temp =\n' + obj.data.temp);
647                                                                         if (volumes=='') return;
648                                                                 
649                                                                         volumes = util.functional.filter_list(
650                                                                                 volumes,
651                                                                                 function (o) {
652                                                                                         return o.ischanged() == '1';
653                                                                                 }
654                                                                         );
655
656                                                                         volumes = util.functional.map_list(
657                                                                                 volumes,
658                                                                                 function (o) {
659                                                                                         o.record( rec ); // staff client 2 did not do this.  Does it matter?
660                                                                                         return o;
661                                                                                 }
662                                                                         );
663
664                                                                         if (volumes.length == 0) return;
665
666                                                                         try {
667                                                                                 var r = obj.network.request(
668                                                                                         api.FM_ACN_TREE_UPDATE.app,
669                                                                                         api.FM_ACN_TREE_UPDATE.method,
670                                                                                         [ ses(), volumes, false ]
671                                                                                 );
672                                                                                 if (typeof r.ilsevent != 'undefined') throw(r);
673                                                                                 alert('Volumes modified.');
674                                                                         } catch(E) {
675                                                                                 obj.error.standard_unexpected_error_alert('volume update error: ',E);
676                                                                         }
677
678                                                                 }
679                                                         } catch(E) {
680                                                                 obj.error.standard_unexpected_error_alert('Copy Status -> Volume Edit',E);
681                                                         }
682                                                 }
683
684                                         ],
685                                         'cmd_delete_volumes' : [
686                                                 ['command'],
687                                                 function() {
688                                                         try {
689                                                                 JSAN.use('util.functional');
690                                                                 var list = util.functional.map_list( obj.selection_list, function(o) { return o.acn_id; } );
691                                                                 if (list.length == 0) return;
692
693                                                                 var map_acn = {};
694
695                                                                 for (var i = 0; i < list.length; i++) {
696                                                                         var volume_id = list[i];
697                                                                         if (volume_id == -1) continue; /* ignore magic pre-cat volume */
698                                                                         if (! map_acn[volume_id]) {
699                                                                                 map_acn[ volume_id ] = obj.network.simple_request('FM_ACN_RETRIEVE',[ volume_id ]);
700                                                                         }
701                                                                 }
702
703                                                                 list = []; for (var v in map_acn) list.push( map_acn[v] );
704
705                                                                 var r = obj.error.yns_alert('Are you sure you would like to delete ' + (list.length != 1 ? 'these ' + list.length + ' volumes' : 'this one volume') + '?', 'Delete Volumes?', 'Delete', 'Cancel', null, 'Check here to confirm this action');
706
707                                                                 if (r == 0) {
708                                                                         for (var i = 0; i < list.length; i++) {
709                                                                                 list[i].isdeleted('1');
710                                                                         }
711                                                                         var robj = obj.network.simple_request(
712                                                                                 'FM_ACN_TREE_UPDATE', 
713                                                                                 [ ses(), list, true ],
714                                                                                 null,
715                                                                                 {
716                                                                                         'title' : 'Override Delete Failure?',
717                                                                                         'overridable_events' : [
718                                                                                         ]
719                                                                                 }
720                                                                         );
721                                                                         if (robj == null) throw(robj);
722                                                                         if (typeof robj.ilsevent != 'undefined') {
723                                                                                 if (robj.ilsevent == 1206 /* VOLUME_NOT_EMPTY */) {
724                                                                                         alert('You must delete all the copies on the volume before you may delete the volume itself.');
725                                                                                         return;
726                                                                                 }
727                                                                                 if (robj.ilsevent != 0) throw(robj);
728                                                                         }
729                                                                         alert('Volumes deleted.');
730                                                                 }
731                                                         } catch(E) {
732                                                                 obj.error.standard_unexpected_error_alert('copy status -> delete volumes',E);
733                                                         }
734
735                                                 }
736
737                                         ],
738                                         'cmd_mark_volume' : [
739                                                 ['command'],
740                                                 function() {
741                                                         try {
742                                                                 JSAN.use('util.functional');
743                                                                 var list = util.functional.map_list( obj.selection_list, function(o) { return o.acn_id; } );
744
745                                                                 if (list.length == 1) {
746                                                                         obj.data.marked_volume = list[0];
747                                                                         obj.data.stash('marked_volume');
748                                                                         alert('Volume marked as Item Transfer Destination');
749                                                                 } else {
750                                                                         obj.error.yns_alert('Choose just one Volume to mark as Item Transfer Destination','Limit Selection','OK',null,null,'Check here to confirm this dialog');
751                                                                 }
752                                                         } catch(E) {
753                                                                 obj.error.standard_unexpected_error_alert('copy status -> mark volume',E);
754                                                         }
755                                                 }
756                                         ],
757                                         'cmd_mark_library' : [
758                                                 ['command'],
759                                                 function() {
760                                                         try {
761                                                                 JSAN.use('util.functional');
762                                                                 var list = util.functional.map_list( obj.selection_list, function(o) { return o.acn_id; } );
763
764                                                                 if (list.length == 1) {
765                                                                         var v = obj.network.simple_request('FM_ACN_RETRIEVE',[list[0]]);
766                                                                         var owning_lib = v.owning_lib(); if (typeof owning_lib == 'object') owning_lib = owning_lib.id();
767
768                                                                         obj.data.marked_library = { 'lib' : owning_lib, 'docid' : v.record() };
769                                                                         obj.data.stash('marked_library');
770                                                                         alert('Library + Record marked as Volume Transfer Destination');
771                                                                 } else {
772                                                                         obj.error.yns_alert('Choose just one Library to mark as Volume Transfer Destination','Limit Selection','OK',null,null,'Check here to confirm this dialog');
773                                                                 }
774                                                         } catch(E) {
775                                                                 obj.error.standard_unexpected_error_alert('copy status -> mark library',E);
776                                                         }
777                                                 }
778                                         ],
779                                         'cmd_transfer_volume' : [
780                                                 ['command'],
781                                                 function() {
782                                                         try {
783                                                                         obj.data.stash_retrieve();
784                                                                         if (!obj.data.marked_library) {
785                                                                                 alert('Please mark a library as the destination from within holdings maintenance and then try this again.');
786                                                                                 return;
787                                                                         }
788                                                                         
789                                                                         JSAN.use('util.functional');
790
791                                                                         var list = util.functional.map_list( obj.selection_list, function(o) { return o.acn_id; } );
792                                                                         if (list.length == 0) return;
793
794                                                                         var map_acn = {};
795
796                                                                         for (var i = 0; i < list.length; i++) {
797                                                                                 var volume_id = list[i];
798                                                                                 if (volume_id == -1) continue; /* ignore magic pre-cat volume */
799                                                                                 if (! map_acn[volume_id]) {
800                                                                                         map_acn[ volume_id ] = obj.network.simple_request('FM_ACN_RETRIEVE',[ volume_id ]);
801                                                                                 }
802                                                                         }
803
804                                                                         list = []; for (v in map_acn) list.push(map_acn[v]);
805
806                                                                         netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect UniversalBrowserWrite');
807                                                                         var xml = '<vbox xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" flex="1" style="overflow: auto">';
808                                                                         xml += '<description>Transfer volumes ';
809
810                                                                         xml += util.functional.map_list(
811                                                                                 list,
812                                                                                 function (o) {
813                                                                                         return o.label();
814                                                                                 }
815                                                                         ).join(", ");
816
817                                                                         xml += ' to library ' + obj.data.hash.aou[ obj.data.marked_library.lib ].shortname();
818                                                                         xml += ' on the following record?</description>';
819                                                                         xml += '<hbox><button label="Transfer" name="fancy_submit"/>';
820                                                                         xml += '<button label="Cancel" accesskey="C" name="fancy_cancel"/></hbox>';
821                                                                         xml += '<iframe style="overflow: scroll" flex="1" src="' + urls.XUL_BIB_BRIEF + '?docid=' + obj.data.marked_library.docid + '"/>';
822                                                                         xml += '</vbox>';
823                                                                         JSAN.use('OpenILS.data');
824                                                                         var data = new OpenILS.data(); data.init({'via':'stash'});
825                                                                         data.temp_transfer = xml; data.stash('temp_transfer');
826                                                                         window.open(
827                                                                                 urls.XUL_FANCY_PROMPT
828                                                                                 + '?xml_in_stash=temp_transfer'
829                                                                                 + '&title=' + window.escape('Volume Transfer'),
830                                                                                 'fancy_prompt', 'chrome,resizable,modal,width=500,height=300'
831                                                                         );
832                                                                 
833                                                                         data.init({'via':'stash'});
834                                                                         if (data.fancy_prompt_data == '') { alert('Transfer Aborted'); return; }
835
836                                                                         var robj = obj.network.simple_request(
837                                                                                 'FM_ACN_TRANSFER', 
838                                                                                 [ ses(), { 'docid' : obj.data.marked_library.docid, 'lib' : obj.data.marked_library.lib, 'volumes' : util.functional.map_list( list, function(o) { return o.id(); }) } ],
839                                                                                 null,
840                                                                                 {
841                                                                                         'title' : 'Override Volume Transfer Failure?',
842                                                                                         'overridable_events' : [
843                                                                                                 1208 /* TITLE_LAST_COPY */,
844                                                                                                 1219 /* COPY_REMOTE_CIRC_LIB */,
845                                                                                         ],
846                                                                                 }
847                                                                         );
848
849                                                                         if (typeof robj.ilsevent != 'undefined') {
850                                                                                 if (robj.ilsevent == 1221 /* ORG_CANNOT_HAVE_VOLS */) {
851                                                                                         alert('That destination cannot have volumes.');
852                                                                                 } else {
853                                                                                         throw(robj);
854                                                                                 }
855                                                                         } else {
856                                                                                 alert('Volumes transferred.');
857                                                                         }
858
859                                                         } catch(E) {
860                                                                 obj.error.standard_unexpected_error_alert('All volumes not likely transferred.',E);
861                                                         }
862                                                 }
863
864                                         ],
865                                 }
866                         }
867                 );
868                 this.controller.render();
869                 this.controller.view.copy_status_barcode_entry_textbox.focus();
870
871         },
872
873         'test_barcode' : function(bc) {
874                 var obj = this;
875                 var good = util.barcode.check(bc);
876                 var x = document.getElementById('strict_barcode');
877                 if (x && x.checked != true) return true;
878                 if (good) {
879                         return true;
880                 } else {
881                         if ( 1 == obj.error.yns_alert(
882                                                 'Bad checkdigit; possible mis-scan.  Use this barcode ("' + bc + '") anyway?',
883                                                 'Bad Barcode',
884                                                 'Cancel',
885                                                 'Accept Barcode',
886                                                 null,
887                                                 'Check here to confirm this action',
888                                                 '/xul/server/skin/media/images/bad_barcode.png'
889                         ) ) {
890                                 return true;
891                         } else {
892                                 return false;
893                         }
894                 }
895         },
896
897         'copy_status' : function(barcode) {
898                 var obj = this;
899                 try {
900                         try { document.getElementById('last_scanned').setAttribute('value',''); } catch(E) {}
901                         if (!barcode) barcode = obj.controller.view.copy_status_barcode_entry_textbox.value;
902                         if (!barcode) return;
903                         if (barcode) {
904                                 if ( obj.test_barcode(barcode) ) { /* good */ } else { /* bad */ return; }
905                         }
906                         JSAN.use('circ.util');
907                         obj.network.simple_request('FM_ACP_DETAILS_VIA_BARCODE', [ ses(), barcode ], function(req) {
908                                 try {
909                                         var details = req.getResultObject();
910                                         if (details == null) {
911                                                 throw('Something weird happened.  null result');
912                                         } else if (details.ilsevent) {
913                                                 switch(details.ilsevent) {
914                                                         case -1: 
915                                                                 obj.error.standard_network_error_alert(); 
916                                                                 obj.controller.view.copy_status_barcode_entry_textbox.select();
917                                                                 obj.controller.view.copy_status_barcode_entry_textbox.focus();
918                                                                 return;
919                                                         break;
920                                                         case 1502 /* ASSET_COPY_NOT_FOUND */ :
921                                                                 try { document.getElementById('last_scanned').setAttribute('value',barcode + ' was either mis-scanned or is not cataloged.'); } catch(E) {}
922                                                                 obj.error.yns_alert(barcode + ' was either mis-scanned or is not cataloged.','Not Cataloged','OK',null,null,'Check here to confirm this message');
923                                                                 obj.controller.view.copy_status_barcode_entry_textbox.select();
924                                                                 obj.controller.view.copy_status_barcode_entry_textbox.focus();
925                                                                 return;
926                                                         break;
927                                                         default: 
928                                                                 throw(details); 
929                                                         break;
930                                                 }
931                                         }
932                                         var msg = details.copy.barcode() + ' -- ';
933                                         if (details.copy.call_number() == -1) msg += 'Item is a Pre-Cat.  ';
934                                         if (details.hold) msg += 'Item is captured for a Hold.  ';
935                                         if (details.transit) msg += 'Item is in Transit.  ';
936                                         if (details.circ && ! details.circ.checkin_time()) msg += 'Item is circulating.  ';
937                                         try { document.getElementById('last_scanned').setAttribute('value',msg); } catch(E) {}
938                                         if (document.getElementById('trim_list')) {
939                                                 var x = document.getElementById('trim_list');
940                                                 if (x.checked) { obj.list.trim_list = 20; } else { obj.list.trim_list = null; }
941                                         }
942                                         obj.list.append(
943                                                 {
944                                                         'retrieve_id' : js2JSON( 
945                                                                 { 
946                                                                         'renewable' : details.circ ? 't' : 'f', 
947                                                                         'copy_id' : details.copy.id(), 
948                                                                         'acn_id' : details.volume ? details.volume.id() : -1, 
949                                                                         'barcode' : barcode, 
950                                                                         'doc_id' : details.mvr ? details.mvr.doc_id() : null  
951                                                                 } 
952                                                         ),
953                                                         'row' : {
954                                                                 'my' : {
955                                                                         'mvr' : details.mvr,
956                                                                         'acp' : details.copy,
957                                                                         'acn' : details.volume,
958                                                                         'atc' : details.transit,
959                                                                         'circ' : details.circ,
960                                                                         'ahr' : details.hold,
961                                                                 }
962                                                         },
963                                                         'to_top' : true,
964                                                 }
965                                         );
966                                 } catch(E) {
967                                         obj.error.standard_unexpected_error_alert('',E);
968                                 }
969                         } );
970                         obj.controller.view.copy_status_barcode_entry_textbox.value = '';
971                         obj.controller.view.copy_status_barcode_entry_textbox.focus();
972                         
973                 } catch(E) {
974                         obj.error.standard_unexpected_error_alert('',E);
975                         obj.controller.view.copy_status_barcode_entry_textbox.select();
976                         obj.controller.view.copy_status_barcode_entry_textbox.focus();
977                 }
978
979         },
980         
981         'spawn_copy_editor' : function() {
982
983                 /* FIXME -  a lot of redundant calls here */
984
985                 var obj = this;
986
987                 JSAN.use('util.widgets'); JSAN.use('util.functional');
988
989                 var list = obj.selection_list;
990
991                 list = util.functional.map_list(
992                         list,
993                         function (o) {
994                                 return o.copy_id;
995                         }
996                 );
997
998                 var copies = util.functional.map_list(
999                         list,
1000                         function (acp_id) {
1001                                 return obj.network.simple_request('FM_ACP_RETRIEVE',[acp_id]);
1002                         }
1003                 );
1004
1005                 var edit = 0;
1006                 try {
1007                         edit = obj.network.request(
1008                                 api.PERM_MULTI_ORG_CHECK.app,
1009                                 api.PERM_MULTI_ORG_CHECK.method,
1010                                 [ 
1011                                         ses(), 
1012                                         obj.data.list.au[0].id(), 
1013                                         util.functional.map_list(
1014                                                 copies,
1015                                                 function (o) {
1016                                                         return o.call_number() == -1 ? o.circ_lib() : obj.network.simple_request('FM_ACN_RETRIEVE',[o.call_number()]).owning_lib();
1017                                                 }
1018                                         ),
1019                                         copies.length == 1 ? [ 'UPDATE_COPY' ] : [ 'UPDATE_COPY', 'UPDATE_BATCH_COPY' ]
1020                                 ]
1021                         ).length == 0 ? 1 : 0;
1022                 } catch(E) {
1023                         obj.error.sdump('D_ERROR','batch permission check: ' + E);
1024                 }
1025
1026                 JSAN.use('cat.util'); cat.util.spawn_copy_editor(list,edit);
1027
1028         },
1029
1030 }
1031
1032 dump('exiting circ.copy_status.js\n');