]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/xul/staff_client/server/circ/copy_status.js
strict barcode toggle
[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.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                                                 } else {
67                                                         obj.controller.view.sel_checkin.setAttribute('disabled','false');
68                                                         obj.controller.view.cmd_replace_barcode.setAttribute('disabled','false');
69                                                         obj.controller.view.sel_edit.setAttribute('disabled','false');
70                                                         obj.controller.view.sel_opac.setAttribute('disabled','false');
71                                                         obj.controller.view.sel_patron.setAttribute('disabled','false');
72                                                         obj.controller.view.sel_bucket.setAttribute('disabled','false');
73                                                         obj.controller.view.sel_copy_details.setAttribute('disabled','false');
74                                                         obj.controller.view.sel_mark_items_damaged.setAttribute('disabled','false');
75                                                         obj.controller.view.sel_mark_items_missing.setAttribute('disabled','false');
76                                                         obj.controller.view.sel_spine.setAttribute('disabled','false');
77                                                         obj.controller.view.sel_transit_abort.setAttribute('disabled','false');
78                                                         obj.controller.view.sel_clip.setAttribute('disabled','false');
79                                                         obj.controller.view.sel_renew.setAttribute('disabled','false');
80                                                 }
81                                         } catch(E) {
82                                                 alert('FIXME: ' + E);
83                                         }
84                                 },
85                         }
86                 );
87                 
88                 JSAN.use('util.controller'); obj.controller = new util.controller();
89                 obj.controller.init(
90                         {
91                                 'control_map' : {
92                                         'save_columns' : [ [ 'command' ], function() { obj.list.save_columns(); } ],
93                                         'sel_clip' : [
94                                                 ['command'],
95                                                 function() { obj.list.clipboard(); }
96                                         ],
97                                         'sel_checkin' : [
98                                                 ['command'],
99                                                 function() {
100                                                         try {
101                                                                 var funcs = [];
102                                                                 JSAN.use('circ.util');
103                                                                 for (var i = 0; i < obj.selection_list.length; i++) {
104                                                                         var barcode = obj.selection_list[i].barcode;
105                                                                         var checkin = circ.util.checkin_via_barcode( ses(), { 'barcode' : barcode } );
106                                                                         funcs.push( function(a) { return function() { obj.copy_status( a ); }; }(barcode) );
107                                                                 }
108                                                                 alert('Action complete.');
109                                                                 for (var i = 0; i < funcs.length; i++) { funcs[i](); }
110                                                         } catch(E) {
111                                                                 obj.error.standard_unexpected_error_alert('Checkin did not likely happen.',E);
112                                                         }
113                                                 }
114                                         ],
115                                         'cmd_replace_barcode' : [
116                                                 ['command'],
117                                                 function() {
118                                                         try {
119                                                                 var funcs = [];
120                                                                 JSAN.use('cat.util');
121                                                                 for (var i = 0; i < obj.selection_list.length; i++) {
122                                                                         try { 
123                                                                                 var barcode = obj.selection_list[i].barcode;
124                                                                                 var new_bc = cat.util.replace_barcode( barcode );
125                                                                                 funcs.push( function(a) { return function() { obj.copy_status( a ); }; }(new_bc) );
126                                                                         } catch(E) {
127                                                                                 obj.error.standard_unexpected_error_alert('Barcode ' + barcode + ' was not likely replaced.',E);
128                                                                         }
129                                                                 }
130                                                                 alert('Action complete.');
131                                                                 for (var i = 0; i < funcs.length; i++) { funcs[i](); }
132                                                         } catch(E) {
133                                                                 obj.error.standard_unexpected_error_alert('Barcode replacements did not likely happen.',E);
134                                                         }
135                                                 }
136                                         ],
137                                         'sel_edit' : [
138                                                 ['command'],
139                                                 function() {
140                                                         try {
141                                                                 var funcs = [];
142                                                                 obj.spawn_copy_editor();
143                                                                 for (var i = 0; i < obj.selection_list.length; i++) {
144                                                                                 var barcode = obj.selection_list[i].barcode;
145                                                                                 funcs.push( function(a) { return function() { obj.copy_status( a ); }; }(barcode) );
146                                                                 }
147                                                                 for (var i = 0; i < funcs.length; i++) { funcs[i](); }
148                                                         } catch(E) {
149                                                                 obj.error.standard_unexpected_error_alert('with copy editor',E);
150                                                         }
151                                                 }
152                                         ],
153                                         'sel_spine' : [
154                                                 ['command'],
155                                                 function() {
156                                                         JSAN.use('cat.util');
157                                                         cat.util.spawn_spine_editor(obj.selection_list);
158                                                 }
159                                         ],
160                                         'sel_opac' : [
161                                                 ['command'],
162                                                 function() {
163                                                         JSAN.use('cat.util');
164                                                         cat.util.show_in_opac(obj.selection_list);
165                                                 }
166                                         ],
167                                         'sel_transit_abort' : [
168                                                 ['command'],
169                                                 function() {
170                                                         var funcs = [];
171                                                         JSAN.use('circ.util');
172                                                         circ.util.abort_transits(obj.selection_list);
173                                                         for (var i = 0; i < obj.selection_list.length; i++) {
174                                                                 var barcode = obj.selection_list[i].barcode;
175                                                                 funcs.push( function(a) { return function() { obj.copy_status( a ); }; }(barcode) );
176                                                         }
177                                                         alert('Action complete.');
178                                                         for (var i = 0; i < funcs.length; i++) { funcs[i](); }
179                                                 }
180                                         ],
181                                         'sel_patron' : [
182                                                 ['command'],
183                                                 function() {
184                                                         JSAN.use('circ.util');
185                                                         circ.util.show_last_few_circs(obj.selection_list);
186                                                 }
187                                         ],
188                                         'sel_copy_details' : [
189                                                 ['command'],
190                                                 function() {
191                                                         JSAN.use('circ.util');
192                                                         for (var i = 0; i < obj.selection_list.length; i++) {
193                                                                 circ.util.show_copy_details( obj.selection_list[i].copy_id );
194                                                         }
195                                                 }
196                                         ],
197                                         'sel_renew' : [
198                                                 ['command'],
199                                                 function() {
200                                                         var funcs = [];
201                                                         JSAN.use('circ.util');
202                                                         for (var i = 0; i < obj.selection_list.length; i++) {
203                                                                 var test = obj.selection_list[i].renewable;
204                                                                 var barcode = obj.selection_list[i].barcode;
205                                                                 if (test == 't') {
206                                                                         circ.util.renew_via_barcode( barcode );
207                                                                         funcs.push( function(a) { return function() { obj.copy_status( a ); }; }(barcode) );
208                                                                 } else {
209                                                                         alert('Item with barcode ' + barcode + ' is not circulating.');
210                                                                 }
211                                                         }
212                                                         alert('Action complete.');
213                                                         for (var i = 0; i < funcs.length; i++) { funcs[i](); }
214                                                 }
215                                         ],
216
217                                         'sel_mark_items_damaged' : [
218                                                 ['command'],
219                                                 function() {
220                                                         var funcs = [];
221                                                         JSAN.use('cat.util'); JSAN.use('util.functional');
222                                                         cat.util.mark_item_damaged( util.functional.map_list( obj.selection_list, function(o) { return o.copy_id; } ) );
223                                                         for (var i = 0; i < obj.selection_list.length; i++) {
224                                                                 var barcode = obj.selection_list[i].barcode;
225                                                                 funcs.push( function(a) { return function() { obj.copy_status( a ); }; }(barcode) );
226                                                         }
227                                                         for (var i = 0; i < funcs.length; i++) { funcs[i](); }
228                                                 }
229                                         ],
230                                         'sel_mark_items_missing' : [
231                                                 ['command'],
232                                                 function() {
233                                                         var funcs = [];
234                                                         JSAN.use('cat.util'); JSAN.use('util.functional');
235                                                         cat.util.mark_item_missing( util.functional.map_list( obj.selection_list, function(o) { return o.copy_id; } ) );
236                                                         for (var i = 0; i < obj.selection_list.length; i++) {
237                                                                 var barcode = obj.selection_list[i].barcode;
238                                                                 funcs.push( function(a) { return function() { obj.copy_status( a ); }; }(barcode) );
239                                                         }
240                                                         for (var i = 0; i < funcs.length; i++) { funcs[i](); }
241                                                 }
242                                         ],
243                                         'sel_bucket' : [
244                                                 ['command'],
245                                                 function() {
246                                                         JSAN.use('cat.util');
247                                                         cat.util.add_copies_to_bucket(obj.selection_list);
248                                                 }
249                                         ],
250                                         'copy_status_barcode_entry_textbox' : [
251                                                 ['keypress'],
252                                                 function(ev) {
253                                                         if (ev.keyCode && ev.keyCode == 13) {
254                                                                 obj.copy_status();
255                                                         }
256                                                 }
257                                         ],
258                                         'cmd_broken' : [
259                                                 ['command'],
260                                                 function() { alert('Not Yet Implemented'); }
261                                         ],
262                                         'cmd_copy_status_submit_barcode' : [
263                                                 ['command'],
264                                                 function() {
265                                                         obj.copy_status();
266                                                 }
267                                         ],
268                                         'cmd_copy_status_print' : [
269                                                 ['command'],
270                                                 function() {
271                                                         try {
272                                                                 obj.list.on_all_fleshed =
273                                                                         function() {
274                                                                                 try {
275                                                                                         dump( js2JSON( obj.list.dump_with_keys() ) + '\n' );
276                                                                                         obj.data.stash_retrieve();
277                                                                                         var lib = obj.data.hash.aou[ obj.data.list.au[0].ws_ou() ];
278                                                                                         lib.children(null);
279                                                                                         var p = { 
280                                                                                                 'lib' : lib,
281                                                                                                 'staff' : obj.data.list.au[0],
282                                                                                                 'header' : obj.data.print_list_templates.item_status.header,
283                                                                                                 'line_item' : obj.data.print_list_templates.item_status.line_item,
284                                                                                                 'footer' : obj.data.print_list_templates.item_status.footer,
285                                                                                                 'type' : obj.data.print_list_templates.item_status.type,
286                                                                                                 'list' : obj.list.dump_with_keys(),
287                                                                                         };
288                                                                                         JSAN.use('util.print'); var print = new util.print();
289                                                                                         print.tree_list( p );
290                                                                                         setTimeout(function(){ obj.list.on_all_fleshed = null; },0);
291                                                                                 } catch(E) {
292                                                                                         obj.error.standard_unexpected_error_alert('print',E); 
293                                                                                 }
294                                                                         }
295                                                                 obj.list.full_retrieve();
296                                                         } catch(E) {
297                                                                 obj.error.standard_unexpected_error_alert('print',E); 
298                                                         }
299                                                 }
300                                         ],
301                                         'cmd_copy_status_export' : [
302                                                 ['command'],
303                                                 function() {
304                                                         try {
305                                                                 obj.list.on_all_fleshed =
306                                                                         function() {
307                                                                                 try {
308                                                                                         dump( obj.list.dump_csv() + '\n' );
309                                                                                         copy_to_clipboard(obj.list.dump_csv());
310                                                                                         setTimeout(function(){ obj.list.on_all_fleshed = null; },0);
311                                                                                 } catch(E) {
312                                                                                         obj.error.standard_unexpected_error_alert('export',E); 
313                                                                                 }
314                                                                         }
315                                                                 obj.list.full_retrieve();
316                                                         } catch(E) {
317                                                                 obj.error.standard_unexpected_error_alert('export',E); 
318                                                         }
319                                                 }
320                                         ],
321
322                                         'cmd_copy_status_reprint' : [
323                                                 ['command'],
324                                                 function() {
325                                                 }
326                                         ],
327                                         'cmd_copy_status_done' : [
328                                                 ['command'],
329                                                 function() {
330                                                 }
331                                         ],
332                                 }
333                         }
334                 );
335                 this.controller.render();
336                 this.controller.view.copy_status_barcode_entry_textbox.focus();
337
338         },
339
340         'test_barcode' : function(bc) {
341                 var obj = this;
342                 var good = util.barcode.check(bc);
343                 var x = document.getElementById('strict_barcode');
344                 if (x && x.checked != true) return true;
345                 if (good) {
346                         return true;
347                 } else {
348                         if ( 1 == obj.error.yns_alert(
349                                                 'Bad checkdigit; possible mis-scan.  Use this barcode ("' + bc + '") anyway?',
350                                                 'Bad Barcode',
351                                                 'Cancel',
352                                                 'Accept Barcode',
353                                                 null,
354                                                 'Check here to confirm this action',
355                                                 '/xul/server/skin/media/images/bad_barcode.png'
356                         ) ) {
357                                 return true;
358                         } else {
359                                 return false;
360                         }
361                 }
362         },
363
364         'copy_status' : function(barcode) {
365                 var obj = this;
366                 try {
367                         try { document.getElementById('last_scanned').setAttribute('value',''); } catch(E) {}
368                         if (!barcode) barcode = obj.controller.view.copy_status_barcode_entry_textbox.value;
369                         if (!barcode) return;
370                         if (barcode) {
371                                 if ( obj.test_barcode(barcode) ) { /* good */ } else { /* bad */ return; }
372                         }
373                         JSAN.use('circ.util');
374                         var copy = obj.network.simple_request( 'FM_ACP_RETRIEVE_VIA_BARCODE', [ barcode ]);
375                         if (copy == null) {
376                                 throw('Something weird happened.  null result');
377                         } else if (copy.ilsevent) {
378                                 switch(copy.ilsevent) {
379                                         case -1: 
380                                                 obj.error.standard_network_error_alert(); 
381                                                 obj.controller.view.copy_status_barcode_entry_textbox.select();
382                                                 obj.controller.view.copy_status_barcode_entry_textbox.focus();
383                                         break;
384                                         case 1502 /* ASSET_COPY_NOT_FOUND */ :
385                                                 try { document.getElementById('last_scanned').setAttribute('value',barcode + ' was either mis-scanned or is not cataloged.'); } catch(E) {}
386                                                 obj.error.yns_alert(barcode + ' was either mis-scanned or is not cataloged.','Not Cataloged','OK',null,null,'Check here to confirm this message');
387                                                 obj.controller.view.copy_status_barcode_entry_textbox.select();
388                                                 obj.controller.view.copy_status_barcode_entry_textbox.focus();
389                                         break;
390                                         default: 
391                                                 throw(copy); 
392                                         break;
393                                 }
394                         } else {
395                                 obj.network.simple_request('FM_ACP_DETAILS', [ ses(), copy.id() ], function(req) {
396                                         try {
397                                                 var details = req.getResultObject();
398                                                 var msg = copy.barcode() + ' -- ';
399                                                 if (copy.call_number() == -1) msg += 'Item is a Pre-Cat.  ';
400                                                 if (details.hold) msg += 'Item is captured for a Hold.  ';
401                                                 if (details.transit) msg += 'Item is in Transit.  ';
402                                                 if (details.circ && ! details.circ.checkin_time()) msg += 'Item is circulating.  ';
403                                                 try { document.getElementById('last_scanned').setAttribute('value',msg); } catch(E) {}
404                                         } catch(E) {
405                                                 alert(E);
406                                         }
407                                 } );
408                                 var my_mvr = obj.network.simple_request('MODS_SLIM_RECORD_RETRIEVE_VIA_COPY', [ copy.id() ]);
409                                 if (document.getElementById('trim_list')) {
410                                         var x = document.getElementById('trim_list');
411                                         if (x.checked) { obj.list.trim_list = 20; } else { obj.list.trim_list = null; }
412                                 }
413                                 obj.list.append(
414                                         {
415                                                 '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 ) } ),
416                                                 'row' : {
417                                                         'my' : {
418                                                                 'mvr' : my_mvr,
419                                                                 'acp' : copy,
420                                                         }
421                                                 },
422                                                 'to_top' : true,
423                                         }
424                                 );
425                                 obj.controller.view.copy_status_barcode_entry_textbox.value = '';
426                                 obj.controller.view.copy_status_barcode_entry_textbox.focus();
427                         }
428                 } catch(E) {
429                         obj.error.standard_unexpected_error_alert('',E);
430                         obj.controller.view.copy_status_barcode_entry_textbox.select();
431                         obj.controller.view.copy_status_barcode_entry_textbox.focus();
432                 }
433
434         },
435         
436         'spawn_copy_editor' : function() {
437
438                 /* FIXME -  a lot of redundant calls here */
439
440                 var obj = this;
441
442                 JSAN.use('util.widgets'); JSAN.use('util.functional');
443
444                 var list = obj.selection_list;
445
446                 list = util.functional.map_list(
447                         list,
448                         function (o) {
449                                 return o.copy_id;
450                         }
451                 );
452
453                 var copies = util.functional.map_list(
454                         list,
455                         function (acp_id) {
456                                 return obj.network.simple_request('FM_ACP_RETRIEVE',[acp_id]);
457                         }
458                 );
459
460                 var edit = 0;
461                 try {
462                         edit = obj.network.request(
463                                 api.PERM_MULTI_ORG_CHECK.app,
464                                 api.PERM_MULTI_ORG_CHECK.method,
465                                 [ 
466                                         ses(), 
467                                         obj.data.list.au[0].id(), 
468                                         util.functional.map_list(
469                                                 copies,
470                                                 function (o) {
471                                                         return o.call_number() == -1 ? o.circ_lib() : obj.network.simple_request('FM_ACN_RETRIEVE',[o.call_number()]).owning_lib();
472                                                 }
473                                         ),
474                                         copies.length == 1 ? [ 'UPDATE_COPY' ] : [ 'UPDATE_COPY', 'UPDATE_BATCH_COPY' ]
475                                 ]
476                         ).length == 0 ? 1 : 0;
477                 } catch(E) {
478                         obj.error.sdump('D_ERROR','batch permission check: ' + E);
479                 }
480
481                 JSAN.use('cat.util'); cat.util.spawn_copy_editor(list,edit);
482
483         },
484
485 }
486
487 dump('exiting circ.copy_status.js\n');