]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/xul/staff_client/server/circ/copy_status.js
option for auto-pruning lists
[working/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.date');
9         JSAN.use('OpenILS.data'); this.data = new OpenILS.data(); this.data.init({'via':'stash'});
10 }
11
12 circ.copy_status.prototype = {
13         'selection_list' : [],
14
15         'init' : function( params ) {
16
17                 var obj = this;
18
19                 JSAN.use('circ.util');
20                 var columns = circ.util.columns( 
21                         { 
22                                 'barcode' : { 'hidden' : false },
23                                 'title' : { 'hidden' : false },
24                                 'location' : { 'hidden' : false },
25                                 'call_number' : { 'hidden' : false },
26                                 'status' : { 'hidden' : false },
27                                 'alert_message' : { 'hidden' : false },
28                                 'due_date' : { 'hidden' : false },
29                         },
30                         {
31                                 'except_these' : [
32                                         'checkin_time', 'checkin_time_full', 'route_to', 'message', 'uses', 'xact_finish',
33                                 ],
34                         }
35                 );
36
37                 JSAN.use('util.list'); obj.list = new util.list('copy_status_list');
38                 obj.list.init(
39                         {
40                                 'columns' : columns,
41                                 'map_row_to_column' : circ.util.std_map_row_to_column(),
42                                 'on_select' : function(ev) {
43                                         try {
44                                                 JSAN.use('util.functional');
45                                                 var sel = obj.list.retrieve_selection();
46                                                 obj.selection_list = util.functional.map_list(
47                                                         sel,
48                                                         function(o) { return JSON2js(o.getAttribute('retrieve_id')); }
49                                                 );
50                                                 obj.error.sdump('D_TRACE','circ/copy_status: selection list = ' + js2JSON(obj.selection_list) );
51                                                 if (obj.selection_list.length == 0) {
52                                                         obj.controller.view.sel_checkin.setAttribute('disabled','true');
53                                                         obj.controller.view.cmd_replace_barcode.setAttribute('disabled','true');
54                                                         obj.controller.view.sel_edit.setAttribute('disabled','true');
55                                                         obj.controller.view.sel_opac.setAttribute('disabled','true');
56                                                         obj.controller.view.sel_bucket.setAttribute('disabled','true');
57                                                         obj.controller.view.sel_copy_details.setAttribute('disabled','true');
58                                                         obj.controller.view.sel_mark_items_damaged.setAttribute('disabled','true');
59                                                         obj.controller.view.sel_mark_items_missing.setAttribute('disabled','true');
60                                                         obj.controller.view.sel_patron.setAttribute('disabled','true');
61                                                         obj.controller.view.sel_spine.setAttribute('disabled','true');
62                                                         obj.controller.view.sel_transit_abort.setAttribute('disabled','true');
63                                                         obj.controller.view.sel_clip.setAttribute('disabled','true');
64                                                         obj.controller.view.sel_renew.setAttribute('disabled','true');
65                                                 } else {
66                                                         obj.controller.view.sel_checkin.setAttribute('disabled','false');
67                                                         obj.controller.view.cmd_replace_barcode.setAttribute('disabled','false');
68                                                         obj.controller.view.sel_edit.setAttribute('disabled','false');
69                                                         obj.controller.view.sel_opac.setAttribute('disabled','false');
70                                                         obj.controller.view.sel_patron.setAttribute('disabled','false');
71                                                         obj.controller.view.sel_bucket.setAttribute('disabled','false');
72                                                         obj.controller.view.sel_copy_details.setAttribute('disabled','false');
73                                                         obj.controller.view.sel_mark_items_damaged.setAttribute('disabled','false');
74                                                         obj.controller.view.sel_mark_items_missing.setAttribute('disabled','false');
75                                                         obj.controller.view.sel_spine.setAttribute('disabled','false');
76                                                         obj.controller.view.sel_transit_abort.setAttribute('disabled','false');
77                                                         obj.controller.view.sel_clip.setAttribute('disabled','false');
78                                                         obj.controller.view.sel_renew.setAttribute('disabled','false');
79                                                 }
80                                         } catch(E) {
81                                                 alert('FIXME: ' + E);
82                                         }
83                                 },
84                         }
85                 );
86                 
87                 JSAN.use('util.controller'); obj.controller = new util.controller();
88                 obj.controller.init(
89                         {
90                                 'control_map' : {
91                                         'save_columns' : [ [ 'command' ], function() { obj.list.save_columns(); } ],
92                                         'sel_clip' : [
93                                                 ['command'],
94                                                 function() { obj.list.clipboard(); }
95                                         ],
96                                         'sel_checkin' : [
97                                                 ['command'],
98                                                 function() {
99                                                         try {
100                                                                 var funcs = [];
101                                                                 JSAN.use('circ.util');
102                                                                 for (var i = 0; i < obj.selection_list.length; i++) {
103                                                                         var barcode = obj.selection_list[i].barcode;
104                                                                         var checkin = circ.util.checkin_via_barcode( ses(), barcode );
105                                                                         funcs.push( function(a) { return function() { obj.copy_status( a ); }; }(barcode) );
106                                                                 }
107                                                                 alert('Action complete.');
108                                                                 for (var i = 0; i < funcs.length; i++) { funcs[i](); }
109                                                         } catch(E) {
110                                                                 obj.error.standard_unexpected_error_alert('Checkin did not likely happen.',E);
111                                                         }
112                                                 }
113                                         ],
114                                         'cmd_replace_barcode' : [
115                                                 ['command'],
116                                                 function() {
117                                                         try {
118                                                                 var funcs = [];
119                                                                 JSAN.use('cat.util');
120                                                                 for (var i = 0; i < obj.selection_list.length; i++) {
121                                                                         try { 
122                                                                                 var barcode = obj.selection_list[i].barcode;
123                                                                                 var new_bc = cat.util.replace_barcode( barcode );
124                                                                                 funcs.push( function(a) { return function() { obj.copy_status( a ); }; }(new_bc) );
125                                                                         } catch(E) {
126                                                                                 obj.error.standard_unexpected_error_alert('Barcode ' + barcode + ' was not likely replaced.',E);
127                                                                         }
128                                                                 }
129                                                                 alert('Action complete.');
130                                                                 for (var i = 0; i < funcs.length; i++) { funcs[i](); }
131                                                         } catch(E) {
132                                                                 obj.error.standard_unexpected_error_alert('Barcode replacements did not likely happen.',E);
133                                                         }
134                                                 }
135                                         ],
136                                         'sel_edit' : [
137                                                 ['command'],
138                                                 function() {
139                                                         try {
140                                                                 var funcs = [];
141                                                                 obj.spawn_copy_editor();
142                                                                 for (var i = 0; i < obj.selection_list.length; i++) {
143                                                                                 var barcode = obj.selection_list[i].barcode;
144                                                                                 funcs.push( function(a) { return function() { obj.copy_status( a ); }; }(barcode) );
145                                                                 }
146                                                                 for (var i = 0; i < funcs.length; i++) { funcs[i](); }
147                                                         } catch(E) {
148                                                                 obj.error.standard_unexpected_error_alert('with copy editor',E);
149                                                         }
150                                                 }
151                                         ],
152                                         'sel_spine' : [
153                                                 ['command'],
154                                                 function() {
155                                                         JSAN.use('cat.util');
156                                                         cat.util.spawn_spine_editor(obj.selection_list);
157                                                 }
158                                         ],
159                                         'sel_opac' : [
160                                                 ['command'],
161                                                 function() {
162                                                         JSAN.use('cat.util');
163                                                         cat.util.show_in_opac(obj.selection_list);
164                                                 }
165                                         ],
166                                         'sel_transit_abort' : [
167                                                 ['command'],
168                                                 function() {
169                                                         var funcs = [];
170                                                         JSAN.use('circ.util');
171                                                         circ.util.abort_transits(obj.selection_list);
172                                                         for (var i = 0; i < obj.selection_list.length; i++) {
173                                                                 var barcode = obj.selection_list[i].barcode;
174                                                                 funcs.push( function(a) { return function() { obj.copy_status( a ); }; }(barcode) );
175                                                         }
176                                                         alert('Action complete.');
177                                                         for (var i = 0; i < funcs.length; i++) { funcs[i](); }
178                                                 }
179                                         ],
180                                         'sel_patron' : [
181                                                 ['command'],
182                                                 function() {
183                                                         JSAN.use('circ.util');
184                                                         circ.util.show_last_few_circs(obj.selection_list);
185                                                 }
186                                         ],
187                                         'sel_copy_details' : [
188                                                 ['command'],
189                                                 function() {
190                                                         JSAN.use('circ.util');
191                                                         for (var i = 0; i < obj.selection_list.length; i++) {
192                                                                 circ.util.show_copy_details( obj.selection_list[i].copy_id );
193                                                         }
194                                                 }
195                                         ],
196                                         'sel_renew' : [
197                                                 ['command'],
198                                                 function() {
199                                                         var funcs = [];
200                                                         JSAN.use('circ.util');
201                                                         for (var i = 0; i < obj.selection_list.length; i++) {
202                                                                 var test = obj.selection_list[i].renewable;
203                                                                 var barcode = obj.selection_list[i].barcode;
204                                                                 if (test == 't') {
205                                                                         circ.util.renew_via_barcode( barcode );
206                                                                         funcs.push( function(a) { return function() { obj.copy_status( a ); }; }(barcode) );
207                                                                 } else {
208                                                                         alert('Item with barcode ' + barcode + ' is not circulating.');
209                                                                 }
210                                                         }
211                                                         alert('Action complete.');
212                                                         for (var i = 0; i < funcs.length; i++) { funcs[i](); }
213                                                 }
214                                         ],
215
216                                         'sel_mark_items_damaged' : [
217                                                 ['command'],
218                                                 function() {
219                                                         var funcs = [];
220                                                         JSAN.use('cat.util'); JSAN.use('util.functional');
221                                                         cat.util.mark_item_damaged( util.functional.map_list( obj.selection_list, function(o) { return o.copy_id; } ) );
222                                                         for (var i = 0; i < obj.selection_list.length; i++) {
223                                                                 var barcode = obj.selection_list[i].barcode;
224                                                                 funcs.push( function(a) { return function() { obj.copy_status( a ); }; }(barcode) );
225                                                         }
226                                                         for (var i = 0; i < funcs.length; i++) { funcs[i](); }
227                                                 }
228                                         ],
229                                         'sel_mark_items_missing' : [
230                                                 ['command'],
231                                                 function() {
232                                                         var funcs = [];
233                                                         JSAN.use('cat.util'); JSAN.use('util.functional');
234                                                         cat.util.mark_item_missing( util.functional.map_list( obj.selection_list, function(o) { return o.copy_id; } ) );
235                                                         for (var i = 0; i < obj.selection_list.length; i++) {
236                                                                 var barcode = obj.selection_list[i].barcode;
237                                                                 funcs.push( function(a) { return function() { obj.copy_status( a ); }; }(barcode) );
238                                                         }
239                                                         for (var i = 0; i < funcs.length; i++) { funcs[i](); }
240                                                 }
241                                         ],
242                                         'sel_bucket' : [
243                                                 ['command'],
244                                                 function() {
245                                                         JSAN.use('cat.util');
246                                                         cat.util.add_copies_to_bucket(obj.selection_list);
247                                                 }
248                                         ],
249                                         'copy_status_barcode_entry_textbox' : [
250                                                 ['keypress'],
251                                                 function(ev) {
252                                                         if (ev.keyCode && ev.keyCode == 13) {
253                                                                 obj.copy_status();
254                                                         }
255                                                 }
256                                         ],
257                                         'cmd_broken' : [
258                                                 ['command'],
259                                                 function() { alert('Not Yet Implemented'); }
260                                         ],
261                                         'cmd_copy_status_submit_barcode' : [
262                                                 ['command'],
263                                                 function() {
264                                                         obj.copy_status();
265                                                 }
266                                         ],
267                                         'cmd_copy_status_print' : [
268                                                 ['command'],
269                                                 function() {
270                                                         try {
271                                                                 obj.list.on_all_fleshed =
272                                                                         function() {
273                                                                                 try {
274                                                                                         dump( js2JSON( obj.list.dump_with_keys() ) + '\n' );
275                                                                                         obj.data.stash_retrieve();
276                                                                                         var lib = obj.data.hash.aou[ obj.data.list.au[0].ws_ou() ];
277                                                                                         lib.children(null);
278                                                                                         var p = { 
279                                                                                                 'lib' : lib,
280                                                                                                 'staff' : obj.data.list.au[0],
281                                                                                                 'header' : obj.data.print_list_templates.item_status.header,
282                                                                                                 'line_item' : obj.data.print_list_templates.item_status.line_item,
283                                                                                                 'footer' : obj.data.print_list_templates.item_status.footer,
284                                                                                                 'type' : obj.data.print_list_templates.item_status.type,
285                                                                                                 'list' : obj.list.dump_with_keys(),
286                                                                                         };
287                                                                                         JSAN.use('util.print'); var print = new util.print();
288                                                                                         print.tree_list( p );
289                                                                                         setTimeout(function(){ obj.list.on_all_fleshed = null; },0);
290                                                                                 } catch(E) {
291                                                                                         obj.error.standard_unexpected_error_alert('print',E); 
292                                                                                 }
293                                                                         }
294                                                                 obj.list.full_retrieve();
295                                                         } catch(E) {
296                                                                 obj.error.standard_unexpected_error_alert('print',E); 
297                                                         }
298                                                 }
299                                         ],
300                                         'cmd_copy_status_reprint' : [
301                                                 ['command'],
302                                                 function() {
303                                                 }
304                                         ],
305                                         'cmd_copy_status_done' : [
306                                                 ['command'],
307                                                 function() {
308                                                 }
309                                         ],
310                                 }
311                         }
312                 );
313                 this.controller.render();
314                 this.controller.view.copy_status_barcode_entry_textbox.focus();
315
316         },
317
318         'copy_status' : function(barcode) {
319                 var obj = this;
320                 try {
321                         if (!barcode) barcode = obj.controller.view.copy_status_barcode_entry_textbox.value;
322                         JSAN.use('circ.util');
323                         var copy = obj.network.simple_request( 'FM_ACP_RETRIEVE_VIA_BARCODE', [ barcode ]);
324                         if (copy == null) {
325                                 throw('Something weird happened.  null result');
326                         } else if (copy.ilsevent) {
327                                 switch(copy.ilsevent) {
328                                         case -1: 
329                                                 obj.error.standard_network_error_alert(); 
330                                                 obj.controller.view.copy_status_barcode_entry_textbox.select();
331                                                 obj.controller.view.copy_status_barcode_entry_textbox.focus();
332                                         break;
333                                         case 1502 /* ASSET_COPY_NOT_FOUND */ :
334                                                 obj.error.yns_alert(barcode + ' was either mis-scanned or is not cataloged.','Not Cataloged','OK',null,null,'Check here to confirm this message');
335                                                 obj.controller.view.copy_status_barcode_entry_textbox.select();
336                                                 obj.controller.view.copy_status_barcode_entry_textbox.focus();
337                                         break;
338                                         default: 
339                                                 throw(copy); 
340                                         break;
341                                 }
342                         } else {
343                                 var my_mvr = obj.network.simple_request('MODS_SLIM_RECORD_RETRIEVE_VIA_COPY', [ copy.id() ]);
344                                 if (document.getElementById('trim_list')) {
345                                         var x = document.getElementById('trim_list');
346                                         if (x.checked) { obj.list.trim_list = 20; } else { obj.list.trim_list = null; }
347                                 }
348                                 obj.list.append(
349                                         {
350                                                 'retrieve_id' : js2JSON( { 'renewable' : copy.circulations() ? 't' : 'f', 'copy_id' : copy.id(), 'barcode' : barcode, 'doc_id' : (typeof my_mvr.ilsevent == 'undefined' ? my_mvr.doc_id() : null ) } ),
351                                                 'row' : {
352                                                         'my' : {
353                                                                 'mvr' : my_mvr,
354                                                                 'acp' : copy,
355                                                         }
356                                                 },
357                                                 'to_top' : true,
358                                         }
359                                 );
360                                 obj.controller.view.copy_status_barcode_entry_textbox.value = '';
361                                 obj.controller.view.copy_status_barcode_entry_textbox.focus();
362                         }
363                 } catch(E) {
364                         obj.error.standard_unexpected_error_alert('',E);
365                         obj.controller.view.copy_status_barcode_entry_textbox.select();
366                         obj.controller.view.copy_status_barcode_entry_textbox.focus();
367                 }
368
369         },
370         
371         'spawn_copy_editor' : function() {
372
373                 /* FIXME -  a lot of redundant calls here */
374
375                 var obj = this;
376
377                 JSAN.use('util.widgets'); JSAN.use('util.functional');
378
379                 var list = obj.selection_list;
380
381                 list = util.functional.map_list(
382                         list,
383                         function (o) {
384                                 return o.copy_id;
385                         }
386                 );
387
388                 var copies = util.functional.map_list(
389                         list,
390                         function (acp_id) {
391                                 return obj.network.simple_request('FM_ACP_RETRIEVE',[acp_id]);
392                         }
393                 );
394
395                 var edit = 0;
396                 try {
397                         edit = obj.network.request(
398                                 api.PERM_MULTI_ORG_CHECK.app,
399                                 api.PERM_MULTI_ORG_CHECK.method,
400                                 [ 
401                                         ses(), 
402                                         obj.data.list.au[0].id(), 
403                                         util.functional.map_list(
404                                                 copies,
405                                                 function (o) {
406                                                         return o.call_number() == -1 ? o.circ_lib() : obj.network.simple_request('FM_ACN_RETRIEVE',[o.call_number()]).owning_lib();
407                                                 }
408                                         ),
409                                         copies.length == 1 ? [ 'UPDATE_COPY' ] : [ 'UPDATE_COPY', 'UPDATE_BATCH_COPY' ]
410                                 ]
411                         ).length == 0 ? 1 : 0;
412                 } catch(E) {
413                         obj.error.sdump('D_ERROR','batch permission check: ' + E);
414                 }
415
416                 JSAN.use('cat.util'); cat.util.spawn_copy_editor(list,edit);
417
418         },
419
420 }
421
422 dump('exiting circ.copy_status.js\n');