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