]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/xul/staff_client/server/circ/checkin.js
skip xulG.get_barcode if no barcode completion
[Evergreen.git] / Open-ILS / xul / staff_client / server / circ / checkin.js
1 dump('entering circ.checkin.js\n');
2
3 if (typeof circ == 'undefined') circ = {};
4 circ.checkin = 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     this.OpenILS = {}; JSAN.use('OpenILS.data'); this.OpenILS.data = new OpenILS.data(); this.OpenILS.data.init({'via':'stash'});
11     this.data = this.OpenILS.data;
12 }
13
14 circ.checkin.prototype = {
15
16     'selection_list' : [],
17     'row_map' : {},
18
19     'init' : function( params ) {
20
21         var obj = this;
22
23         JSAN.use('circ.util'); JSAN.use('patron.util');
24         var columns = circ.util.columns( 
25             { 
26                 'barcode' : { 'hidden' : false },
27                 'title' : { 'hidden' : false },
28                 'location' : { 'hidden' : false },
29                 'status' : { 'hidden' : false },
30                 'route_to' : { 'hidden' : false },
31                 'alert_message' : { 'hidden' : false },
32                 'checkin_time' : { 'hidden' : false }
33             },
34             {
35                 'except_these' : [ 'uses', 'checkin_time_full' ]
36             }
37         ).concat(
38             patron.util.columns( { 'family_name' : { 'hidden' : 'false' } } )
39
40         ).concat(
41             patron.util.mbts_columns( {}, { 'except_these' : [ 'total_paid', 'total_owed', 'xact_start', 'xact_finish', 'xact_type' ] } )
42
43         ).sort( function(a,b) { if (a.label < b.label) return -1; if (a.label > b.label) return 1; return 0; } );
44
45         JSAN.use('util.list'); obj.list = new util.list('checkin_list');
46         obj.list.init(
47             {
48                 'columns' : columns,
49                 'retrieve_row' : obj.gen_list_retrieve_row_func(),
50                 'on_select' : function(ev) {
51                     try {
52                         JSAN.use('util.functional');
53                         var sel = obj.list.retrieve_selection();
54                         obj.selection_list = util.functional.map_list(
55                             sel,
56                             function(o) { 
57                                 if (o.getAttribute('retrieve_id')) {
58                                     try {
59                                         var p = JSON2js(o.getAttribute('retrieve_id')); 
60                                         p.unique_row_counter = o.getAttribute('unique_row_counter'); 
61                                         o.setAttribute('id','_checkin_list_row_'+p.unique_row_counter);
62                                         return p; 
63                                     } catch(E) {
64                                         return -1;
65                                     }
66                                 } else {
67                                     return -1;
68                                 }
69                             }
70                         );
71                         obj.selection_list = util.functional.filter_list(
72                             obj.selection_list,
73                             function(o) {
74                                 return o != -1;
75                             }
76                         );
77                         obj.error.sdump('D_TRACE', 'circ/copy_status: selection list = ' + js2JSON(obj.selection_list) );
78                         if (obj.selection_list.length == 0) {
79                             obj.controller.view.sel_edit.setAttribute('disabled','true');
80                             obj.controller.view.sel_backdate.setAttribute('disabled','true');
81                             obj.controller.view.sel_opac.setAttribute('disabled','true');
82                             obj.controller.view.sel_patron.setAttribute('disabled','true');
83                             obj.controller.view.sel_last_patron.setAttribute('disabled','true');
84                             obj.controller.view.sel_copy_details.setAttribute('disabled','true');
85                             obj.controller.view.sel_bucket.setAttribute('disabled','true');
86                             obj.controller.view.sel_spine.setAttribute('disabled','true');
87                             obj.controller.view.sel_transit_abort.setAttribute('disabled','true');
88                             obj.controller.view.sel_clip.setAttribute('disabled','true');
89                             obj.controller.view.sel_mark_items_damaged.setAttribute('disabled','true');
90                             obj.controller.view.sel_mark_missing_pieces.setAttribute('disabled','true');
91                         } else {
92                             obj.controller.view.sel_edit.setAttribute('disabled','false');
93                             obj.controller.view.sel_backdate.setAttribute('disabled','false');
94                             obj.controller.view.sel_opac.setAttribute('disabled','false');
95                             obj.controller.view.sel_patron.setAttribute('disabled','false');
96                             obj.controller.view.sel_last_patron.setAttribute('disabled','false');
97                             obj.controller.view.sel_copy_details.setAttribute('disabled','false');
98                             obj.controller.view.sel_bucket.setAttribute('disabled','false');
99                             obj.controller.view.sel_spine.setAttribute('disabled','false');
100                             obj.controller.view.sel_transit_abort.setAttribute('disabled','false');
101                             obj.controller.view.sel_clip.setAttribute('disabled','false');
102                             obj.controller.view.sel_mark_items_damaged.setAttribute('disabled','false');
103                             obj.controller.view.sel_mark_missing_pieces.setAttribute('disabled','false');
104                         }
105
106                         // This is for updating that label in the upper left of the UI that shows Item already checked-in, etc.
107                         // Our purpose here is to show the bill amount associated with a specific transaction whenever that
108                         // transaction is selected in the list
109                         if (obj.selection_list.length == 1) {
110                             var unique_row_counter = obj.selection_list[0].unique_row_counter;
111                             var node = $('_checkin_list_row_'+unique_row_counter);
112                             if (node && node.getAttribute('no_change_label_label')) {
113                                 $('no_change_label').setAttribute('unique_row_counter',unique_row_counter);
114                                 $('no_change_label').setAttribute('value',node.getAttribute('no_change_label_label'));
115                                 $('no_change_label').setAttribute('onclick',node.getAttribute('no_change_label_click'));
116                                 $('no_change_label').setAttribute('hidden','false');
117                                 addCSSClass($('no_change_label'),'click_link'); 
118                             }
119                         }
120                     } catch(E) {
121                         alert('FIXME: ' + E);
122                     }
123                 }
124             }
125         );
126         
127         JSAN.use('util.controller'); obj.controller = new util.controller();
128         obj.controller.init(
129             {
130                 'control_map' : {
131                     'save_columns' : [ [ 'command' ], function() { obj.list.save_columns(); } ],
132                     'sel_clip' : [
133                         ['command'],
134                         function() { 
135                             obj.list.clipboard(); 
136                             obj.controller.view.checkin_barcode_entry_textbox.focus();
137                         }
138                     ],
139                     'sel_edit' : [
140                         ['command'],
141                         function() {
142                             try {
143                                 obj.spawn_copy_editor();
144                             } catch(E) {
145                                 alert(E);
146                             }
147                         }
148                     ],
149                     'sel_spine' : [
150                         ['command'],
151                         function() {
152                             JSAN.use('cat.util');
153                             cat.util.spawn_spine_editor(obj.selection_list);
154                         }
155                     ],
156                     'sel_opac' : [
157                         ['command'],
158                         function() {
159                             JSAN.use('cat.util');
160                             cat.util.show_in_opac(obj.selection_list);
161                         }
162                     ],
163                     'sel_transit_abort' : [
164                         ['command'],
165                         function() {
166                             JSAN.use('circ.util');
167                             circ.util.abort_transits(obj.selection_list);
168                         }
169                     ],
170                     'sel_patron' : [
171                         ['command'],
172                         function() {
173                             JSAN.use('circ.util');
174                             circ.util.show_last_few_circs(obj.selection_list);
175                         }
176                     ],
177                     'sel_last_patron' : [
178                         ['command'],
179                         function() {
180                             var patrons = {};
181                             for (var i = 0; i < obj.selection_list.length; i++) {
182                                 var circs = obj.network.simple_request('FM_CIRC_RETRIEVE_VIA_COPY',[ses(),obj.selection_list[i].copy_id,1]);
183                                 if (circs.length > 0) {
184                                     patrons[circs[0].usr()] = 1;
185                                 } else {
186                                     alert(document.getElementById('circStrings').getFormattedString('staff.circ.item_no_circs', [obj.selection_list[i].barcode]));
187                                 }
188                             }
189                             for (var i in patrons) {
190                                 xulG.new_patron_tab({},{'id' : i});
191                             }
192                         }
193                     ],
194                     'sel_copy_details' : [
195                         ['command'],
196                         function() {
197                             JSAN.use('circ.util');
198                             circ.util.item_details_new(
199                                 util.functional.map_list(
200                                     obj.selection_list,
201                                     function(o) { return o.barcode; }
202                                 )
203                             );
204                         }
205                     ],
206                     'sel_backdate' : [
207                         ['command'],
208                         function() {
209                             try {
210                                 JSAN.use('circ.util');
211                                 var circ_ids = []; var circ_row_map = {};
212                                 for (var i = 0; i < obj.selection_list.length; i++) {
213                                     var circ_id = obj.selection_list[i].circ_id; 
214                                     var copy_id = obj.selection_list[i].copy_id; 
215                                     if (!circ_id) {
216                                         var blob = obj.network.simple_request('FM_ACP_DETAILS',[ses(),copy_id]);
217                                         if (blob.circ) circ_id = blob.circ.id();
218                                     }
219                                     if (!circ_id) continue;
220                                     if (! circ_row_map[ circ_id ]) { circ_row_map[ circ_id ] = []; }
221                                     circ_row_map[ circ_id ].push( obj.selection_list[i].unique_row_counter );
222                                     circ_ids.push( circ_id );
223                                 }
224                                 var robj = circ.util.backdate_post_checkin( circ_ids );
225                                 if (robj.complete) {
226                                     var bad_circs = {};
227                                     for (var i = 0; i < robj.bad_circs.length; i++) {
228                                         bad_circs[ robj.bad_circs[i].circ_id ] = robj.bad_circs[i].result;
229                                     }
230                                     for (var circ_id in circ_row_map) {
231                                         var row_array = circ_row_map[circ_id];
232                                         for (var i = 0; i < row_array.length; i++) {
233                                             var row_data = obj.row_map[ row_array[i] ];
234                                             if (row_data.row.my.circ) {
235                                                 if (bad_circs[ circ_id ]) {
236                                                     row_data.row_properties = 'backdate_failed';
237                                                 } else {
238                                                     row_data.row_properties = 'backdate_succeeded';
239                                                     row_data.row.my.circ.checkin_time( robj.backdate );
240                                                 }
241                                             }
242                                             obj.list.refresh_row( row_data );
243                                         } 
244                                     }
245                                 }
246                             } catch(E) {
247                                 alert('Error in checkin.js, sel_backdate: ' + E);
248                             }
249                         }
250                     ],
251                     'sel_mark_items_damaged' : [
252                         ['command'],
253                         function() {
254                             var funcs = [];
255                             JSAN.use('cat.util'); JSAN.use('util.functional');
256                             cat.util.mark_item_damaged( util.functional.map_list( obj.selection_list, function(o) { return o.copy_id; } ) );
257                         }
258                     ],
259                     'sel_mark_missing_pieces' : [
260                         ['command'],
261                         function() {
262                             var funcs = [];
263                             JSAN.use('cat.util'); JSAN.use('util.functional');
264                             cat.util.mark_item_as_missing_pieces( util.functional.map_list( obj.selection_list, function(o) { return o.copy_id; } ) );
265                         }
266                     ],
267                     'sel_bucket' : [
268                         ['command'],
269                         function() {
270                             JSAN.use('cat.util');
271                             cat.util.add_copies_to_bucket(obj.selection_list);
272                         }
273                     ],
274                     'checkin_barcode_entry_textbox' : [
275                         ['keypress'],
276                         function(ev) {
277                             if (ev.keyCode && ev.keyCode == 13) {
278                                 obj.checkin();
279                             }
280                         }
281                     ],
282                     'checkin_effective_date_label' : [
283                         ['render'],
284                         function(e) {
285                             return function() {
286                                 obj.controller.view.checkin_effective_datepicker.value =
287                                     util.date.formatted_date(new Date(),'%F');
288                             };
289                         }
290                     ],
291                     'checkin_effective_datepicker' : [
292                         ['change'],
293                         function(ev) {
294                             if (ev.target.nodeName == 'datepicker') {
295                                 try {
296                                     if ( ev.target.dateValue > new Date() ) throw(document.getElementById('circStrings').getString('staff.circ.future_date'));
297                                     var x = document.getElementById('background');
298                                     if (x) {
299                                         if ( ev.target.value == util.date.formatted_date(new Date(),'%F') ) {
300                                             //addCSSClass(x,'checkin_screen_normal');
301                                             removeCSSClass(x,'checkin_screen_backdating');
302                                             removeCSSClass(document.getElementById('background'),'checkin_screen_do_not_alert_on_precat');
303                                             removeCSSClass(document.getElementById('background'),'checkin_screen_suppress_holds_and_transits');
304                                             removeCSSClass(document.getElementById('background'),'checkin_screen_amnesty_mode');
305                                             removeCSSClass(document.getElementById('background'),'checkin_screen_checkin_auto_print_slips');
306                                             document.getElementById('background-text').setAttribute('value',document.getElementById('circStrings').getString('staff.circ.process_item'));
307                                         } else {
308                                             addCSSClass(x,'checkin_screen_backdating');
309                                             //removeCSSClass(x,'checkin_screen_normal');
310                                             document.getElementById('background-text').setAttribute('value',document.getElementById('circStrings').getFormattedString('staff.circ.backdated_checkin', [ev.target.value]));
311                                         }
312                                     }
313                                 } catch(E) {
314                                     var x = document.getElementById('background');
315                                     if (x) {
316                                         //addCSSClass(x,'checkin_screen_normal');
317                                         removeCSSClass(x,'checkin_screen_backdating');
318                                         removeCSSClass(document.getElementById('background'),'checkin_screen_do_not_alert_on_precat');
319                                         removeCSSClass(document.getElementById('background'),'checkin_screen_suppress_holds_and_transits');
320                                         removeCSSClass(document.getElementById('background'),'checkin_screen_amnesty_mode');
321                                         removeCSSClass(document.getElementById('background'),'checkin_screen_checkin_auto_print_slips');
322                                         document.getElementById('background-text').setAttribute('value',document.getElementById('circStrings').getString('staff.circ.process_item'));
323                                     }
324                                     dump('checkin:effective_date: ' + E + '\n');
325                                     ev.target.disabled = true;
326                                     //alert(document.getElementById('circStrings').getFormattedString('staff.circ.backdate.exception', [E]));
327                                     ev.target.value = util.date.formatted_date(new Date(),'%F');
328                                     ev.target.disabled = false;
329                                     JSAN.use('util.sound'); var sound = new util.sound(); sound.bad();
330                                     
331                                 }
332                             }
333                         }
334                     ],
335                     'cmd_broken' : [
336                         ['command'],
337                         function() { alert(document.getElementById('circStrings').getString('staff.circ.unimplemented')); }
338                     ],
339                     'cmd_checkin_submit_barcode' : [
340                         ['command'],
341                         function() {
342                             obj.checkin();
343                         }
344                     ],
345                     'cmd_checkin_print' : [
346                         ['command'],
347                         function() {
348                             var p = { 
349                                 'printer_context' : 'receipt',
350                                 'template' : 'checkin'
351                             };
352                             obj.list.print(p);
353                         }
354                     ],
355                     'cmd_csv_to_clipboard' : [ ['command'], function() { 
356                         obj.list.dump_csv_to_clipboard(); 
357                         obj.controller.view.checkin_barcode_entry_textbox.focus();
358                     } ],
359                     'cmd_csv_to_printer' : [ ['command'], function() { 
360                         obj.list.dump_csv_to_printer(); 
361                         obj.controller.view.checkin_barcode_entry_textbox.focus();
362                     } ],
363                     'cmd_csv_to_file' : [ ['command'], function() { 
364                         obj.list.dump_csv_to_file( { 'defaultFileName' : 'checked_in.txt' } ); 
365                         obj.controller.view.checkin_barcode_entry_textbox.focus();
366                     } ],
367                     'cmd_do_not_alert_on_precat' : [ ['command'], function(ev) {
368                         dump('in cmd_do_not_alert_on_precat\n');
369                         var bg = document.getElementById('background');
370                         var cb = document.getElementById('do_not_alert_on_precat');
371                         var ind = document.getElementById('do_not_alert_on_precat_indicator');
372                         var cn = 'checkin_screen_do_not_alert_on_precat';
373                         if (cb.getAttribute('checked') == 'true') { addCSSClass(bg,cn); } else { removeCSSClass(bg,cn); }
374                         ind.hidden = cb.getAttribute('checked') != 'true'; 
375                         document.getElementById('checkin_barcode_entry_textbox').focus();
376                         return true;
377                     } ],
378                     'cmd_suppress_holds_and_transits' : [ ['command'], function(ev) {
379                         dump('in cmd_suppress_holds_and_transits\n');
380                         var bg = document.getElementById('background');
381                         var cb = document.getElementById('suppress_holds_and_transits');
382                         var ind = document.getElementById('suppress_holds_and_transits_indicator');
383                         var cn = 'checkin_screen_suppress_holds_and_transits';
384                         if (cb.getAttribute('checked') == 'true') { addCSSClass(bg,cn); } else { removeCSSClass(bg,cn); }
385                         ind.hidden = cb.getAttribute('checked') != 'true'; 
386                         document.getElementById('checkin_barcode_entry_textbox').focus();
387                         return true;
388                     } ],
389                     'cmd_amnesty_mode' : [ ['command'], function(ev) {
390                         dump('in cmd_amnesty_mode\n');
391                         var bg = document.getElementById('background');
392                         var cb = document.getElementById('amnesty_mode');
393                         var ind = document.getElementById('amnesty_mode_indicator');
394                         var cn = 'checkin_screen_amnesty_mode';
395                         if (cb.getAttribute('checked') == 'true') { addCSSClass(bg,cn); } else { removeCSSClass(bg,cn); }
396                         ind.hidden = cb.getAttribute('checked') != 'true'; 
397                         document.getElementById('checkin_barcode_entry_textbox').focus();
398                         return true;
399                     } ],
400                     'cmd_checkin_auto_print_slips' : [ ['command'], function(ev) {
401                         dump('in cmd_checkin_auto_print_slips\n');
402                         var bg = document.getElementById('background');
403                         var cb = document.getElementById('checkin_auto_print_slips');
404                         var ind = document.getElementById('checkin_auto_print_slips_indicator');
405                         var cn = 'checkin_screen_checkin_auto_print_slips';
406                         if (cb.getAttribute('checked') == 'true') { addCSSClass(bg,cn); } else { removeCSSClass(bg,cn); }
407                         ind.hidden = cb.getAttribute('checked') != 'true'; 
408                         document.getElementById('checkin_barcode_entry_textbox').focus();
409                         return true;
410                     } ],
411                     'cmd_checkin_clear_shelf_expired' : [ ['command'], function(ev) {
412                         dump('in cmd_checkin_clear_shelf_expired\n');
413                         var bg = document.getElementById('background');
414                         var cb = document.getElementById('checkin_clear_shelf_expired');
415                         var ind = document.getElementById('checkin_clear_shelf_expired_indicator');
416                         var cn = 'checkin_screen_checkin_clear_shelf_expired';
417                         if (cb.getAttribute('checked') == 'true') { addCSSClass(bg,cn); } else { removeCSSClass(bg,cn); }
418                         ind.hidden = cb.getAttribute('checked') != 'true'; 
419                         document.getElementById('checkin_barcode_entry_textbox').focus();
420                         return true;
421                     } ],
422                     'cmd_checkin_auto_retarget' : [ ['command'], function(ev) {
423                         dump('in cmd_checkin_auto_retarget\n');
424                         var bg = document.getElementById('background');
425                         var cb = document.getElementById('checkin_auto_retarget');
426                         var cb2 = document.getElementById('checkin_auto_retarget_all');
427                         var ind = document.getElementById('checkin_auto_retarget_indicator');
428                         var ind2 = document.getElementById('checkin_auto_retarget_all_indicator');
429                         var cn = 'checkin_screen_checkin_auto_retarget';
430                         var cn2 = 'checkin_screen_checkin_auto_retarget_all';
431                         if (cb.getAttribute('checked') == 'true') {
432                             if(cb2.getAttribute('checked') == 'true') {
433                                 removeCSSClass(bg,cn);
434                                 addCSSClass(bg,cn2);
435                                 ind.hidden = true;
436                                 ind2.hidden = false;
437                             } else {
438                                 addCSSClass(bg,cn);
439                                 removeCSSClass(bg,cn2);
440                                 ind.hidden = false;
441                                 ind2.hidden = true;
442                             }
443                         } else {
444                             removeCSSClass(bg,cn);
445                             removeCSSClass(bg,cn2);
446                             ind.hidden = true;
447                             ind2.hidden = true;
448                         }
449                         document.getElementById('checkin_barcode_entry_textbox').focus();
450                         return true;
451                     } ],
452                     'cmd_checkin_local_hold_as_transit' : [ ['command'], function(ev) {
453                         dump('in cmd_checkin_local_hold_as_transit\n');
454                         var bg = document.getElementById('background');
455                         var cb = document.getElementById('checkin_local_hold_as_transit');
456                         var ind = document.getElementById('checkin_local_hold_as_transit_indicator');
457                         var cn = 'checkin_screen_checkin_local_hold_as_transit';
458                         if (cb.getAttribute('checked') == 'true') { addCSSClass(bg,cn); } else { removeCSSClass(bg,cn); }
459                         ind.hidden = cb.getAttribute('checked') != 'true'; 
460                         document.getElementById('checkin_barcode_entry_textbox').focus();
461                         return true;
462
463                     } ]
464                 }
465             }
466         );
467         this.controller.render();
468         this.controller.view.checkin_barcode_entry_textbox.focus();
469
470     },
471
472     'update_no_change_label' : function (node,row) {
473         var obj = this;
474         var no_change_label = document.getElementById('no_change_label');
475         var incumbent_row = no_change_label.getAttribute('unique_row_counter');
476         var incoming_row = node.getAttribute('unique_row_counter');
477         if (!incumbent_row) { incumbent_row = incoming_row; }
478         if (row.my.mbts && ( no_change_label || document.getElementById('fine_tally') ) ) {
479             var bill = row.my.mbts;
480             if (Number(bill.balance_owed()) == 0) { return; }
481             if (no_change_label) {
482                 var msg = incumbent_row != incoming_row
483                     ? '' // clear out label if for a different transaction
484                     : no_change_label.getAttribute('value');
485                 var new_msg = document.getElementById('circStrings').getFormattedString(
486                     'staff.circ.utils.billable.amount', [
487                         row.my.acp.barcode(),
488                         util.money.sanitize(bill.balance_owed())
489                     ]
490                 );
491                 no_change_label.setAttribute(
492                     'value', 
493                     msg.indexOf(new_msg) > -1 ? msg : msg + new_msg + '  '
494                 );
495                 no_change_label.setAttribute('hidden','false');
496                 no_change_label.setAttribute('onclick','xulG.new_patron_tab({},{"id" : '+bill.usr()+', "show" : "bills" })');
497                 no_change_label.setAttribute('unique_row_counter',incoming_row);
498                 addCSSClass(no_change_label,'click_link'); 
499                 node.setAttribute('no_change_label_label', no_change_label.getAttribute('value'));
500                 node.setAttribute('no_change_label_click', no_change_label.getAttribute('onclick'));
501             }
502         }
503     },
504
505     'gen_list_retrieve_row_func' : function() {
506         var obj = this;
507         return function(params) {
508             try {
509                 var row = params.row;
510                 if (typeof params.on_retrieve == 'function') params.on_retrieve(row);
511                 obj.update_no_change_label(params.treeitem_node,row);
512                 var bill = row.my.mbts;
513                 if (bill && document.getElementById('fine_tally') && ! row.already_tallied) {
514                     params.row.already_tallied = true;
515                     var amount = util.money.cents_as_dollars(
516                         Number( util.money.dollars_float_to_cents_integer( document.getElementById('fine_tally').getAttribute('amount') ) ) 
517                         + Number( util.money.dollars_float_to_cents_integer( bill.balance_owed() ) )
518                     );
519                     document.getElementById('fine_tally').setAttribute('amount',amount);
520                     document.getElementById('fine_tally').setAttribute(
521                         'value',
522                         document.getElementById('circStrings').getFormattedString('staff.circ.utils.fine_tally_text', [ util.money.sanitize( amount ) ])
523                     );
524                     document.getElementById('fine_tally').setAttribute('hidden','false');
525                 }
526             } catch(E) {
527                 alert('Error in checkin.js, list_retrieve_row(): ' + E);
528             }
529             return row;
530         };
531     },
532
533     'test_barcode' : function(bc) {
534         var obj = this;
535         var x = document.getElementById('strict_barcode');
536         if (x && x.checked != true) return true;
537         var good = util.barcode.check(bc);
538         if (good) {
539             return true;
540         } else {
541             if ( 1 == obj.error.yns_alert(
542                         document.getElementById('circStrings').getFormattedString('staff.circ.check_digit.bad', [bc]),
543                         document.getElementById('circStrings').getString('staff.circ.barcode.bad'),
544                         document.getElementById('circStrings').getString('staff.circ.cancel'),
545                         document.getElementById('circStrings').getString('staff.circ.barcode.accept'),
546                         null,
547                         document.getElementById('circStrings').getString('staff.circ.confirm'),
548                         '/xul/server/skin/media/images/bad_barcode.png'
549             ) ) {
550                 return true;
551             } else {
552                 return false;
553             }
554         }
555     },
556
557     'checkin' : function() {
558         var obj = this;
559         try {
560             var textbox = obj.controller.view.checkin_barcode_entry_textbox;
561             var async = false;
562             var async_checkbox = document.getElementById('async_checkin');
563             if (async_checkbox) { async = async_checkbox.getAttribute('checked') == 'true'; }
564             var barcode = textbox.value;
565             if (async) {
566                 textbox.value = ''; textbox.focus();
567             }
568             if (obj.data.list.cbc.length > 0) { // skip barcode completion lookups if none configured
569                 // Auto-complete the barcode, items only
570                 var barcode_object = xulG.get_barcode(window, 'asset', barcode);
571                 // user_false means the user selected "None of the above", abort before other prompts/errors
572                 if(barcode_object == "user_false") return;
573                 // Got a barcode without an error? Use it. Otherwise fall through.
574                 if(barcode_object && typeof barcode_object.ilsevent == 'undefined')
575                     barcode = barcode_object.barcode;
576             }
577             if ( obj.test_barcode(barcode) ) { /* good */ } else { /* bad */ return; }
578             var placeholder_item = new acp();
579             placeholder_item.barcode( barcode );
580             var row_params = obj.list.append( { 
581                     'row' : {
582                         'my' : { 
583                             'acp' : placeholder_item
584                         } 
585                     },
586                     'to_top' : true,
587                     'flesh_immediately' : !async,
588                     'on_append' : function(rparams) { obj.row_map[ rparams.unique_row_counter ] = rparams; },
589                     'on_remove' : function(unique_row_counter) { delete obj.row_map[ unique_row_counter ]; }
590             } );
591             
592             var backdate = obj.controller.view.checkin_effective_datepicker.value;
593             var auto_print = document.getElementById('checkin_auto_print_slips');
594             if (auto_print) auto_print = auto_print.getAttribute('checked') == 'true';
595             JSAN.use('circ.util');
596             var params = { 
597                 'barcode' : barcode,
598                 'disable_textbox' : function() { 
599                     if (!async) {
600                         textbox.blur();
601                         textbox.disabled = true; 
602                         textbox.setAttribute('disabled', 'true'); 
603                     }
604                 },
605                 'enable_textbox' : function() { 
606                     textbox.disabled = false; 
607                     textbox.setAttribute('disabled', 'false'); 
608                     textbox.focus();
609                 },
610                 'checkin_result' : function(checkin) {
611                     textbox.disabled = false;
612                     textbox.focus();
613                     //obj.controller.view.cmd_checkin_submit_barcode.setAttribute('disabled', 'false'); 
614                     obj.checkin2(checkin,backdate,row_params);
615                 },
616                 'info_blurb' : function(text) {
617                     try { row_params.row.my.acp.alert_message( text ); } catch(E) {dump('error: ' + E + '\n');}
618                 }
619             }; 
620             var suppress_holds_and_transits = document.getElementById('suppress_holds_and_transits');
621             if (suppress_holds_and_transits) suppress_holds_and_transits = suppress_holds_and_transits.getAttribute('checked') == 'true';
622             if (suppress_holds_and_transits) params.noop = 1;
623             var amnesty_mode = document.getElementById('amnesty_mode');
624             if (amnesty_mode) amnesty_mode = amnesty_mode.getAttribute('checked') == 'true';
625             if (amnesty_mode) params.void_overdues = 1;
626             var clear_shelf_expired_holds = document.getElementById('checkin_clear_shelf_expired');
627             if (clear_shelf_expired_holds) clear_shelf_expired_holds = clear_shelf_expired_holds.getAttribute('checked') == 'true';
628             if (clear_shelf_expired_holds) params.clear_expired = 1;
629             var auto_retarget = document.getElementById('checkin_auto_retarget');
630             if (auto_retarget) auto_retarget = auto_retarget.getAttribute('checked') == 'true';
631             if (auto_retarget) {
632                 var retarget_all = document.getElementById('checkin_auto_retarget_all');
633                 if (retarget_all) retarget_all = retarget_all.getAttribute('checked') == 'true';
634                 if (retarget_all) params.retarget_mode = 'retarget.all';
635                 else params.retarget_mode = 'retarget';
636             }
637             var hold_as_transit = document.getElementById('checkin_local_hold_as_transit');
638             if (hold_as_transit) hold_as_transit = hold_as_transit.getAttribute('checked') == 'true';
639             if (hold_as_transit) params.hold_as_transit = 1;
640             circ.util.checkin_via_barcode(
641                 ses(), 
642                 params,
643                 backdate, 
644                 auto_print,
645                 async
646             );
647         } catch(E) {
648             obj.error.standard_unexpected_error_alert(document.getElementById('circStrings').getFormattedString('staff.circ.checkin.exception', [E]), E);
649             if (typeof obj.on_failure == 'function') {
650                 obj.on_failure(E);
651             }
652             if (typeof window.xulG == 'object' && typeof window.xulG.on_failure == 'function') {
653                 obj.error.sdump('D_CIRC', document.getElementById('circStrings').getString('staff.circ.util.checkin.exception.external') + '\n');
654                 window.xulG.on_failure(E);
655             } else {
656                 obj.error.sdump('D_CIRC', document.getElementById('circStrings').getString('staff.circ.util.checkin.exception.no_external') + '\n');
657             }
658         }
659
660     },
661
662     'checkin2' : function(checkin,backdate,row_params) {
663         var obj = this;
664         try {
665             if (!checkin) {/* circ.util.checkin used to be sole handler of errors and returns null currently */
666                 obj.list.refresh_row( row_params ); /* however, let's refresh the row because we're shoving error text into the dummy placeholder item's alert_message field  */
667                 return obj.on_failure();
668             }
669             if (checkin.ilsevent == 7010 /* COPY_ALERT_MESSAGE */
670                 || checkin.ilsevent == 1203 /* COPY_BAD_STATUS */
671                 || checkin.ilsevent == -1 /* offline */
672                 || checkin.ilsevent == 1502 /* ASSET_COPY_NOT_FOUND */
673                 || checkin.ilsevent == 1203 /* COPY_BAD_STATUS */
674                 || checkin.ilsevent == 7009 /* CIRC_CLAIMS_RETURNED */ 
675                 || checkin.ilsevent == 7011 /* COPY_STATUS_LOST */ 
676                 || checkin.ilsevent == 7012 /* COPY_STATUS_MISSING */) {
677                 obj.list.refresh_row( row_params ); 
678                 return obj.on_failure();
679             }
680             var retrieve_id = js2JSON( { 'circ_id' : checkin.circ ? checkin.circ.id() : null , 'copy_id' : checkin.copy.id(), 'barcode' : checkin.copy.barcode(), 'doc_id' : (typeof checkin.record != 'undefined' ? ( typeof checkin.record.ilsevent == 'undefined' ? checkin.record.doc_id() : null ) : null ) } );
681             if (checkin.circ && checkin.circ.checkin_time() == 'now') checkin.circ.checkin_time(backdate);
682             if (document.getElementById('trim_list')) {
683                 var x = document.getElementById('trim_list');
684                 if (x.checked) { obj.list.trim_list = 20; } else { obj.list.trim_list = null; }
685             }
686             row_params['retrieve_id'] = retrieve_id;
687             row_params['row'] =  {
688                 'already_tallied' : false,
689                 'my' : {
690                     'circ' : checkin.circ,
691                     'mbts' : checkin.circ ? checkin.circ.billable_transaction().summary() : null,
692                     'mvr' : checkin.record,
693                     'acp' : checkin.copy,
694                     'acn' : checkin.volume,
695                     'au' : checkin.patron,
696                     'status' : checkin.status,
697                     'route_to' : checkin.route_to,
698                     'message' : checkin.message
699                 }
700             };
701             obj.list.refresh_row( row_params );
702             obj.list.node.view.selection.select(0);
703
704             JSAN.use('util.sound'); var sound = new util.sound(); sound.circ_good();
705
706             if (typeof obj.on_checkin == 'function') {
707                 obj.on_checkin(checkin);
708             }
709             if (typeof window.xulG == 'object' && typeof window.xulG.on_checkin == 'function') {
710                 obj.error.sdump('D_CIRC', document.getElementById('circStrings').getString('staff.circ.checkin.exception.external') + '\n');
711                 window.xulG.on_checkin(checkin);
712             } else {
713                 obj.error.sdump('D_CIRC', document.getElementById('circStrings').getString('staff.circ.checkin.exception.no_external') + '\n');
714             }
715
716             return true;
717
718         } catch(E) {
719             obj.error.standard_unexpected_error_alert(document.getElementById('circStrings').getFormattedString('staff.circ.checkin2.exception', [E]));
720             if (typeof obj.on_failure == 'function') {
721                 obj.on_failure(E);
722             }
723             if (typeof window.xulG == 'object' && typeof window.xulG.on_failure == 'function') {
724                 obj.error.sdump('D_CIRC', document.getElementById('circStrings').getString('staff.circ.checkin2.exception.external') + '\n');
725                 window.xulG.on_failure(E);
726             } else {
727                 obj.error.sdump('D_CIRC', document.getElementById('circStrings').getString('staff.circ.checkin2.exception.no_external') + '\n');
728             }
729         }
730
731     },
732
733     'on_checkin' : function() {
734         var async = false;
735         var async_checkbox = document.getElementById('async_checkin');
736         if (async_checkbox) { async = async_checkbox.getAttribute('checked') == 'true'; }
737         if (!async) {
738             this.controller.view.checkin_barcode_entry_textbox.disabled = false;
739             this.controller.view.checkin_barcode_entry_textbox.select();
740             this.controller.view.checkin_barcode_entry_textbox.value = '';
741             this.controller.view.checkin_barcode_entry_textbox.focus();
742         }
743     },
744
745     'on_failure' : function() {
746         var async = false;
747         var async_checkbox = document.getElementById('async_checkin');
748         if (async_checkbox) { async = async_checkbox.getAttribute('checked') == 'true'; }
749         if (!async) {
750             this.controller.view.checkin_barcode_entry_textbox.disabled = false;
751             this.controller.view.checkin_barcode_entry_textbox.select();
752             this.controller.view.checkin_barcode_entry_textbox.focus();
753         }
754     },
755     
756     'spawn_copy_editor' : function() {
757
758         var obj = this;
759
760         JSAN.use('util.functional');
761
762         var list = obj.selection_list;
763
764         list = util.functional.map_list(
765             list,
766             function (o) {
767                 return o.copy_id;
768             }
769         );
770
771         JSAN.use('cat.util'); cat.util.spawn_copy_editor( { 'copy_ids' : list, 'edit' : 1 } );
772
773     }
774
775 }
776
777 dump('exiting circ.checkin.js\n');