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