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