]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/xul/staff_client/server/circ/util.js
lp1182605 Add sort value for holds interfaces
[working/Evergreen.git] / Open-ILS / xul / staff_client / server / circ / util.js
1 dump('entering circ/util.js\n');
2
3 if (typeof circ == 'undefined') { var circ = {}; }
4 circ.util = {};
5
6 circ.util.EXPORT_OK    = [
7     'offline_checkout_columns', 'offline_checkin_columns', 'offline_renew_columns', 'offline_inhouse_use_columns',
8     'columns', 'hold_columns', 'checkin_via_barcode', 'std_map_row_to_columns',
9     'show_last_few_circs', 'abort_transits', 'transit_columns', 'work_log_columns', 'renew_via_barcode', 'backdate_post_checkin', 'batch_hold_update'
10 ];
11 circ.util.EXPORT_TAGS    = { ':all' : circ.util.EXPORT_OK };
12
13 circ.util.abort_transits = function(selection_list) {
14     var obj = {};
15     JSAN.use('util.error'); obj.error = new util.error();
16     JSAN.use('util.network'); obj.network = new util.network();
17     JSAN.use('OpenILS.data'); obj.data = new OpenILS.data(); obj.data.init({'via':'stash'});
18     JSAN.use('util.functional');
19     var copies = util.functional.map_list( selection_list, function(o){return o.copy_id;}).join(', ');
20     var msg = document.getElementById('circStrings').getFormattedString('staff.circ.utils.abort_transits.confirm', [copies]);
21     var r = obj.error.yns_alert(
22         msg,
23         document.getElementById('circStrings').getString('staff.circ.utils.abort_transits.title'),
24         document.getElementById('circStrings').getString('staff.circ.utils.yes'),
25         document.getElementById('circStrings').getString('staff.circ.utils.no'),
26         null,
27         document.getElementById('circStrings').getString('staff.circ.confirm')
28     );
29     if (r == 0) {
30         try {
31             for (var i = 0; i < selection_list.length; i++) {
32                 var copy_id = selection_list[i].copy_id;
33                 var robj = obj.network.simple_request('FM_ATC_VOID',[ ses(), { 'copyid' : copy_id } ]);
34                 if (typeof robj.ilsevent != 'undefined') {
35                     switch(Number(robj.ilsevent)) {
36                         case 1225 /* TRANSIT_ABORT_NOT_ALLOWED */ :
37                             alert(document.getElementById('circStrings').getFormattedString('staff.circ.utils.abort_transits.not_allowed', [copy_id]) + '\n' + robj.desc);
38                         break;
39                         case 1504 /* ACTION_TRANSIT_COPY_NOT_FOUND */ :
40                             alert(document.getElementById('circStrings').getString('staff.circ.utils.abort_transits.not_found'));
41                         break;
42                         case 5000 /* PERM_FAILURE */ :
43                         break;
44                         default:
45                             throw(robj);
46                         break;
47                     }
48                 }
49             }
50         } catch(E) {
51             obj.error.standard_unexpected_error_alert(document.getElementById('circStrings').getString('staff.circ.utils.abort_transits.unexpected_error'),E);
52         }
53     }
54 };
55
56 circ.util.show_copy_details = function(copy_id) {
57     var obj = {};
58     JSAN.use('util.error'); obj.error = new util.error();
59     JSAN.use('util.window'); obj.win = new util.window();
60     JSAN.use('util.network'); obj.network = new util.network();
61     JSAN.use('OpenILS.data'); obj.data = new OpenILS.data(); obj.data.init({'via':'stash'});
62
63     if (typeof copy_id == 'object' && copy_id != null) copy_id = copy_id.id();
64
65     try {
66         var url = xulG.url_prefix('XUL_COPY_DETAILS'); // + '?copy_id=' + copy_id;
67         var my_xulG = obj.win.open( url, 'show_copy_details', 'chrome,resizable,modal', { 'copy_id' : copy_id, 'new_tab' : xulG.new_tab, 'url_prefix' : xulG.url_prefix } );
68
69         if (typeof my_xulG.retrieve_these_patrons == 'undefined') return;
70         var patrons = my_xulG.retrieve_these_patrons;
71         for (var j = 0; j < patrons.length; j++) {
72             if (typeof window.xulG == 'object' && typeof window.xulG.new_tab == 'function') {
73                 try {
74                     window.xulG.new_patron_tab( {}, { 'id' : patrons[j] } );
75                 } catch(E) {
76                     obj.error.standard_unexpected_error_alert(document.getElementById('circStrings').getString('staff.circ.utils.retrieve_patron.failure'), E);
77                 }
78             }
79         }
80
81     } catch(E) {
82         obj.error.standard_unexpected_error_alert(document.getElementById('circStrings').getString('staff.circ.utils.retrieve_copy.failure'),E);
83     }
84 };
85
86 circ.util.item_details_new = function(barcodes) {
87     try {
88         var content_params = {
89             'from_item_details_new': true,
90             'barcodes': barcodes
91         };
92         xulG.new_tab(urls.XUL_COPY_STATUS, {}, content_params);
93     } catch(E) {
94         JSAN.use('util.error');
95         (new util.error()).standard_unexpected_error_alert(document.getElementById('circStrings').getString('staff.circ.utils.retrieve_copy.failure'),E);
96     }
97 };
98
99 circ.util.backdate_post_checkin = function(circ_ids) {
100     var obj = {};
101     JSAN.use('util.error'); obj.error = new util.error();
102     JSAN.use('util.window'); obj.win = new util.window();
103     JSAN.use('util.network'); obj.network = new util.network();
104     JSAN.use('OpenILS.data'); obj.data = new OpenILS.data(); obj.data.init({'via':'stash'});
105     JSAN.use('util.sound'); obj.sound = new util.sound();
106
107     var circStrings = document.getElementById('circStrings');
108
109     dojo.forEach(
110         circ_ids,
111         function(element,idx,list) {
112             if (typeof element == 'object' && element != null) list[idx] = element.id();
113         }
114     );
115
116     try {
117         var url = xulG.url_prefix('XUL_BACKDATE');
118         var my_xulG = obj.win.open( url, 'backdate_post_checkin', 'chrome,resizable,modal', { 'circ_ids' : circ_ids } );
119
120         return my_xulG;
121
122     } catch(E) {
123         obj.error.standard_unexpected_error_alert(circStrings.getString('staff.circ.utils.retrieve_copy.failure'),E);
124     }
125 };
126
127
128 circ.util.show_last_few_circs = function(selection_list) {
129     var obj = {};
130     JSAN.use('util.error'); obj.error = new util.error();
131     JSAN.use('util.window'); obj.win = new util.window();
132     JSAN.use('util.network'); obj.network = new util.network();
133     JSAN.use('OpenILS.data'); obj.data = new OpenILS.data(); obj.data.init({'via':'stash'});
134
135     for (var i = 0; i < selection_list.length; i++) {
136         try {
137             if (typeof selection_list[i].copy_id == 'undefined' || selection_list[i].copy_id == null) continue;
138             var url = xulG.url_prefix('XUL_CIRC_SUMMARY'); // + '?copy_id=' + selection_list[i].copy_id + '&count=' + count;
139             var my_xulG = obj.win.open( url, 'show_last_few_circs', 'chrome,resizable,modal', { 'copy_id' : selection_list[i].copy_id, 'new_tab' : xulG.new_tab, 'url_prefix': xulG.url_prefix } );
140
141             if (typeof my_xulG.retrieve_these_patrons == 'undefined') continue;
142             var patrons = my_xulG.retrieve_these_patrons;
143             for (var j = 0; j < patrons.length; j++) {
144                 if (typeof window.xulG == 'object' && typeof window.xulG.new_tab == 'function') {
145                     try {
146                         window.xulG.new_patron_tab( {}, { 'id' : patrons[j] } );
147                     } catch(E) {
148                         obj.error.standard_unexpected_error_alert(document.getElementById('circStrings').getString('staff.circ.utils.retrieve_patron.failure') ,E);
149                     }
150                 }
151             }
152
153         } catch(E) {
154             obj.error.standard_unexpected_error_alert(document.getElementById('circStrings').getString('staff.circ.utils.retrieve_circs.failure') ,E);
155         }
156     }
157 };
158
159 circ.util.offline_checkout_columns = function(modify,params) {
160
161     var c = [
162         {
163             'id' : 'timestamp',
164             'label' : document.getElementById('circStrings').getString('staff.circ.utils.offline.timestamp'),
165             'flex' : 1,
166             'primary' : false,
167             'hidden' : true,
168             'editable' : false, 'render' : function(my) { return my.timestamp; }
169         },
170         {
171             'id' : 'checkout_time',
172             'label' : document.getElementById('circStrings').getString('staff.circ.utils.offline.checkout_time'),
173             'flex' : 1,
174             'primary' : false,
175             'hidden' : true,
176             'editable' : false, 'render' : function(my) { return my.checkout_time; }
177         },
178         {
179             'id' : 'type',
180             'label' : document.getElementById('circStrings').getString('staff.circ.utils.offline.type'),
181             'flex' : 1,
182             'primary' : false,
183             'hidden' : true,
184             'editable' : false, 'render' : function(my) { return my.type; }
185         },
186         {
187             'id' : 'noncat',
188             'label' : document.getElementById('circStrings').getString('staff.circ.utils.offline.noncat'),
189             'flex' : 1,
190             'primary' : false,
191             'hidden' : true,
192             'editable' : false, 'render' : function(my) { return my.noncat; }
193         },
194         {
195             'id' : 'noncat_type',
196             'label' : document.getElementById('circStrings').getString('staff.circ.utils.offline.noncat_type'),
197             'flex' : 1,
198             'primary' : false,
199             'hidden' : true,
200             'editable' : false, 'render' : function(my) { return my.noncat_type; }
201         },
202         {
203             'id' : 'noncat_count',
204             'label' : document.getElementById('circStrings').getString('staff.circ.utils.offline.count'),
205             'sort_type' : 'number',
206             'flex' : 1,
207             'primary' : false,
208             'hidden' : false,
209             'editable' : false, 'render' : function(my) { return my.noncat_count; }
210         },
211         {
212             'id' : 'patron_barcode',
213             'label' : document.getElementById('circStrings').getString('staff.circ.utils.offline.patron_barcode'),
214             'flex' : 1,
215             'primary' : false,
216             'hidden' : true,
217             'editable' : false, 'render' : function(my) { return my.patron_barcode; }
218         },
219         {
220             'id' : 'barcode',
221             'label' : document.getElementById('circStrings').getString('staff.circ.utils.offline.item_barcode'),
222             'flex' : 2,
223             'primary' : true,
224             'hidden' : false,
225             'editable' : false, 'render' : function(my) { return my.barcode; }
226         },
227         {
228             'id' : 'due_date',
229             'label' : document.getElementById('circStrings').getString('staff.circ.utils.offline.due_date'),
230             'flex' : 1,
231             'primary' : false,
232             'hidden' : false,
233             'editable' : false, 'render' : function(my) { return my.due_date; }
234         },
235         {
236             'id' : 'due_time',
237             'label' : document.getElementById('commonStrings').getString('staff.circ_label_due_time'),
238             'flex' : 1,
239             'primary' : false,
240             'hidden' : false,
241             'editable' : false, 'render' : function(my) { return my.due_time; }
242         }
243
244     ];
245     if (modify) for (var i = 0; i < c.length; i++) {
246         if (modify[ c[i].id ]) {
247             for (var j in modify[ c[i].id ]) {
248                 c[i][j] = modify[ c[i].id ][j];
249             }
250         }
251     }
252     if (params) {
253         if (params.just_these) {
254             JSAN.use('util.functional');
255             var new_c = [];
256             for (var i = 0; i < params.just_these.length; i++) {
257                 var x = util.functional.find_list(c,function(d){return(d.id==params.just_these[i]);});
258                 new_c.push( function(y){ return y; }( x ) );
259             }
260             c = new_c;
261         }
262         if (params.except_these) {
263             JSAN.use('util.functional');
264             var new_c = [];
265             for (var i = 0; i < c.length; i++) {
266                 var x = util.functional.find_list(params.except_these,function(d){return(d==c[i].id);});
267                 if (!x) new_c.push(c[i]);
268             }
269             c = new_c;
270         }
271
272     }
273     return c.sort( function(a,b) { if (a.label < b.label) return -1; if (a.label > b.label) return 1; return 0; } );
274 };
275
276 circ.util.offline_checkin_columns = function(modify,params) {
277
278     var c = [
279         {
280             'id' : 'timestamp',
281             'label' : document.getElementById('circStrings').getString('staff.circ.utils.offline.timestamp'),
282             'flex' : 1,
283             'primary' : false,
284             'hidden' : true,
285             'editable' : false, 'render' : function(my) { return my.timestamp; }
286         },
287         {
288             'id' : 'backdate',
289             'label' : document.getElementById('circStrings').getString('staff.circ.utils.offline.backdate'),
290             'flex' : 1,
291             'primary' : false,
292             'hidden' : true,
293             'editable' : false, 'render' : function(my) { return my.backdate; }
294         },
295         {
296             'id' : 'type',
297             'label' : document.getElementById('circStrings').getString('staff.circ.utils.offline.type'),
298             'flex' : 1,
299             'primary' : false,
300             'hidden' : true,
301             'editable' : false, 'render' : function(my) { return my.type; }
302         },
303         {
304             'id' : 'barcode',
305             'label' : document.getElementById('circStrings').getString('staff.circ.utils.offline.item_barcode'),
306             'flex' : 2,
307             'primary' : true,
308             'hidden' : false,
309             'editable' : false, 'render' : function(my) { return my.barcode; }
310         }
311     ];
312     if (modify) for (var i = 0; i < c.length; i++) {
313         if (modify[ c[i].id ]) {
314             for (var j in modify[ c[i].id ]) {
315                 c[i][j] = modify[ c[i].id ][j];
316             }
317         }
318     }
319     if (params) {
320         if (params.just_these) {
321             JSAN.use('util.functional');
322             var new_c = [];
323             for (var i = 0; i < params.just_these.length; i++) {
324                 var x = util.functional.find_list(c,function(d){return(d.id==params.just_these[i]);});
325                 new_c.push( function(y){ return y; }( x ) );
326             }
327             c = new_c;
328         }
329         if (params.except_these) {
330             JSAN.use('util.functional');
331             var new_c = [];
332             for (var i = 0; i < c.length; i++) {
333                 var x = util.functional.find_list(params.except_these,function(d){return(d==c[i].id);});
334                 if (!x) new_c.push(c[i]);
335             }
336             c = new_c;
337         }
338
339     }
340     return c.sort( function(a,b) { if (a.label < b.label) return -1; if (a.label > b.label) return 1; return 0; } );
341 };
342
343 circ.util.offline_renew_columns = function(modify,params) {
344
345     var c = [
346         {
347             'id' : 'timestamp',
348             'label' : document.getElementById('circStrings').getString('staff.circ.utils.offline.timestamp'),
349             'flex' : 1,
350             'primary' : false,
351             'hidden' : true,
352             'editable' : false, 'render' : function(my) { return my.timestamp; }
353         },
354         {
355             'id' : 'checkout_time',
356             'label' : document.getElementById('circStrings').getString('staff.circ.utils.offline.checkout_time'),
357             'flex' : 1,
358             'primary' : false,
359             'hidden' : true,
360             'editable' : false, 'render' : function(my) { return my.checkout_time; }
361         },
362         {
363             'id' : 'type',
364             'label' : document.getElementById('circStrings').getString('staff.circ.utils.offline.type'),
365             'flex' : 1,
366             'primary' : false,
367             'hidden' : true,
368             'editable' : false, 'render' : function(my) { return my.type; }
369         },
370         {
371             'id' : 'patron_barcode',
372             'label' : document.getElementById('circStrings').getString('staff.circ.utils.offline.patron_barcode'),
373             'flex' : 1,
374             'primary' : false,
375             'hidden' : true,
376             'editable' : false, 'render' : function(my) { return my.patron_barcode; }
377         },
378         {
379             'id' : 'barcode',
380             'label' : document.getElementById('circStrings').getString('staff.circ.utils.offline.item_barcode'),
381             'flex' : 2,
382             'primary' : true,
383             'hidden' : false,
384             'editable' : false, 'render' : function(my) { return my.barcode; }
385         },
386         {
387             'id' : 'due_date',
388             'label' : document.getElementById('circStrings').getString('staff.circ.utils.offline.due_date'),
389             'flex' : 1,
390             'primary' : false,
391             'hidden' : false,
392             'editable' : false, 'render' : function(my) { return my.due_date; }
393         },
394         {
395             'id' : 'due_time',
396             'label' : document.getElementById('commonStrings').getString('staff.circ_label_due_time'),
397             'flex' : 1,
398             'primary' : false,
399             'hidden' : false,
400             'editable' : false, 'render' : function(my) { return my.due_time; }
401         }
402     ];
403     if (modify) for (var i = 0; i < c.length; i++) {
404         if (modify[ c[i].id ]) {
405             for (var j in modify[ c[i].id ]) {
406                 c[i][j] = modify[ c[i].id ][j];
407             }
408         }
409     }
410     if (params) {
411         if (params.just_these) {
412             JSAN.use('util.functional');
413             var new_c = [];
414             for (var i = 0; i < params.just_these.length; i++) {
415                 var x = util.functional.find_list(c,function(d){return(d.id==params.just_these[i]);});
416                 new_c.push( function(y){ return y; }( x ) );
417             }
418             c = new_c;
419         }
420         if (params.except_these) {
421             JSAN.use('util.functional');
422             var new_c = [];
423             for (var i = 0; i < c.length; i++) {
424                 var x = util.functional.find_list(params.except_these,function(d){return(d==c[i].id);});
425                 if (!x) new_c.push(c[i]);
426             }
427             c = new_c;
428         }
429
430     }
431     return c.sort( function(a,b) { if (a.label < b.label) return -1; if (a.label > b.label) return 1; return 0; } );
432 };
433
434 circ.util.offline_inhouse_use_columns = function(modify,params) {
435
436     var c = [
437         {
438             'id' : 'timestamp',
439             'label' : document.getElementById('circStrings').getString('staff.circ.utils.offline.timestamp'),
440             'flex' : 1,
441             'primary' : false,
442             'hidden' : true,
443             'editable' : false, 'render' : function(my) { return my.timestamp; }
444         },
445         {
446             'id' : 'use_time',
447             'label' : document.getElementById('circStrings').getString('staff.circ.utils.offline.use_time'),
448             'flex' : 1,
449             'primary' : false,
450             'hidden' : true,
451             'editable' : false, 'render' : function(my) { return my.use_time; }
452         },
453         {
454             'id' : 'type',
455             'label' : document.getElementById('circStrings').getString('staff.circ.utils.offline.type'),
456             'flex' : 1,
457             'primary' : false,
458             'hidden' : true,
459             'editable' : false, 'render' : function(my) { return my.type; }
460         },
461         {
462             'id' : 'count',
463             'label' : document.getElementById('circStrings').getString('staff.circ.utils.offline.count'),
464             'sort_type' : 'number',
465             'flex' : 1,
466             'primary' : false,
467             'hidden' : false,
468             'editable' : false, 'render' : function(my) { return my.count; }
469         },
470         {
471             'id' : 'barcode',
472             'label' : document.getElementById('circStrings').getString('staff.circ.utils.offline.item_barcode'),
473             'flex' : 2,
474             'primary' : true,
475             'hidden' : false,
476             'editable' : false, 'render' : function(my) { return my.barcode; }
477         }
478     ];
479     if (modify) for (var i = 0; i < c.length; i++) {
480         if (modify[ c[i].id ]) {
481             for (var j in modify[ c[i].id ]) {
482                 c[i][j] = modify[ c[i].id ][j];
483             }
484         }
485     }
486     if (params) {
487         if (params.just_these) {
488             JSAN.use('util.functional');
489             var new_c = [];
490             for (var i = 0; i < params.just_these.length; i++) {
491                 var x = util.functional.find_list(c,function(d){return(d.id==params.just_these[i]);});
492                 new_c.push( function(y){ return y; }( x ) );
493             }
494             c = new_c;
495         }
496         if (params.except_these) {
497             JSAN.use('util.functional');
498             var new_c = [];
499             for (var i = 0; i < c.length; i++) {
500                 var x = util.functional.find_list(params.except_these,function(d){return(d==c[i].id);});
501                 if (!x) new_c.push(c[i]);
502             }
503             c = new_c;
504         }
505
506     }
507     return c.sort( function(a,b) { if (a.label < b.label) return -1; if (a.label > b.label) return 1; return 0; } );
508 };
509
510 circ.util.columns = function(modify,params) {
511
512     JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.init({'via':'stash'});
513     JSAN.use('util.network'); var network = new util.network();
514     JSAN.use('util.money');
515
516     var c = [
517         {
518             'id' : 'acp_id',
519             'fm_class' : 'acp',
520             'label' : document.getElementById('commonStrings').getString('staff.acp_label_id'),
521             'flex' : 1,
522             'primary' : false,
523             'hidden' : true,
524             'editable' : false, 'render' : function(my) { return my.acp.id(); }
525         },
526         {
527             'id' : 'circ_id',
528             'fm_class' : 'circ',
529             'label' : document.getElementById('commonStrings').getString('staff.circ_label_id'),
530             'flex' : 1,
531             'primary' : false,
532             'hidden' : true,
533             'editable' : false, 'render' : function(my) { return my.circ ? my.circ.id() : ""; }
534         },
535         {
536             'id' : 'mvr_doc_id',
537             'fm_class' : 'mvr',
538             'label' : document.getElementById('commonStrings').getString('staff.mvr_label_doc_id'),
539             'flex' : 1,
540             'primary' : false,
541             'hidden' : true,
542             'editable' : false, 'render' : function(my) { return my.mvr.doc_id(); }
543         },
544         {
545             'id' : 'service',
546             'label' : document.getElementById('commonStrings').getString('staff.checkout_column_label_service'),
547             'flex' : 1,
548             'primary' : false,
549             'hidden' : true,
550             'editable' : false, 'render' : function(my) { return my.service; }
551         },
552         {
553             'id' : 'barcode',
554             'fm_class' : 'acp',
555             'label' : document.getElementById('commonStrings').getString('staff.acp_label_barcode'),
556             'flex' : 1,
557             'primary' : false,
558             'hidden' : true,
559             'editable' : false, 'render' : function(my) { return my.acp.barcode(); }
560         },
561         {
562             'id' : 'call_number',
563             'fm_class' : 'acp',
564             'label' : document.getElementById('commonStrings').getString('staff.acp_label_call_number'),
565             'flex' : 1,
566             'primary' : false,
567             'hidden' : true,
568             'sort_value' : function(my,scratch_data) {
569                                 var result_label = "label_sortkey";
570                                 return sort_call_numbers_by_label_sortkey(my, scratch_data, result_label);
571                         },
572                         
573             'editable' : false, 'render' : function(my,scratch_data) {
574                                 
575                                 var result_label = "render_label";
576                                 return sort_call_numbers_by_label_sortkey(my, scratch_data, result_label);
577                         }  
578
579         },
580         {
581             'id' : 'owning_lib',
582             'fm_class' : 'acn',
583             'label' : document.getElementById('circStrings').getString('staff.circ.utils.owning_lib'),
584             'flex' : 1,
585             'primary' : false,
586             'hidden' : true,
587             'editable' : false, 'render' : function(my) {
588                 if (Number(my.acn.owning_lib())>=0) {
589                     return data.hash.aou[ my.acn.owning_lib() ].shortname();
590                 } else {
591                     return my.acn.owning_lib().shortname();
592                 }
593             }
594         },
595         {
596             'id' : 'prefix',
597             'fm_class' : 'acn',
598             'label' : document.getElementById('circStrings').getString('staff.circ.utils.prefix'),
599             'flex' : 1,
600             'primary' : false,
601             'hidden' : true,
602             'editable' : false, 'render' : function(my,scratch_data) {
603                 var acn_id;
604                 if (my.acn) {
605                     if (typeof my.acn == 'object') {
606                         acn_id = my.acn.id();
607                     } else {
608                         acn_id = my.acn;
609                     }
610                 } else if (my.acp) {
611                     if (typeof my.acp.call_number() == 'object' && my.acp.call_number() != null) {
612                         acn_id = my.acp.call_number().id();
613                     } else {
614                         acn_id = my.acp.call_number();
615                     }
616                 }
617                 if (!acn_id && acn_id != 0) {
618                     return '';
619                 } else if (acn_id == -1) {
620                     return '';
621                 } else if (acn_id == -2) {
622                     return document.getElementById('circStrings').getString('staff.circ.utils.retrieving');
623                 } else {
624                     if (!my.acn) {
625                         if (typeof scratch_data == 'undefined' || scratch_data == null) {
626                             scratch_data = {};
627                         }
628                         if (typeof scratch_data['acn_map'] == 'undefined') {
629                             scratch_data['acn_map'] = {};
630                         }
631                         if (typeof scratch_data['acn_map'][ acn_id ] == 'undefined') {
632                             var x = network.simple_request("FM_ACN_RETRIEVE.authoritative",[ acn_id ]);
633                             if (x.ilsevent) {
634                                 return document.getElementById('circStrings').getString('staff.circ.utils.not_cataloged');
635                             } else {
636                                 my.acn = x;
637                                 scratch_data['acn_map'][ acn_id ] = my.acn;
638                             }
639                         } else {
640                             my.acn = scratch_data['acn_map'][ acn_id ];
641                         }
642                     }
643                 }
644
645                 if (typeof my.acn != 'object') return '';
646                 return (typeof my.acn.prefix() == 'object')
647                     ? my.acn.prefix().label()
648                     : data.lookup("acnp", my.acn.prefix() ).label();
649             }
650         },
651         {
652             'id' : 'suffix',
653             'fm_class' : 'acn',
654             'label' : document.getElementById('circStrings').getString('staff.circ.utils.suffix'),
655             'flex' : 1,
656             'primary' : false,
657             'hidden' : true,
658             'editable' : false, 'render' : function(my,scratch_data) {
659                 var acn_id;
660                 if (my.acn) {
661                     if (typeof my.acn == 'object') {
662                         acn_id = my.acn.id();
663                     } else {
664                         acn_id = my.acn;
665                     }
666                 } else if (my.acp) {
667                     if (typeof my.acp.call_number() == 'object' && my.acp.call_number() != null) {
668                         acn_id = my.acp.call_number().id();
669                     } else {
670                         acn_id = my.acp.call_number();
671                     }
672                 }
673                 if (!acn_id && acn_id != 0) {
674                     return '';
675                 } else if (acn_id == -1) {
676                     return '';
677                 } else if (acn_id == -2) {
678                     return document.getElementById('circStrings').getString('staff.circ.utils.retrieving');
679                 } else {
680                     if (!my.acn) {
681                         if (typeof scratch_data == 'undefined' || scratch_data == null) {
682                             scratch_data = {};
683                         }
684                         if (typeof scratch_data['acn_map'] == 'undefined') {
685                             scratch_data['acn_map'] = {};
686                         }
687                         if (typeof scratch_data['acn_map'][ acn_id ] == 'undefined') {
688                             var x = network.simple_request("FM_ACN_RETRIEVE.authoritative",[ acn_id ]);
689                             if (x.ilsevent) {
690                                 return document.getElementById('circStrings').getString('staff.circ.utils.not_cataloged');
691                             } else {
692                                 my.acn = x;
693                                 scratch_data['acn_map'][ acn_id ] = my.acn;
694                             }
695                         } else {
696                             my.acn = scratch_data['acn_map'][ acn_id ];
697                         }
698                     }
699                 }
700
701                 if (typeof my.acn != 'object') return '';
702                 return (typeof my.acn.suffix() == 'object')
703                     ? my.acn.suffix().label()
704                     : data.lookup("acns", my.acn.suffix() ).label();
705             }
706         },
707         {
708             'id' : 'label_class',
709             'fm_class' : 'acn',
710             'label' : document.getElementById('circStrings').getString('staff.circ.utils.label_class'),
711             'flex' : 1,
712             'primary' : false,
713             'hidden' : true,
714             'editable' : false, 'render' : function(my,scratch_data) {
715                 var acn_id;
716                 if (my.acn) {
717                     if (typeof my.acn == 'object') {
718                         acn_id = my.acn.id();
719                     } else {
720                         acn_id = my.acn;
721                     }
722                 } else if (my.acp) {
723                     if (typeof my.acp.call_number() == 'object' && my.acp.call_number() != null) {
724                         acn_id = my.acp.call_number().id();
725                     } else {
726                         acn_id = my.acp.call_number();
727                     }
728                 }
729                 if (!acn_id && acn_id != 0) {
730                     return '';
731                 } else if (acn_id == -1) {
732                     return '';
733                 } else if (acn_id == -2) {
734                     return document.getElementById('circStrings').getString('staff.circ.utils.retrieving');
735                 } else {
736                     if (!my.acn) {
737                         if (typeof scratch_data == 'undefined' || scratch_data == null) {
738                             scratch_data = {};
739                         }
740                         if (typeof scratch_data['acn_map'] == 'undefined') {
741                             scratch_data['acn_map'] = {};
742                         }
743                         if (typeof scratch_data['acn_map'][ acn_id ] == 'undefined') {
744                             var x = network.simple_request("FM_ACN_RETRIEVE.authoritative",[ acn_id ]);
745                             if (x.ilsevent) {
746                                 return document.getElementById('circStrings').getString('staff.circ.utils.not_cataloged');
747                             } else {
748                                 my.acn = x;
749                                 scratch_data['acn_map'][ acn_id ] = my.acn;
750                             }
751                         } else {
752                             my.acn = scratch_data['acn_map'][ acn_id ];
753                         }
754                     }
755                 }
756
757                 if (typeof my.acn != 'object') return '';
758                 return (typeof my.acn.label_class() == 'object') ? my.acn.label_class().name() : my.acn.label_class();
759             }
760         },
761         {
762             'id' : 'parts',
763             'fm_class' : 'acp',
764             'label' : document.getElementById('commonStrings').getString('staff.acp_label_parts'),
765             'flex' : 1,
766             'sort_type' : 'number',
767             'primary' : false,
768             'hidden' : true,
769             'editable' : false, 'render' : function(my) {
770                 if (! my.acp.parts()) return '';
771                 var parts = my.acp.parts();
772                 var display_string = '';
773                 for (var i = 0; i < parts.length; i++) {
774                     if (my.doc_id) {
775                         if (my.doc_id == parts[i].record()) {
776                             return parts[i].label();
777                         }
778                     } else {
779                         if (i != 0) display_string += ' : ';
780                         display_string += parts[i].label();
781                     }
782                 }
783                 return display_string;
784             }
785         },
786         {
787             'id' : 'copy_number',
788             'fm_class' : 'acp',
789             'label' : document.getElementById('commonStrings').getString('staff.acp_label_copy_number'),
790             'flex' : 1,
791             'sort_type' : 'number',
792             'primary' : false,
793             'hidden' : true,
794             'editable' : false, 'render' : function(my) { return my.acp.copy_number(); }
795         },
796         {
797             'id' : 'location',
798             'fm_class' : 'acp',
799             'label' : document.getElementById('commonStrings').getString('staff.acp_label_location'),
800             'flex' : 1,
801             'primary' : false,
802             'hidden' : true,
803             'editable' : false, 'render' : function(my) {
804                 if (Number(my.acp.location())>=0) {
805                     return data.lookup("acpl", my.acp.location() ).name();
806                 } else {
807                     return my.acp.location().name();
808                 }
809             }
810         },
811         {
812             'id' : 'loan_duration',
813             'fm_class' : 'acp',
814             'label' : document.getElementById('commonStrings').getString('staff.acp_label_loan_duration'),
815             'flex' : 1,
816             'primary' : false,
817             'hidden' : true,
818             'editable' : false, 'render' : function(my) {
819                 switch(Number(my.acp.loan_duration())) {
820                     case 1:
821                         return document.getElementById('circStrings').getString('staff.circ.utils.loan_duration.short');
822                         break;
823                     case 2:
824                         return document.getElementById('circStrings').getString('staff.circ.utils.loan_duration.normal');
825                         break;
826                     case 3:
827                         return document.getElementById('circStrings').getString('staff.circ.utils.loan_duration.long');
828                         break;
829                 };
830             }
831         },
832         {
833             'id' : 'circ_lib',
834             'fm_class' : 'acp',
835             'label' : document.getElementById('commonStrings').getString('staff.acp_label_circ_lib'),
836             'flex' : 1,
837             'primary' : false,
838             'hidden' : true,
839             'editable' : false, 'render' : function(my) {
840                 if (Number(my.acp.circ_lib())>=0) {
841                     return data.hash.aou[ my.acp.circ_lib() ].shortname();
842                 } else {
843                     return my.acp.circ_lib().shortname();
844                 }
845             }
846         },
847         {
848             'id' : 'fine_level',
849             'fm_class' : 'acp',
850             'label' : document.getElementById('commonStrings').getString('staff.acp_label_fine_level'),
851             'flex' : 1,
852             'primary' : false,
853             'hidden' : true,
854             'editable' : false, 'render' : function(my) {
855                 switch(Number(my.acp.fine_level())) {
856                     case 1:
857                         return document.getElementById('circStrings').getString('staff.circ.utils.fine_level.low');
858                         break;
859                     case 2:
860                         return document.getElementById('circStrings').getString('staff.circ.utils.fine_level.normal');
861                         break;
862                     case 3:
863                         return document.getElementById('circStrings').getString('staff.circ.utils.fine_level.high');
864                         break;
865                 };
866             }
867         },
868         {
869             'id' : 'circulate',
870             'fm_class' : 'acp',
871             'label' : document.getElementById('circStrings').getString('staff.circ.utils.circulate'),
872             'flex' : 1,
873             'primary' : false,
874             'hidden' : true,
875             'editable' : false, 'render' : function(my) {
876                 if (get_bool( my.acp.circulate() )) {
877                     return document.getElementById('circStrings').getString('staff.circ.utils.yes');
878                 } else {
879                     return document.getElementById('circStrings').getString('staff.circ.utils.no');
880                 }
881             }
882         },
883         {
884             'id' : 'deleted',
885             'fm_class' : 'acp',
886             'label' : document.getElementById('circStrings').getString('staff.circ.utils.deleted'),
887             'flex' : 1,
888             'primary' : false,
889             'hidden' : true,
890             'editable' : false, 'render' : function(my) {
891                 if (get_bool( my.acp.deleted() )) {
892                     return document.getElementById('circStrings').getString('staff.circ.utils.yes');
893                 } else {
894                     return document.getElementById('circStrings').getString('staff.circ.utils.no');
895                 }
896             }
897         },
898         {
899             'id' : 'holdable',
900             'fm_class' : 'acp',
901             'label' : document.getElementById('circStrings').getString('staff.circ.utils.holdable'),
902             'flex' : 1,
903             'primary' : false,
904             'hidden' : true,
905             'editable' : false, 'render' : function(my) {
906                 if (get_bool( my.acp.holdable() )) {
907                     return document.getElementById('circStrings').getString('staff.circ.utils.yes');
908                 } else {
909                     return document.getElementById('circStrings').getString('staff.circ.utils.no');
910                 }
911             }
912         },
913         {
914             'id' : 'floating',
915             'fm_class' : 'acp',
916             'label' : document.getElementById('circStrings').getString('staff.circ.utils.floating'),
917             'flex' : 1,
918             'primary' : false,
919             'hidden' : true,
920             'editable' : false, 'render' : function(my) {
921                 if (my.acp.floating() && typeof my.acp.floating() == 'object') {
922                     return my.acp.floating().name();
923                 } else {
924                     if (get_bool( my.acp.floating() )) {
925                         return document.getElementById('circStrings').getString('staff.circ.utils.yes');
926                     } else {
927                         return document.getElementById('circStrings').getString('staff.circ.utils.no');
928                     }
929                 }
930             }
931         },
932
933         {
934             'id' : 'opac_visible',
935             'fm_class' : 'acp',
936             'label' : document.getElementById('circStrings').getString('staff.circ.utils.opac_visible'),
937             'flex' : 1,
938             'primary' : false,
939             'hidden' : true,
940             'editable' : false, 'render' : function(my) {
941                 if (get_bool( my.acp.opac_visible() )) {
942                     return document.getElementById('circStrings').getString('staff.circ.utils.yes');
943                 } else {
944                     return document.getElementById('circStrings').getString('staff.circ.utils.no');
945                 }
946             }
947         },
948         {
949             'id' : 'acp_mint_condition',
950             'fm_class' : 'acp',
951             'label' : document.getElementById('circStrings').getString('staff.circ.utils.acp_mint_condition'),
952             'flex' : 0,
953             'primary' : false,
954             'hidden' : true,
955             'editable' : false, 'render' : function(my) {
956                 if (get_bool( my.acp.mint_condition() )) {
957                     return document.getElementById('circStrings').getString('staff.circ.utils.acp_mint_condition.true');
958                 } else {
959                     return document.getElementById('circStrings').getString('staff.circ.utils.acp_mint_condition.false');
960                 }
961             }
962         },
963         {
964             'fm_class' : 'acp',
965             'id' : 'ref',
966             'label' : document.getElementById('circStrings').getString('staff.circ.utils.reference'),
967             'flex' : 1,
968             'primary' : false,
969             'hidden' : true,
970             'editable' : false, 'render' : function(my) {
971                 if (get_bool( my.acp.ref() )) {
972                     return document.getElementById('circStrings').getString('staff.circ.utils.yes');
973                 } else {
974                     return document.getElementById('circStrings').getString('staff.circ.utils.no');
975                 }
976             }
977         },
978         {
979             'fm_class' : 'acp',
980             'id' : 'deposit',
981             'label' : document.getElementById('circStrings').getString('staff.circ.utils.deposit'),
982             'flex' : 1,
983             'primary' : false,
984             'hidden' : true,
985             'editable' : false, 'render' : function(my) {
986                 if (get_bool( my.acp.deposit() )) {
987                     return document.getElementById('circStrings').getString('staff.circ.utils.yes');
988                 } else {
989                     return document.getElementById('circStrings').getString('staff.circ.utils.no');
990                 }
991             }
992         },
993         {
994             'fm_class' : 'acp',
995             'id' : 'deposit_amount',
996             'label' : document.getElementById('commonStrings').getString('staff.acp_label_deposit_amount'),
997             'flex' : 1,
998             'primary' : false,
999             'hidden' : true,
1000             'editable' : false, 'render' : function(my) {
1001                 if (my.acp.price() == null) {
1002                     return document.getElementById('circStrings').getString('staff.circ.utils.unset');
1003                 } else {
1004                     return util.money.sanitize(my.acp.deposit_amount());
1005                 }
1006             },
1007             'sort_type' : 'money'
1008         },
1009         {
1010             'fm_class' : 'acp',
1011             'id' : 'price',
1012             'label' : document.getElementById('commonStrings').getString('staff.acp_label_price'),
1013             'flex' : 1,
1014             'primary' : false,
1015             'hidden' : true,
1016             'editable' : false, 'render' : function(my) {
1017                 if (my.acp.price() == null) {
1018                     return document.getElementById('circStrings').getString('staff.circ.utils.unset');
1019                 } else {
1020                     return util.money.sanitize(my.acp.price());
1021                 }
1022             },
1023             'sort_type' : 'money'
1024         },
1025         {
1026             'fm_class' : 'acp',
1027             'id' : 'circ_as_type',
1028             'label' : document.getElementById('commonStrings').getString('staff.acp_label_circ_as_type'),
1029             'flex' : 1,
1030             'primary' : false,
1031             'hidden' : true,
1032             'editable' : false, 'render' : function(my) {
1033                 return my.acp.circ_as_type() != null && my.acp.circ_as_type() == 'object'
1034                     ? my.acp.circ_as_type()
1035                     : ( typeof data.hash.citm[ my.acp.circ_as_type() ] != 'undefined'
1036                         ? data.hash.citm[ my.acp.circ_as_type() ].value
1037                         : ''
1038                     );
1039             }
1040         },
1041         {
1042             'fm_class' : 'acp',
1043             'id' : 'circ_modifier',
1044             'label' : document.getElementById('commonStrings').getString('staff.acp_label_circ_modifier'),
1045             'flex' : 1,
1046             'primary' : false,
1047             'hidden' : true,
1048             'editable' : false, 'render' : function(my) { var cm = my.acp.circ_modifier(); return document.getElementById('commonStrings').getFormattedString('staff.circ_modifier.display',[cm,data.hash.ccm[cm].name(),data.hash.ccm[cm].description()]); }
1049         },
1050         {
1051             'id' : 'status_changed_time',
1052             'fm_class' : 'acp',
1053             'label' : document.getElementById('circStrings').getString('staff.circ.utils.status_changed_time'),
1054             'flex' : 1,
1055             'sort_type' : 'date',
1056             'primary' : false,
1057             'hidden' : true,
1058             'editable' : false, 'render' : function(my) { return util.date.formatted_date( my.acp.status_changed_time(), '%{localized}' ); },
1059             'sort_value' : function(my) {
1060                 return util.date.db_date2Date(
1061                     my.acp
1062                     ? my.acp.status_changed_time()
1063                     : null
1064                 ).getTime();
1065             }
1066         },
1067         {
1068             'fm_class' : 'circ',
1069             'id' : 'checkout_lib',
1070             'label' : document.getElementById('circStrings').getString('staff.circ.utils.checkout_lib'),
1071             'flex' : 1,
1072             'primary' : false,
1073             'hidden' : true,
1074             'editable' : false, 'render' : function(my) {
1075                 if (my.circ) {
1076                     return data.hash.aou[ my.circ.circ_lib() ].shortname();
1077                 } else {
1078                     return "";
1079                 }
1080             }
1081         },
1082         {
1083             'fm_class' : 'circ',
1084             'id' : 'xact_start',
1085             'label' : document.getElementById('circStrings').getString('staff.circ.utils.xact_start'),
1086             'flex' : 1,
1087             'sort_type' : 'date',
1088             'primary' : false,
1089             'hidden' : true,
1090             'editable' : false, 'render' : function(my) {
1091                 if (my.circ) {
1092                     return util.date.formatted_date( my.circ.xact_start(), '%{localized}' );
1093                 } else {
1094                     return "";
1095                 }
1096             }
1097             ,'sort_value' : function(my) {
1098                 return util.date.db_date2Date(
1099                     my.circ
1100                     ? my.circ.xact_start()
1101                     : null
1102                 ).getTime();
1103             }
1104         },
1105         {
1106             'fm_class' : 'circ',
1107             'id' : 'checkin_time',
1108             'label' : document.getElementById('circStrings').getString('staff.circ.utils.checkin_time'),
1109             'flex' : 1,
1110             'sort_type' : 'date',
1111             'primary' : false,
1112             'hidden' : true,
1113             'editable' : false, 'render' : function(my) {
1114                 if (my.circ) {
1115                     return util.date.formatted_date( my.circ.checkin_time(), '%{localized}' );
1116                 } else {
1117                     return "";
1118                 }
1119             }
1120             ,'sort_value' : function(my) {
1121                 return util.date.db_date2Date(
1122                     my.circ
1123                     ? my.circ.checkin_time()
1124                     : null
1125                 ).getTime();
1126             }
1127         },
1128         {
1129             'fm_class' : 'circ',
1130             'id' : 'xact_finish',
1131             'label' : document.getElementById('circStrings').getString('staff.circ.utils.xact_finish'),
1132             'flex' : 1,
1133             'sort_type' : 'date',
1134             'primary' : false,
1135             'hidden' : true,
1136             'editable' : false, 'render' : function(my) { return my.circ ? util.date.formatted_date( my.circ.xact_finish(), '%{localized}' ) : ""; },
1137             'sort_value' : function(my) {
1138                 return util.date.db_date2Date(
1139                     my.circ
1140                     ? my.circ.xact_finish()
1141                     : null
1142                 ).getTime(); }
1143         },
1144         {
1145             'fm_class' : 'circ',
1146             'id' : 'due_date',
1147             'label' : document.getElementById('commonStrings').getString('staff.circ_label_due_date'),
1148             'flex' : 1,
1149             'sort_type' : 'date',
1150             'primary' : false,
1151             'hidden' : true,
1152             'editable' : false, 'render' : function(my) {
1153                 if (my.circ) {
1154                     return util.date.formatted_date( my.circ.due_date(), '%{localized}' );
1155                 } else {
1156                     return "";
1157                 }
1158             }
1159             ,'sort_value' : function(my) {
1160                 return util.date.db_date2Date(
1161                     my.circ
1162                     ? my.circ.due_date()
1163                     : null
1164                 ).getTime();
1165             }
1166         },
1167         {
1168             'fm_class' : 'acp',
1169             'id' : 'acp_create_date',
1170             'label' : document.getElementById('circStrings').getString('staff.circ.utils.create_date'),
1171             'flex' : 1,
1172             'sort_type' : 'date',
1173             'primary' : false,
1174             'hidden' : true,
1175             'editable' : false, 'render' : function(my) { return util.date.formatted_date( my.acp.create_date(), '%{localized}' ); }
1176             ,'sort_value' : function(my) {
1177                 return util.date.db_date2Date(
1178                     my.acp
1179                     ? my.acp.create_date()
1180                     : null
1181                 ).getTime();
1182             }
1183         },
1184         {
1185             'fm_class' : 'acp',
1186             'id' : 'acp_edit_date',
1187             'label' : document.getElementById('circStrings').getString('staff.circ.utils.edit_date'),
1188             'flex' : 1,
1189             'sort_type' : 'date',
1190             'primary' : false,
1191             'hidden' : true,
1192             'editable' : false, 'render' : function(my) { return util.date.formatted_date( my.acp.edit_date(), '%{localized}' ); }
1193             ,'sort_value' : function(my) {
1194                 return util.date.db_date2Date(
1195                     my.acp
1196                     ? my.acp.edit_date()
1197                     : null
1198                 ).getTime();
1199             }
1200         },
1201         {
1202             'fm_class' : 'mvr',
1203             'id' : 'title',
1204             'label' : document.getElementById('commonStrings').getString('staff.mvr_label_title'),
1205             'flex' : 2,
1206             'sort_type' : 'title',
1207             'primary' : false,
1208             'hidden' : true,
1209             'editable' : false, 'render' : function(my) {
1210                 if (my.mvr) {
1211                     if (my.mvr.doc_id() == -1) {
1212                         return my.acp.dummy_title();
1213                     } else {
1214                         return my.mvr.title();
1215                     }
1216                 } else {
1217                     return my.acp.dummy_title();
1218                 }
1219             }
1220         },
1221         {
1222             'fm_class' : 'mvr',
1223             'id' : 'author',
1224             'label' : document.getElementById('commonStrings').getString('staff.mvr_label_author'),
1225             'flex' : 1,
1226             'primary' : false,
1227             'hidden' : true,
1228             'editable' : false, 'render' : function(my) {
1229                 if (my.mvr) {
1230                     if (my.mvr.doc_id() == -1) {
1231                         return my.acp.dummy_author();
1232                     } else {
1233                         return my.mvr.author();
1234                     }
1235                 } else {
1236                     return my.acp.dummy_author();
1237                 }
1238             }
1239         },
1240         {
1241             'fm_class' : 'mvr',
1242             'id' : 'edition',
1243             'label' : document.getElementById('circStrings').getString('staff.circ.utils.edition'),
1244             'flex' : 1,
1245             'primary' : false,
1246             'hidden' : true,
1247             'editable' : false, 'render' : function(my) { return my.mvr.edition(); }
1248         },
1249         {
1250             'fm_class' : 'mvr',
1251             'id' : 'isbn',
1252             'label' : document.getElementById('circStrings').getString('staff.circ.utils.isbn'),
1253             'flex' : 1,
1254             'primary' : false,
1255             'hidden' : true,
1256             'editable' : false, 'render' : function(my) { 
1257                 if (my.mvr) {
1258                     if (my.mvr.doc_id() == -1) {
1259                         return my.acp.dummy_isbn();
1260                     } else {
1261                         return my.mvr.isbn();
1262                     }
1263                 } else {
1264                     return my.acp.dummy_isbn();
1265                 }
1266             }
1267         },
1268         {
1269             'fm_class' : 'mvr',
1270             'id' : 'pubdate',
1271             'label' : document.getElementById('circStrings').getString('staff.circ.utils.pubdate'),
1272             'flex' : 1,
1273             'primary' : false,
1274             'hidden' : true,
1275             'editable' : false, 'render' : function(my) { return my.mvr.pubdate(); }
1276         },
1277         {
1278             'fm_class' : 'mvr',
1279             'id' : 'publisher',
1280             'label' : document.getElementById('circStrings').getString('staff.circ.utils.publisher'),
1281             'flex' : 1,
1282             'primary' : false,
1283             'hidden' : true,
1284             'editable' : false, 'render' : function(my) { return my.mvr.publisher(); }
1285         },
1286         {
1287             'fm_class' : 'mvr',
1288             'id' : 'tcn',
1289             'label' : document.getElementById('circStrings').getString('staff.circ.utils.tcn'),
1290             'flex' : 1,
1291             'primary' : false,
1292             'hidden' : true,
1293             'editable' : false, 'render' : function(my) { return my.mvr.tcn(); }
1294         },
1295         {
1296             'fm_class' : 'circ',
1297             'id' : 'renewal_remaining',
1298             'label' : document.getElementById('commonStrings').getString('staff.circ_label_renewal_remaining'),
1299             'flex' : 0,
1300             'primary' : false,
1301             'hidden' : true,
1302             'editable' : false, 'render' : function(my) {
1303                 if (my.circ) {
1304                     return my.circ.renewal_remaining();
1305                 } else {
1306                     return "";
1307                 }
1308             },
1309             'sort_type' : 'number'
1310         },
1311         {
1312             'fm_class' : 'circ',
1313             'id' : 'stop_fines',
1314             'label' : document.getElementById('circStrings').getString('staff.circ.utils.stop_fines'),
1315             'flex' : 0,
1316             'primary' : false,
1317             'hidden' : true,
1318             'editable' : false, 'render' : function(my) {
1319                 if (my.circ) {
1320                     return my.circ.stop_fines();
1321                 } else {
1322                     return "";
1323                 }
1324             }
1325         },
1326         {
1327             'fm_class' : 'circ',
1328             'id' : 'stop_fines_time',
1329             'label' : document.getElementById('circStrings').getString('staff.circ.utils.stop_fines_time'),
1330             'flex' : 0,
1331             'sort_type' : 'date',
1332             'primary' : false,
1333             'hidden' : true,
1334             'editable' : false, 'render' : function(my) {
1335                 if (my.circ) {
1336                     return util.date.formatted_date( my.circ.stop_fines_time(), '%{localized}' );
1337                 } else {
1338                     return "";
1339                 }
1340             }
1341             ,'sort_value' : function(my) {
1342                 return util.date.db_date2Date(
1343                     my.circ
1344                     ? my.circ.stop_fines_time()
1345                     : null
1346                 ).getTime();
1347             }
1348         },
1349         {
1350             'fm_class' : 'acp',
1351             'id' : 'acp_status',
1352             'label' : document.getElementById('commonStrings').getString('staff.acp_label_status'),
1353             'flex' : 1,
1354             'primary' : false,
1355             'hidden' : true,
1356             'editable' : false, 'render' : function(my) {
1357                 if (Number(my.acp.status())>=0) {
1358                     return data.hash.ccs[ my.acp.status() ].name();
1359                 } else {
1360                     return my.acp.status().name();
1361                 }
1362             }
1363         },
1364         {
1365             'id' : 'route_to',
1366             'label' : document.getElementById('circStrings').getString('staff.circ.utils.route_to'),
1367             'flex' : 1,
1368             'primary' : false,
1369             'hidden' : true,
1370             'editable' : false, 'render' : function(my) { return my.route_to.toString(); }
1371         },
1372         {
1373             'id' : 'message',
1374             'label' : document.getElementById('circStrings').getString('staff.circ.utils.message'),
1375             'flex' : 1,
1376             'primary' : false,
1377             'hidden' : true,
1378             'editable' : false, 'render' : function(my) { return my.message.toString(); }
1379         },
1380         {
1381             'id' : 'uses',
1382             'label' : document.getElementById('circStrings').getString('staff.circ.utils.uses'),
1383             'flex' : 1,
1384             'primary' : false,
1385             'hidden' : true,
1386             'editable' : false, 'render' : function(my) { return my.uses; },
1387             'sort_type' : 'number'
1388         },
1389         {
1390             'fm_class' : 'acp',
1391             'id' : 'alert_message',
1392             'label' : document.getElementById('circStrings').getString('staff.circ.utils.alert_message'),
1393             'flex' : 1,
1394             'primary' : false,
1395             'hidden' : true,
1396             'editable' : false, 'render' : function(my) { return my.acp.alert_message(); }
1397         },
1398         {
1399             'fm_class' : 'circ',
1400             'id' : 'checkin_workstation',
1401             'label' : document.getElementById('circStrings').getString('staff.circ.utils.checkin_workstation'),
1402             'flex' : 1,
1403             'primary' : false,
1404             'hidden' : true,
1405             'editable' : false, 'render' : function(my) { return my.circ ? ( typeof my.circ.checkin_workstation() == 'object' ? my.circ.checkin_workstation().name() : my.circ.checkin_workstation() ) : ""; },
1406         },
1407         {
1408             'fm_class' : 'circ',
1409             'id' : 'checkout_workstation',
1410             'label' : document.getElementById('circStrings').getString('staff.circ.utils.checkout_workstation'),
1411             'flex' : 1,
1412             'primary' : false,
1413             'hidden' : true,
1414             'editable' : false, 'render' : function(my) { return my.circ ? ( typeof my.circ.workstation() == 'object' ? my.circ.workstation().name() : my.circ.workstation() ) : ""; },
1415         },
1416         {
1417             'fm_class' : 'circ',
1418             'id' : 'checkout_workstation_top_of_chain',
1419             'label' : document.getElementById('circStrings').getString('staff.circ.utils.checkout_workstation_top_of_chain'),
1420             'flex' : 1,
1421             'primary' : false,
1422             'hidden' : true,
1423             'editable' : false, 'render' : function(my) { if (my.circ&&!my.original_circ) { if(!get_bool(my.circ.desk_renewal())&&!get_bool(my.circ.opac_renewal())&&!get_bool(my.circ.phone_renewal())){my.original_circ = my.circ;}}; return my.original_circ ? ( typeof my.original_circ.workstation() == 'object' ? my.original_circ.workstation().name() : my.original_circ.workstation() ) : ""; },
1424         },
1425         {
1426             'fm_class' : 'circ',
1427             'id' : 'checkin_scan_time',
1428             'label' : document.getElementById('circStrings').getString('staff.circ.utils.checkin_scan_time'),
1429             'flex' : 1,
1430             'sort_type' : 'date',
1431             'primary' : false,
1432             'hidden' : true,
1433             'editable' : false, 'render' : function(my) { return my.circ ? util.date.formatted_date( my.circ.checkin_scan_time(), '%{localized}' ) : ""; },
1434             'sort_value' : function(my) {
1435                 return util.date.db_date2Date(
1436                     my.circ
1437                     ? my.circ.checkin_scan_time()
1438                     : null
1439                 ).getTime();
1440             }
1441         },
1442         {
1443             'fm_class' : 'bre',
1444             'id' : 'owner',
1445             'label' : document.getElementById('circStrings').getString('staff.circ.utils.owner'),
1446             'flex' : 1,
1447             'primary' : false,
1448             'hidden' : true,
1449             'editable' : false, 'render' : function(my) { return my.bre ? (typeof my.bre.owner() == 'object' ? my.bre.owner().shortname() : data.hash.aou[my.bre.owner()].shortname() ) : ''; }
1450         },
1451         {
1452             'fm_class' : 'bre',
1453             'id' : 'creator',
1454             'label' : document.getElementById('circStrings').getString('staff.circ.utils.creator'),
1455             'flex' : 1,
1456             'primary' : false,
1457             'hidden' : true,
1458             'editable' : false, 'render' : function(my) { return my.bre ? (typeof my.bre.creator() == 'object' ? my.bre.creator().usrname() : '#' + my.bre.creator() ) : ''; }
1459         },
1460         {
1461             'fm_class' : 'bre',
1462             'id' : 'editor',
1463             'label' : document.getElementById('circStrings').getString('staff.circ.utils.editor'),
1464             'flex' : 1,
1465             'primary' : false,
1466             'hidden' : true,
1467             'editable' : false, 'render' : function(my) { return my.bre ? (typeof my.bre.editor() == 'object' ? my.bre.editor().usrname() : '#' + my.bre.editor() ) : ''; }
1468         },
1469         {
1470             'fm_class' : 'bre',
1471             'id' : 'create_date',
1472             'label' : document.getElementById('circStrings').getString('staff.circ.utils.bre.create_date'),
1473             'flex' : 1,
1474             'sort_type' : 'date',
1475             'primary' : false,
1476             'hidden' : true,
1477             'editable' : false, 'render' : function(my) { return my.bre ? util.date.formatted_date( my.bre.create_date(), '%{localized}' ) : ''; }
1478             ,'sort_value' : function(my) {
1479                 return util.date.db_date2Date(
1480                     my.bre
1481                     ? my.bre.create_date()
1482                     : null
1483                 ).getTime();
1484             }
1485         },
1486         {
1487             'fm_class' : 'bre',
1488             'id' : 'edit_date',
1489             'label' : document.getElementById('circStrings').getString('staff.circ.utils.bre.edit_date'),
1490             'flex' : 1,
1491             'sort_type' : 'date',
1492             'primary' : false,
1493             'hidden' : true,
1494             'editable' : false, 'render' : function(my) { return my.bre ? util.date.formatted_date( my.bre.edit_date(), '%{localized}' ) : ''; }
1495             ,'sort_value' : function(my) {
1496                 return util.date.db_date2Date(
1497                     my.bre
1498                     ? my.bre.edit_date()
1499                     : null
1500                 ).getTime();
1501             }
1502         },
1503         {
1504             'fm_class' : 'bre',
1505             'id' : 'tcn_value',
1506             'label' : document.getElementById('circStrings').getString('staff.circ.utils.tcn'),
1507             'flex' : 1,
1508             'primary' : false,
1509             'hidden' : true,
1510             'editable' : false, 'render' : function(my) { return my.bre ? my.bre.tcn_value() : ''; }
1511         },
1512         {
1513             'fm_class' : 'bre',
1514             'id' : 'tcn_source',
1515             'label' : document.getElementById('circStrings').getString('staff.circ.utils.tcn_source'),
1516             'flex' : 1,
1517             'primary' : false,
1518             'hidden' : true,
1519             'editable' : false, 'render' : function(my) { return my.bre ? my.bre.tcn_source() : ''; }
1520         }
1521
1522     ];
1523     for (var i = 0; i < c.length; i++) {
1524         if (modify[ c[i].id ]) {
1525             for (var j in modify[ c[i].id ]) {
1526                 c[i][j] = modify[ c[i].id ][j];
1527             }
1528         }
1529     }
1530     if (params) {
1531         if (params.just_these) {
1532             JSAN.use('util.functional');
1533             var new_c = [];
1534             for (var i = 0; i < params.just_these.length; i++) {
1535                 var x = util.functional.find_list(c,function(d){return(d.id==params.just_these[i]);});
1536                 new_c.push( function(y){ return y; }( x ) );
1537             }
1538             c = new_c;
1539         }
1540         if (params.except_these) {
1541             JSAN.use('util.functional');
1542             var new_c = [];
1543             for (var i = 0; i < c.length; i++) {
1544                 var x = util.functional.find_list(params.except_these,function(d){return(d==c[i].id);});
1545                 if (!x) new_c.push(c[i]);
1546             }
1547             c = new_c;
1548         }
1549     }
1550     return c.sort( function(a,b) { if (a.label < b.label) return -1; if (a.label > b.label) return 1; return 0; } );
1551 };
1552
1553 circ.util.work_log_columns = function(modify,params) {
1554
1555     JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.init({'via':'stash'});
1556
1557     var c = [
1558         {
1559             'id' : 'message',
1560             'label' : document.getElementById('circStrings').getString('staff.circ.work_log_column.message'),
1561             'flex' : 3,
1562             'primary' : true,
1563             'hidden' : false,
1564             'editable' : false, 'render' : function(my) { return my.message; }
1565         },
1566         {
1567             'id' : 'when',
1568             'label' : document.getElementById('circStrings').getString('staff.circ.work_log_column.when'),
1569             'flex' : 1,
1570             'primary' : false,
1571             'hidden' : false,
1572             'editable' : false, 'render' : function(my) { return String( my.when ); }
1573         }
1574
1575     ];
1576     for (var i = 0; i < c.length; i++) {
1577         if (modify[ c[i].id ]) {
1578             for (var j in modify[ c[i].id ]) {
1579                 c[i][j] = modify[ c[i].id ][j];
1580             }
1581         }
1582     }
1583     if (params) {
1584         if (params.just_these) {
1585             JSAN.use('util.functional');
1586             var new_c = [];
1587             for (var i = 0; i < params.just_these.length; i++) {
1588                 var x = util.functional.find_list(c,function(d){return(d.id==params.just_these[i]);});
1589                 new_c.push( function(y){ return y; }( x ) );
1590             }
1591             c = new_c;
1592         }
1593         if (params.except_these) {
1594             JSAN.use('util.functional');
1595             var new_c = [];
1596             for (var i = 0; i < c.length; i++) {
1597                 var x = util.functional.find_list(params.except_these,function(d){return(d==c[i].id);});
1598                 if (!x) new_c.push(c[i]);
1599             }
1600             c = new_c;
1601         }
1602
1603     }
1604     return c.sort( function(a,b) { if (a.label < b.label) return -1; if (a.label > b.label) return 1; return 0; } );
1605 };
1606
1607 circ.util.transit_columns = function(modify,params) {
1608
1609     JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.init({'via':'stash'});
1610
1611     var c = [
1612         {
1613             'id' : 'transit_item_barcode',
1614             'label' : document.getElementById('circStrings').getString('staff.circ.utils.barcode'),
1615             'flex' : 1,
1616             'primary' : false,
1617             'hidden' : true,
1618             'editable' : false, 'render' : function(my) { return my.acp.barcode(); }
1619         },
1620         {
1621             'id' : 'transit_item_title',
1622             'label' : document.getElementById('circStrings').getString('staff.circ.utils.title'),
1623             'flex' : 1,
1624             'primary' : false,
1625             'hidden' : true,
1626             'editable' : false, 'render' : function(my) {
1627                 try { return my.mvr.title(); }
1628                 catch(E) { return my.acp.dummy_title(); }
1629             }
1630         },
1631         {
1632             'id' : 'transit_item_author',
1633             'label' : document.getElementById('circStrings').getString('staff.circ.utils.author'),
1634             'flex' : 1,
1635             'primary' : false,
1636             'hidden' : true,
1637             'editable' : false, 'render' : function(my) {
1638                 try { return my.mvr.author(); }
1639                 catch(E) { return my.acp.dummy_author(); }
1640             }
1641         },
1642         {
1643             'id' : 'transit_item_callnumber',
1644             'label' : document.getElementById('circStrings').getString('staff.circ.utils.callnumber'),
1645             'flex' : 1,
1646             'primary' : false,
1647             'hidden' : true,
1648             'editable' : false, 'render' : function(my) { return my.acn.label(); }
1649         },
1650         {
1651             'id' : 'transit_id',
1652             'label' : document.getElementById('circStrings').getString('staff.circ.utils.transit_id'),
1653             'flex' : 1,
1654             'primary' : false,
1655             'hidden' : true,
1656             'editable' : false, 'render' : function(my) { return my.atc.id(); }
1657         },
1658         {
1659             'id' : 'transit_source',
1660             'label' : document.getElementById('circStrings').getString('staff.circ.utils.transit_source'),
1661             'flex' : 1,
1662             'primary' : false,
1663             'hidden' : false,
1664             'editable' : false, 'render' : function(my) {
1665                 if (typeof my.atc.source() == "object") {
1666                     return my.atc.source().shortname();
1667                 } else {
1668                     return data.hash.aou[ my.atc.source() ].shortname();
1669                 }
1670             }
1671         },
1672         {
1673             'id' : 'transit_source_send_time',
1674             'label' : document.getElementById('circStrings').getString('staff.circ.utils.transit_source_send_time'),
1675             'flex' : 1,
1676             'sort_type' : 'date',
1677             'primary' : false,
1678             'hidden' : false,
1679             'editable' : false, 'render' : function(my) { return util.date.formatted_date( my.atc.source_send_time(), '%{localized}' ); }
1680             ,'sort_value' : function(my) {
1681                 return util.date.db_date2Date(
1682                     my.atc
1683                     ? my.atc.source_send_time()
1684                     : null
1685                 ).getTime();
1686             }
1687         },
1688         {
1689             'id' : 'transit_dest_lib',
1690             'label' : document.getElementById('circStrings').getString('staff.circ.utils.transit_dest'),
1691             'flex' : 1,
1692             'primary' : false,
1693             'hidden' : false,
1694             'editable' : false, 'render' : function(my) {
1695                 if (typeof my.atc.dest() == "object") {
1696                     return my.atc.dest().shortname();
1697                 } else {
1698                     return data.hash.aou[ my.atc.dest() ].shortname();
1699                 }
1700             }
1701         },
1702         {
1703             'id' : 'transit_dest_recv_time',
1704             'label' : document.getElementById('circStrings').getString('staff.circ.utils.transit_dest_recv_time'),
1705             'flex' : 1,
1706             'sort_type' : 'date',
1707             'primary' : false,
1708             'hidden' : false,
1709             'editable' : false, 'render' : function(my) { return util.date.formatted_date( my.atc.dest_recv_time(), '%{localized}' ); }
1710             ,'sort_value' : function(my) {
1711                 return util.date.db_date2Date(
1712                     my.atc
1713                     ? my.atc.dest_recv_time()
1714                     : null
1715                 ).getTime();
1716             }
1717         },
1718         {
1719             'id' : 'transit_target_copy',
1720             'label' : document.getElementById('circStrings').getString('staff.circ.utils.transit_target_copy'),
1721             'flex' : 1,
1722             'primary' : false,
1723             'hidden' : true,
1724             'editable' : false, 'render' : function(my) { return my.atc.target_copy(); }
1725         },
1726         {
1727             // status of the copy on the transit, not "in-transit".
1728             // putting this here allows 'transit_copy_status' to
1729             // appear as a MACRO for the 'transit_slip' receipt.
1730             // Note that the actual value (for checkin) is 
1731             // collected below in circ.util.checkin_via_barcode2().
1732             'id' : 'transit_copy_status',
1733             'label' : document.getElementById('circStrings').
1734                 getString('staff.circ.utils.transit_copy_status'),
1735             'flex' : 1,
1736             'primary' : false,
1737             'hidden' : true,
1738             'editable' : false,
1739             'render' : function(my) {
1740                 return data.hash.ccs[ my.atc.copy_status() ].name();
1741             }
1742         },
1743     ];
1744     for (var i = 0; i < c.length; i++) {
1745         if (modify[ c[i].id ]) {
1746             for (var j in modify[ c[i].id ]) {
1747                 c[i][j] = modify[ c[i].id ][j];
1748             }
1749         }
1750     }
1751     if (params) {
1752         if (params.just_these) {
1753             JSAN.use('util.functional');
1754             var new_c = [];
1755             for (var i = 0; i < params.just_these.length; i++) {
1756                 var x = util.functional.find_list(c,function(d){return(d.id==params.just_these[i]);});
1757                 new_c.push( function(y){ return y; }( x ) );
1758             }
1759             c = new_c;
1760         }
1761         if (params.except_these) {
1762             JSAN.use('util.functional');
1763             var new_c = [];
1764             for (var i = 0; i < c.length; i++) {
1765                 var x = util.functional.find_list(params.except_these,function(d){return(d==c[i].id);});
1766                 if (!x) new_c.push(c[i]);
1767             }
1768             c = new_c;
1769         }
1770
1771     }
1772     return c.sort( function(a,b) { if (a.label < b.label) return -1; if (a.label > b.label) return 1; return 0; } );
1773 };
1774
1775 circ.util.hold_columns = function(modify,params) {
1776
1777     JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.init({'via':'stash'});
1778
1779     var c = [
1780         {
1781             'id' : 'post_clear_shelf_action',
1782             'flex' : 1, 'primary' : false, 'hidden' : true, 'editable' : false, 
1783             'label' : document.getElementById('circStrings').getString('staff.circ.utils.hold_post_clear_shelf_action.label'),
1784             'render' : function(my) { 
1785                 return my.post_clear_shelf_action ? document.getElementById('circStrings').getString('staff.circ.utils.hold_post_clear_shelf_action.' + my.post_clear_shelf_action) : '';
1786             }
1787         },
1788         {
1789             'id' : 'cancel_time',
1790             'label' : document.getElementById('circStrings').getString('staff.circ.utils.hold_cancel_time'),
1791             'flex' : 1,
1792             'sort_type' : 'date',
1793             'primary' : false,
1794             'hidden' : true,
1795             'editable' : false, 'render' : function(my) { return util.date.formatted_date( my.ahr.cancel_time(), '%{localized}' ); }
1796             ,'sort_value' : function(my) {
1797                 return util.date.db_date2Date(
1798                     my.ahr
1799                     ? my.ahr.cancel_time()
1800                     : null
1801                 ).getTime();
1802             }
1803         },
1804         {
1805             'id' : 'cancel_cause',
1806             'label' : document.getElementById('circStrings').getString('staff.circ.utils.hold_cancel_cause'),
1807             'flex' : 1,
1808             'primary' : false,
1809             'hidden' : true,
1810             'editable' : false, 'render' : function(my) { return typeof my.ahr.cancel_cause == 'object' ? my.ahr.cancel_cause().label() : data.hash.ahrcc[ my.ahr.cancel_cause() ].label(); }
1811         },
1812         {
1813             'id' : 'cancel_note',
1814             'label' : document.getElementById('circStrings').getString('staff.circ.utils.hold_cancel_note'),
1815             'flex' : 1,
1816             'primary' : false,
1817             'hidden' : true,
1818             'editable' : false, 'render' : function(my) { return my.ahr.cancel_note(); }
1819         },
1820         {
1821             'id' : 'request_lib',
1822             'label' : document.getElementById('circStrings').getString('staff.circ.utils.request_lib'),
1823             'flex' : 1,
1824             'primary' : false,
1825             'hidden' : true,
1826             'editable' : false, 'render' : function(my) {
1827                 if (Number(my.ahr.request_lib())>=0) {
1828                     return data.hash.aou[ my.ahr.request_lib() ].name();
1829                 } else {
1830                     return my.ahr.request_lib().name();
1831                 }
1832             }
1833         },
1834         {
1835             'id' : 'request_lib_shortname',
1836             'label' : document.getElementById('circStrings').getString('staff.circ.utils.request_lib_shortname'),
1837             'flex' : 0,
1838             'primary' : false,
1839             'hidden' : true,
1840             'editable' : false, 'render' : function(my) {
1841                 if (Number(my.ahr.request_lib())>=0) {
1842                     return data.hash.aou[ my.ahr.request_lib() ].shortname();
1843                 } else {
1844                     return my.ahr.request_lib().shortname();
1845                 }
1846             }
1847         },
1848         {
1849             'id' : 'request_time',
1850             'label' : document.getElementById('circStrings').getString('staff.circ.utils.request_time'),
1851             'flex' : 0,
1852             'sort_type' : 'date',
1853             'primary' : false,
1854             'hidden' : true,
1855             'editable' : false, 'render' : function(my) { return util.date.formatted_date( my.ahr.request_time(), '%{localized}' ); }
1856             ,'sort_value' : function(my) {
1857                 return util.date.db_date2Date(
1858                     my.ahr
1859                     ? my.ahr.request_time()
1860                     : null
1861                 ).getTime();
1862             }
1863         },
1864         {
1865             'id' : 'shelf_time',
1866             'label' : document.getElementById('circStrings').getString('staff.circ.utils.holds.shelf_time'),
1867             'flex' : 0,
1868             'sort_type' : 'date',
1869             'primary' : false,
1870             'hidden' : true,
1871             'editable' : false, 'render' : function(my) { return util.date.formatted_date( my.ahr.shelf_time(), '%{localized}' ); }
1872             ,'sort_value' : function(my) {
1873                 return util.date.db_date2Date(
1874                     my.ahr
1875                     ? my.ahr.shelf_time()
1876                     : null
1877                 ).getTime();
1878             }
1879         },
1880         {
1881             'id' : 'shelf_expire_time',
1882             'label' : document.getElementById('circStrings').getString('staff.circ.utils.holds.shelf_expire_time'),
1883             'flex' : 0,
1884             'sort_type' : 'date',
1885             'primary' : false,
1886             'hidden' : true,
1887             'editable' : false, 'render' : function(my) { return util.date.formatted_date( my.ahr.shelf_expire_time(), '%{localized}' ); }
1888             ,'sort_value' : function(my) {
1889                 return util.date.db_date2Date(
1890                     my.ahr
1891                     ? my.ahr.shelf_expire_time()
1892                     : null
1893                 ).getTime();
1894             }
1895         },
1896         {
1897             'id' : 'available_time',
1898             'label' : document.getElementById('circStrings').getString('staff.circ.utils.available_time'),
1899             'flex' : 1,
1900             'sort_type' : 'date',
1901             'primary' : false,
1902             'hidden' : false,
1903             'editable' : false, 'render' : function(my) {
1904                 if (my.ahr.current_shelf_lib() == my.ahr.pickup_lib()) {
1905                     return util.date.formatted_date( my.ahr.shelf_time(), '%{localized}' );
1906                 }
1907                 return "";
1908             }
1909             ,'sort_value' : function(my) {
1910                 if (my.ahr.current_shelf_lib() == my.ahr.pickup_lib()) {
1911                     return util.date.db_date2Date( my.ahr.shelf_time() ).getTime();
1912                 } else {
1913                     return util.date.db_date2Date( null ).getTime();
1914                 }
1915             }
1916         },
1917         {
1918             'id' : 'capture_time',
1919             'label' : document.getElementById('circStrings').getString('staff.circ.utils.capture_time'),
1920             'flex' : 1,
1921             'sort_type' : 'date',
1922             'primary' : false,
1923             'hidden' : true,
1924             'editable' : false, 'render' : function(my) { return my.ahr.capture_time() ? util.date.formatted_date( my.ahr.capture_time(), '%{localized}' ) : ""; }
1925             ,'sort_value' : function(my) {
1926                 return util.date.db_date2Date(
1927                     my.ahr
1928                     ? my.ahr.capture_time()
1929                     : null
1930                 ).getTime();
1931             }
1932         },
1933         {
1934             'id' : 'ahr_status',
1935             'label' : document.getElementById('commonStrings').getString('staff.ahr_status_label'),
1936             'flex' : 1,
1937             'primary' : false,
1938             'hidden' : false,
1939             'editable' : false, 'render' : function(my) {
1940                 switch (Number(my.status)) {
1941                     case 1:
1942                         return document.getElementById('circStrings').getString('staff.circ.utils.hold_status.1');
1943                         break;
1944                     case 2:
1945                         return document.getElementById('circStrings').getString('staff.circ.utils.hold_status.2');
1946                         break;
1947                     case 3:
1948                         return document.getElementById('circStrings').getString('staff.circ.utils.hold_status.3');
1949                         break;
1950                     case 4:
1951                         return document.getElementById('circStrings').getString('staff.circ.utils.hold_status.4');
1952                         break;
1953                     case 5:
1954                         return document.getElementById('circStrings').getString('staff.circ.utils.hold_status.5');
1955                         break;
1956                     case 6:
1957                         return document.getElementById('circStrings').getString('staff.circ.utils.hold_status.6');
1958                         break;
1959                     case 7:
1960                         return document.getElementById('circStrings').getString('staff.circ.utils.hold_status.7');
1961                         break;
1962                     case 8:
1963                         return document.getElementById('circStrings').getString('staff.circ.utils.hold_status.8');
1964                         break;
1965                     default:
1966                         return my.status;
1967                         break;
1968                 };
1969             }
1970         },
1971         {
1972             'id' : 'hold_type',
1973             'label' : document.getElementById('commonStrings').getString('staff.ahr_hold_type_label'),
1974             'flex' : 0,
1975             'primary' : false,
1976             'hidden' : true,
1977             'editable' : false, 'render' : function(my) { return my.ahr.hold_type(); }
1978         },
1979         {
1980             'id' : 'ahr_mint_condition',
1981             'label' : document.getElementById('circStrings').getString('staff.circ.utils.ahr_mint_condition'),
1982             'flex' : 0,
1983             'primary' : false,
1984             'hidden' : true,
1985             'editable' : false, 'render' : function(my) {
1986                 if (get_bool( my.ahr.mint_condition() )) {
1987                     return document.getElementById('circStrings').getString('staff.circ.utils.ahr_mint_condition.true');
1988                 } else {
1989                     return document.getElementById('circStrings').getString('staff.circ.utils.ahr_mint_condition.false');
1990                 }
1991             }
1992         },
1993         {
1994             'id' : 'frozen',
1995             'label' : document.getElementById('circStrings').getString('staff.circ.utils.active'),
1996             'flex' : 0,
1997             'primary' : false,
1998             'hidden' : true,
1999             'editable' : false, 'render' : function(my) {
2000                 if (!get_bool( my.ahr.frozen() )) {
2001                     return document.getElementById('circStrings').getString('staff.circ.utils.yes');
2002                 } else {
2003                     return document.getElementById('circStrings').getString('staff.circ.utils.no');
2004                 }
2005             }
2006         },
2007         {
2008             'id' : 'thaw_date',
2009             'label' : document.getElementById('circStrings').getString('staff.circ.utils.thaw_date'),
2010             'flex' : 0,
2011             'sort_type' : 'date',
2012             'primary' : false,
2013             'hidden' : true,
2014             'editable' : false, 'render' : function(my) {
2015                 if (my.ahr.thaw_date() == null) {
2016                     return document.getElementById('circStrings').getString('staff.circ.utils.thaw_date.none');
2017                 } else {
2018                     return util.date.formatted_date( my.ahr.thaw_date(), '%{localized}' );
2019                 }
2020             }
2021             ,'sort_value' : function(my) {
2022                 return util.date.db_date2Date(
2023                     my.ahr
2024                     ? my.ahr.thaw_date()
2025                     : null
2026                 ).getTime();
2027             }
2028         },
2029         {
2030             'id' : 'pickup_lib',
2031             'label' : document.getElementById('circStrings').getString('staff.circ.utils.pickup_lib'),
2032             'flex' : 1,
2033             'primary' : false,
2034             'hidden' : true,
2035             'editable' : false, 'render' : function(my) {
2036                 if (Number(my.ahr.pickup_lib())>=0) {
2037                     return data.hash.aou[ my.ahr.pickup_lib() ].name();
2038                 } else {
2039                     return my.ahr.pickup_lib().name();
2040                 }
2041             }
2042         },
2043         {
2044             'id' : 'pickup_lib_shortname',
2045             'label' : document.getElementById('commonStrings').getString('staff.ahr_pickup_lib_label'),
2046             'flex' : 0,
2047             'primary' : false,
2048             'hidden' : true,
2049             'editable' : false, 'render' : function(my) {
2050                 if (Number(my.ahr.pickup_lib())>=0) {
2051                     return data.hash.aou[ my.ahr.pickup_lib() ].shortname();
2052                 } else {
2053                     return my.ahr.pickup_lib().shortname();
2054                 }
2055             }
2056         },
2057         {
2058             'id' : 'current_shelf_lib',
2059             'label' : document.getElementById('circStrings').getString('staff.circ.utils.current_shelf_lib'),
2060             'flex' : 1,
2061             'primary' : false,
2062             'hidden' : true,
2063             'editable' : false, 'render' : function(my) {
2064                 if (Number(my.ahr.current_shelf_lib())>=0) {
2065                     return data.hash.aou[ my.ahr.current_shelf_lib() ].name();
2066                 } else {
2067                     return my.ahr.current_shelf_lib().name();
2068                 }
2069             }
2070         },
2071         {
2072             'id' : 'current_shelf_lib_shortname',
2073             'label' : document.getElementById('commonStrings').getString('staff.ahr_current_shelf_lib_label'),
2074             'flex' : 0,
2075             'primary' : false,
2076             'hidden' : true,
2077             'editable' : false, 'render' : function(my) {
2078                 if (Number(my.ahr.current_shelf_lib())>=0) {
2079                     return data.hash.aou[ my.ahr.current_shelf_lib() ].shortname();
2080                 } else {
2081                     return my.ahr.current_shelf_lib().shortname();
2082                 }
2083             }
2084         },
2085
2086         {
2087             'id' : 'current_copy',
2088             'label' : document.getElementById('commonStrings').getString('staff.ahr_current_copy_label'),
2089             'flex' : 1,
2090             'primary' : false,
2091             'hidden' : true,
2092             'editable' : false, 'render' : function(my) {
2093                 if (my.acp) {
2094                     return my.acp.barcode();
2095                 } else {
2096                     return document.getElementById('circStrings').getString('staff.circ.utils.current_copy.none');
2097                 }
2098             }
2099         },
2100         {
2101             'id' : 'current_copy_location',
2102             'label' : document.getElementById('commonStrings').getString('staff.ahr_current_copy_location_label'),
2103             'flex' : 1,
2104             'primary' : false,
2105             'hidden' : true,
2106             'editable' : false, 'render' : function(my) {
2107                 if (!my.acp) { return ""; } else { if (Number(my.acp.location())>=0) return data.lookup("acpl", my.acp.location() ).name(); else return my.acp.location().name(); }
2108             }
2109         },
2110         {
2111             'id' : 'email_notify',
2112             'label' : document.getElementById('commonStrings').getString('staff.ahr_email_notify_label'),
2113             'flex' : 1,
2114             'primary' : false,
2115             'hidden' : true,
2116             'editable' : false, 'render' : function(my) {
2117                 if (get_bool(my.ahr.email_notify())) {
2118                     return document.getElementById('circStrings').getString('staff.circ.utils.yes');
2119                 } else {
2120                     return document.getElementById('circStrings').getString('staff.circ.utils.no');
2121                 }
2122             }
2123         },
2124         {
2125             'id' : 'expire_date',
2126             'label' : document.getElementById('commonStrings').getString('staff.ahr_expire_date_label'),
2127             'flex' : 1,
2128             'sort_type' : 'date',
2129             'primary' : false,
2130             'hidden' : true,
2131             'editable' : false, 'render' : function(my) { return my.ahr.expire_time() ? util.date.formatted_date( my.ahr.expire_time(), '%{localized}' ) : ''; }
2132             ,'sort_value' : function(my) {
2133                 return util.date.db_date2Date(
2134                     my.ahr
2135                     ? my.ahr.expire_time()
2136                     : null
2137                 ).getTime();
2138             }
2139         },
2140         {
2141             'id' : 'fulfillment_time',
2142             'label' : document.getElementById('commonStrings').getString('staff.ahr_fulfillment_time_label'),
2143             'flex' : 1,
2144             'sort_type' : 'date',
2145             'primary' : false,
2146             'hidden' : true,
2147             'editable' : false, 'render' : function(my) { return util.date.formatted_date( my.ahr.fulfillment_time(), '%{localized}' ); }
2148             ,'sort_value' : function(my) {
2149                 return util.date.db_date2Date(
2150                     my.ahr
2151                     ? my.ahr.fulfillment_time()
2152                     : null
2153                 ).getTime();
2154             }
2155         },
2156         {
2157             'id' : 'holdable_formats',
2158             'label' : document.getElementById('commonStrings').getString('staff.ahr_holdable_formats_label'),
2159             'flex' : 1,
2160             'primary' : false,
2161             'hidden' : true,
2162             'editable' : false, 'render' : function(my) { return my.ahr.holdable_formats(); }
2163         },
2164         {
2165             'id' : 'holdable_part',
2166             'label' : document.getElementById('commonStrings').getString('staff.ahr_holdable_part_label'),
2167             'flex' : 1,
2168             'primary' : false,
2169             'hidden' : true,
2170             'editable' : false, 'render' : function(my) { return my.part.label(); }
2171         },
2172         {
2173             'id' : 'issuance_label',
2174             'label' : document.getElementById('commonStrings').getString('staff.ahr_issuance_label_label'),
2175             'flex' : 1,
2176             'primary' : false,
2177             'hidden' : true,
2178             'editable' : false, 'render' : function(my) { return my.issuance.label(); }
2179         },
2180         {
2181             'id' : 'ahr_id',
2182             'label' : document.getElementById('commonStrings').getString('staff.ahr_id_label'),
2183             'flex' : 1,
2184             'primary' : false,
2185             'hidden' : true,
2186             'editable' : false, 'render' : function(my) { return my.ahr.id(); }
2187         },
2188         {
2189             'id' : 'phone_notify',
2190             'label' : document.getElementById('commonStrings').getString('staff.ahr_phone_notify_label'),
2191             'flex' : 1,
2192             'primary' : false,
2193             'hidden' : true,
2194             'editable' : false, 'render' : function(my) { return my.ahr.phone_notify(); }
2195         },
2196         {
2197             'id' : 'sms_notify',
2198             'label' : document.getElementById('commonStrings').getString('staff.ahr_sms_notify_label'),
2199             'flex' : 1,
2200             'primary' : false,
2201             'hidden' : true,
2202             'editable' : false, 'render' : function(my) { return my.ahr.sms_notify(); }
2203         },
2204         {
2205             'id' : 'sms_carrier',
2206             'label' : document.getElementById('commonStrings').getString('staff.ahr_sms_carrier_label'),
2207             'flex' : 1,
2208             'primary' : false,
2209             'hidden' : true,
2210             'editable' : false, 'render' : function(my) { return data.hash.csc[ my.ahr.sms_carrier() ].name(); }
2211         },
2212         {
2213             'id' : 'prev_check_time',
2214             'label' : document.getElementById('commonStrings').getString('staff.ahr_prev_check_time_label'),
2215             'flex' : 1,
2216             'sort_type' : 'date',
2217             'primary' : false,
2218             'hidden' : true,
2219             'editable' : false, 'render' : function(my) { return util.date.formatted_date( my.ahr.prev_check_time(), '%{localized}' ); }
2220             ,'sort_value' : function(my) {
2221                 return util.date.db_date2Date(
2222                     my.ahr
2223                     ? my.ahr.prev_check_time()
2224                     : null
2225                 ).getTime();
2226             }
2227         },
2228         {
2229             'id' : 'requestor',
2230             'label' : document.getElementById('commonStrings').getString('staff.ahr_requestor_label'),
2231             'flex' : 1,
2232             'primary' : false,
2233             'hidden' : true,
2234             'editable' : false, 'render' : function(my) { return my.ahr.requestor(); }
2235         },
2236         {
2237             'id' : 'selection_depth',
2238             'label' : document.getElementById('commonStrings').getString('staff.ahr_selection_depth_label'),
2239             'flex' : 1,
2240             'primary' : false,
2241             'hidden' : true,
2242             'editable' : false, 'render' : function(my) { return my.ahr.selection_depth(); }
2243         },
2244         {
2245             'id' : 'top_of_queue',
2246             'label' : document.getElementById('commonStrings').getString('staff.ahr_top_of_queue_label'),
2247             'flex' : 1,
2248             'primary' : false,
2249             'hidden' : true,
2250             'editable' : false, 'render' : function(my) { return get_bool( my.ahr.cut_in_line() ) ? document.getElementById('commonStrings').getString('common.yes') : document.getElementById('commonStrings').getString('common.no') ; }
2251         },
2252         {
2253             'id' : 'target',
2254             'label' : document.getElementById('commonStrings').getString('staff.ahr_target_label'),
2255             'flex' : 1,
2256             'primary' : false,
2257             'hidden' : true,
2258             'editable' : false, 'render' : function(my) { return my.ahr.target(); }
2259         },
2260         {
2261             'id' : 'usr',
2262             'label' : document.getElementById('commonStrings').getString('staff.ahr_usr_label'),
2263             'flex' : 1,
2264             'primary' : false,
2265             'hidden' : true,
2266             'editable' : false, 'render' : function(my) { return my.ahr.usr(); }
2267         },
2268         {
2269             'id' : 'title',
2270             'label' : document.getElementById('commonStrings').getString('staff.mvr_label_title'),
2271             'flex' : 1,
2272             'sort_type' : 'title',
2273             'primary' : false,
2274             'hidden' : true,
2275             'editable' : false, 'render' : function(my) {
2276                 if (my.mvr) {
2277                     return my.mvr.title();
2278                 } else {
2279                     return document.getElementById('circStrings').getString('staff.circ.utils.title.none');
2280                 }
2281             }
2282         },
2283         {
2284             'id' : 'author',
2285             'label' : document.getElementById('commonStrings').getString('staff.mvr_label_author'),
2286             'flex' : 1,
2287             'primary' : false,
2288             'hidden' : true,
2289             'editable' : false, 'render' : function(my) {
2290                 if (my.mvr) {
2291                     return my.mvr.author();
2292                 } else {
2293                     return document.getElementById('circStrings').getString('staff.circ.utils.author.none');
2294                 }
2295             }
2296         },
2297         {
2298             'id' : 'edition',
2299             'label' : document.getElementById('circStrings').getString('staff.circ.utils.edition'),
2300             'flex' : 1,
2301             'primary' : false,
2302             'hidden' : true,
2303             'editable' : false, 'render' : function(my) { return my.mvr.edition(); }
2304         },
2305         {
2306             'id' : 'isbn',
2307             'label' : document.getElementById('circStrings').getString('staff.circ.utils.isbn'),
2308             'flex' : 1,
2309             'primary' : false,
2310             'hidden' : true,
2311             'editable' : false, 'render' : function(my) { return my.mvr.isbn(); }
2312         },
2313         {
2314             'id' : 'pubdate',
2315             'label' : document.getElementById('circStrings').getString('staff.circ.utils.pubdate'),
2316             'flex' : 1,
2317             'primary' : false,
2318             'hidden' : true,
2319             'editable' : false, 'render' : function(my) { return my.mvr.pubdate(); }
2320         },
2321         {
2322             'id' : 'publisher',
2323             'label' : document.getElementById('circStrings').getString('staff.circ.utils.publisher'),
2324             'flex' : 1,
2325             'primary' : false,
2326             'hidden' : true,
2327             'editable' : false, 'render' : function(my) { return my.mvr.publisher(); }
2328         },
2329         {
2330             'id' : 'tcn',
2331             'label' : document.getElementById('circStrings').getString('staff.circ.utils.tcn'),
2332             'flex' : 1,
2333             'primary' : false,
2334             'hidden' : true,
2335             'editable' : false, 'render' : function(my) { return my.mvr.tcn(); }
2336         },
2337         {
2338             'id' : 'notify_time',
2339             'label' : document.getElementById('circStrings').getString('staff.circ.utils.notify_time'),
2340             'flex' : 1,
2341             'sort_type' : 'date',
2342             'primary' : false,
2343             'hidden' : true,
2344             'editable' : false, 'render' : function(my) { return util.date.formatted_date( my.ahr.notify_time(), '%{localized}' ); }
2345             ,'sort_value' : function(my) {
2346                 return util.date.db_date2Date(
2347                     my.ahr
2348                     ? my.ahr.notify_time()
2349                     : null
2350                 ).getTime();
2351             }
2352         },
2353         {
2354             'id' : 'notify_count',
2355             'label' : document.getElementById('circStrings').getString('staff.circ.utils.notify_count'),
2356             'flex' : 1,
2357             'primary' : false,
2358             'hidden' : true,
2359             'editable' : false, 'render' : function(my) { return my.ahr.notify_count(); }
2360         },
2361         {
2362             'id' : 'transit_source',
2363             'label' : document.getElementById('circStrings').getString('staff.circ.utils.transit_source'),
2364             'flex' : 1,
2365             'primary' : false,
2366             'hidden' : true,
2367             'editable' : false, 'render' : function(my) {
2368                 if (my.ahr.transit()) {
2369                     return data.hash.aou[ my.ahr.transit().source() ].shortname();
2370                 } else {
2371                     return "";
2372                 }
2373             }
2374         },
2375         {
2376             'id' : 'transit_source_send_time',
2377             'label' : document.getElementById('circStrings').getString('staff.circ.utils.transit_source_send_time'),
2378             'flex' : 1,
2379             'sort_type' : 'date',
2380             'primary' : false,
2381             'hidden' : true,
2382             'editable' : false, 'render' : function(my) { return my.ahr.transit() ?  util.date.formatted_date( my.ahr.transit().source_send_time(), '%{localized}' ) : ""; }
2383             ,'sort_value' : function(my) {
2384                 return util.date.db_date2Date(
2385                     my.ahr
2386                     ? my.ahr.transit().source_send_time()
2387                     : null
2388                 ).getTime();
2389             }
2390         },
2391         {
2392             'id' : 'transit_dest_lib',
2393             'label' : document.getElementById('circStrings').getString('staff.circ.utils.transit_dest'),
2394             'flex' : 1,
2395             'primary' : false,
2396             'hidden' : true,
2397             'editable' : false, 'render' : function(my) { return my.ahr.transit() ?  data.hash.aou[ my.ahr.transit().dest() ].shortname() : ""; }
2398         },
2399         {
2400             'id' : 'transit_dest_recv_time',
2401             'label' : document.getElementById('circStrings').getString('staff.circ.utils.transit_dest_recv_time'),
2402             'flex' : 1,
2403             'sort_type' : 'date',
2404             'primary' : false,
2405             'hidden' : true,
2406             'editable' : false, 'render' : function(my) { return my.ahr.transit() ?  util.date.formatted_date( my.ahr.transit().dest_recv_time(), '%{localized}' ) : ""; }
2407             ,'sort_value' : function(my) {
2408                 return util.date.db_date2Date(
2409                     my.ahr
2410                     ? my.ahr.transit().dest_recv_time()
2411                     : null
2412                 ).getTime();
2413             }
2414         },
2415         {
2416             'id' : 'patron_barcode',
2417             'label' : document.getElementById('circStrings').getString('staff.circ.utils.offline.patron_barcode'),
2418             'flex' : 1,
2419             'primary' : false,
2420             'hidden' : true,
2421             'editable' : false, 'render' : function(my) { return my.patron_barcode ? my.patron_barcode : ""; }
2422         },
2423         {
2424             'id' : 'patron_family_name',
2425             'label' : document.getElementById('circStrings').getString('staff.circ.utils.patron_family_name'),
2426             'flex' : 1,
2427             'primary' : false,
2428             'hidden' : true,
2429             'editable' : false, 'render' : function(my) { return my.patron_family_name ? my.patron_family_name : ""; }
2430         },
2431         {
2432             "persist": "hidden width ordinal",
2433             "id": "patron_alias",
2434             'label' : document.getElementById('circStrings').getString('staff.circ.utils.patron_alias'),
2435             'flex' : 1,
2436             'primary' : false,
2437             'hidden' : true,
2438             'editable' : false, 'render' : function(my) { return my.patron_alias ? my.patron_alias : ""; }
2439         },
2440         {
2441             'id' : 'patron_first_given_name',
2442             'label' : document.getElementById('circStrings').getString('staff.circ.utils.patron_first_given_name'),
2443             'flex' : 1,
2444             'primary' : false,
2445             'hidden' : true,
2446             'editable' : false, 'render' : function(my) { return my.patron_first_given_name ? my.patron_first_given_name : ""; }
2447         },
2448         {
2449             'id' : 'callnumber',
2450             'fm_class' : 'acp',
2451             'label' : document.getElementById('commonStrings').getString('staff.acp_label_call_number'),
2452             'flex' : 1,
2453             'primary' : false,
2454             'hidden' : true,
2455             'sort_value' : function(my,scratch_data) {
2456                                 var result_label = "label_sortkey";
2457                                 return sort_call_numbers_by_label_sortkey(my,scratch_data, result_label);
2458                        },
2459             'editable' : false, 'render' : function(my,scratch_data) {
2460                                 var result_label = "render_label";
2461                                 return sort_call_numbers_by_label_sortkey(my, scratch_data, result_label);
2462                         } 
2463         },
2464         {
2465             'id' : 'prefix',
2466             'fm_class' : 'acn',
2467             'label' : document.getElementById('circStrings').getString('staff.circ.utils.prefix'),
2468             'flex' : 1,
2469             'primary' : false,
2470             'hidden' : true,
2471             'editable' : false, 'render' : function(my) {
2472                 if (typeof my.acn == 'undefined') return '';
2473                 return (typeof my.acn.prefix() == 'object')
2474                     ? my.acn.prefix().label()
2475                     : data.lookup("acnp", my.acn.prefix() ).label();
2476             }
2477         },
2478         {
2479             'id' : 'suffix',
2480             'fm_class' : 'acn',
2481             'label' : document.getElementById('circStrings').getString('staff.circ.utils.suffix'),
2482             'flex' : 1,
2483             'primary' : false,
2484             'hidden' : true,
2485             'editable' : false, 'render' : function(my) {
2486                 if (typeof my.acn == 'undefined') return '';
2487                 return (typeof my.acn.suffix() == 'object')
2488                     ? my.acn.suffix().label()
2489                     : data.lookup("acns", my.acn.suffix() ).label();
2490             }
2491         },
2492         {
2493             'id' : 'total_holds',
2494             'label' : document.getElementById('circStrings').getString('staff.circ.utils.total_holds'),
2495             'flex' : 1,
2496             'primary' : false,
2497             'hidden' : true,
2498             'editable' : false, 'render' : function(my) { return my.total_holds; }
2499         },
2500                 {
2501             'id' : 'queue_position',
2502             'sort_type' : 'number',
2503             'label' : document.getElementById('circStrings').getString('staff.circ.utils.queue_position'),
2504             'flex' : 1,
2505             'primary' : false,
2506             'hidden' : true,
2507             'editable' : false, 'render' : function(my) { return my.queue_position; }
2508         },
2509                 {
2510             'id' : 'potential_copies',
2511             'label' : document.getElementById('circStrings').getString('staff.circ.utils.potential_copies'),
2512             'flex' : 1,
2513             'primary' : false,
2514             'hidden' : true,
2515             'editable' : false, 'render' : function(my) { return my.potential_copies; }
2516         },
2517                 {
2518             'id' : 'estimated_wait',
2519             'label' : document.getElementById('circStrings').getString('staff.circ.utils.estimated_wait'),
2520             'flex' : 1,
2521             'primary' : false,
2522             'hidden' : true,
2523             'editable' : false, 'render' : function(my) { return my.estimated_wait; }
2524         },
2525         {
2526             'id' : 'hold_note',
2527             'label' : document.getElementById('circStrings').getString('staff.circ.utils.hold_note'),
2528             'flex' : 1,
2529             'primary' : false,
2530             'hidden' : true,
2531             'editable' : false, 'render' : function(my) { return my.ahrn_count; }
2532         },
2533         {
2534             'id' : 'hold_note_text',
2535             'label' : document.getElementById('circStrings').getString('staff.circ.utils.hold_note_text'),
2536             'flex' : 1,
2537             'primary' : false,
2538             'hidden' : true,
2539             'editable' : false, 'render' : function(my) {
2540                 var s = '';
2541                 var notes = my.ahr.notes();
2542                 for (var i = 0; i < notes.length; i++) {
2543                     s += notes[i].title() + ':' + notes[i].body() + '; \n';
2544                 }
2545                 return s;
2546             }
2547         },
2548         {
2549             'id' : 'staff_hold',
2550             'label' : document.getElementById('circStrings').getString('staff.circ.utils.staff_hold'),
2551             'flex' : 1,
2552             'primary' : false,
2553             'hidden' : true,
2554             'editable' : false, 
2555             'render' : function(my) {
2556                 if (my.ahr.usr() != my.ahr.requestor()){
2557                     return document.getElementById('circStrings').getString('staff.circ.utils.yes');
2558                 } else {
2559                     return document.getElementById('circStrings').getString('staff.circ.utils.no');
2560                 }
2561             }
2562         },
2563         {
2564             'id' : 'behind_desk',
2565             'label' : document.getElementById('circStrings').getString('staff.circ.utils.hold.behind_desk'),
2566             'flex' : 1,
2567             'primary' : false,
2568             'hidden' : true,
2569             'editable' : false, 
2570             'render' : function(my) {
2571                 if (isTrue(my.ahr.behind_desk())) {
2572                     return document.getElementById('circStrings').getString('staff.circ.utils.yes');
2573                 } else {
2574                     return document.getElementById('circStrings').getString('staff.circ.utils.no');
2575                 }
2576             }
2577         }
2578
2579     ];
2580     for (var i = 0; i < c.length; i++) {
2581         if (modify[ c[i].id ]) {
2582             for (var j in modify[ c[i].id ]) {
2583                 c[i][j] = modify[ c[i].id ][j];
2584             }
2585         }
2586     }
2587     if (params) {
2588         if (params.just_these) {
2589             JSAN.use('util.functional');
2590             var new_c = [];
2591             for (var i = 0; i < params.just_these.length; i++) {
2592                 var x = util.functional.find_list(c,function(d){return(d.id==params.just_these[i]);});
2593                 new_c.push( function(y){ return y; }( x ) );
2594             }
2595             c = new_c;
2596         }
2597         if (params.except_these) {
2598             JSAN.use('util.functional');
2599             var new_c = [];
2600             for (var i = 0; i < c.length; i++) {
2601                 var x = util.functional.find_list(params.except_these,function(d){return(d==c[i].id);});
2602                 if (!x) new_c.push(c[i]);
2603             }
2604             c = new_c;
2605         }
2606
2607     }
2608     return c.sort( function(a,b) { if (a.label < b.label) return -1; if (a.label > b.label) return 1; return 0; } );
2609 };
2610
2611 circ.util.checkin_via_barcode = function(session,params,backdate,auto_print,async) {
2612     try {
2613         JSAN.use('util.error'); var error = new util.error();
2614         JSAN.use('util.network'); var network = new util.network();
2615         JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.init({'via':'stash'});
2616         JSAN.use('util.date'); JSAN.use('util.functional');
2617
2618         if (backdate && (backdate == util.date.formatted_date(new Date(),'%Y-%m-%d')) ) backdate = null;
2619
2620         //var params = { 'barcode' : barcode };
2621         if (backdate) params.backdate = util.date.formatted_date(backdate,'%{iso8601}');
2622
2623         if (typeof params.disable_textbox == 'function') {
2624             try { params.disable_textbox(); }
2625             catch(E) { error.sdump('D_ERROR','params.disable_textbox() = ' + E); };
2626         }
2627
2628         function checkin_callback(req) {
2629             JSAN.use('util.error'); var error = new util.error();
2630             try {
2631                 var check = req.getResultObject();
2632                 var r = circ.util.checkin_via_barcode2(session,params,backdate,auto_print,check);
2633                 try {
2634                     error.work_log(
2635                         document.getElementById('circStrings').getFormattedString(
2636                             'staff.circ.work_log_checkin_attempt.' + r.what_happened + '.message',
2637                             [
2638                                 ses('staff_usrname'),
2639                                 r.payload.patron ? r.payload.patron.family_name() : '',
2640                                 r.payload.patron ? r.payload.patron.card().barcode() : '',
2641                                 r.payload.copy ? r.payload.copy.barcode() : '',
2642                                 r.route_to ? r.route_to : ''
2643                             ]
2644                         ), {
2645                             'au_id' : r.payload.patron ? r.payload.patron.id() : '',
2646                             'au_family_name' : r.payload.patron ? r.payload.patron.family_name() : '',
2647                             'au_barcode' : r.payload.patron ? r.payload.patron.card().barcode() : '',
2648                             'acp_barcode' : r.payload.copy ? r.payload.copy.barcode() : ''
2649                         }
2650                     );
2651                 } catch(E) {
2652                     error.sdump('D_ERROR','Error with work_logging in server/circ/checkout.js, _checkout:' + E);
2653                 }
2654
2655                 if (typeof params.checkin_result == 'function') {
2656                     try { params.checkin_result(r); } catch(E) { error.sdump('D_ERROR','params.checkin_result() = ' + E); };
2657                 }
2658                 if (typeof async == 'function') async(check);
2659                 return check;
2660             } catch(E) {
2661                 error.standard_unexpected_error_alert(document.getElementById('circStrings').getFormattedString('staff.circ.checkin.error', ['1']), E);
2662                 if (typeof params.enable_textbox == 'function') {
2663                     try { params.enable_textbox(); }
2664                     catch(E) { error.sdump('D_ERROR','params.disable_textbox() = ' + E); };
2665                 }
2666                 return null;
2667             }
2668         }
2669
2670         var suppress_popups = data.hash.aous['ui.circ.suppress_checkin_popups'];
2671
2672         var check = network.request(
2673             api.CHECKIN_VIA_BARCODE.app,
2674             api.CHECKIN_VIA_BARCODE.method,
2675             [ session, util.functional.filter_object( params, function(i,o) { return typeof o != 'function'; } ) ],
2676             async ? checkin_callback : null,
2677             {
2678                 'title' : document.getElementById('circStrings').getString('staff.circ.utils.checkin.override'),
2679                 'auto_override_these_events' : suppress_popups ? [
2680                     null /* custom event */,
2681                     1203 /* COPY_BAD_STATUS */,
2682                     1213 /* PATRON_BARRED */,
2683                     1217 /* PATRON_INACTIVE */,
2684                     1224 /* PATRON_ACCOUNT_EXPIRED */,
2685                     1234 /* ITEM_DEPOSIT_PAID */,
2686                     7009 /* CIRC_CLAIMS_RETURNED */,
2687                     7010 /* COPY_ALERT_MESSAGE */,
2688                     7011 /* COPY_STATUS_LOST */,
2689                     7025 /* COPY_STATUS_LONG_OVERDUE */, 
2690                     7026 /* COPY_STATUS_LOST_AND_PAID */,
2691                     7012 /* COPY_STATUS_MISSING */,
2692                     7013 /* PATRON_EXCEEDS_FINES */
2693                 ] : [],
2694                 'overridable_events' : [
2695                     null /* custom event */,
2696                     1203 /* COPY_BAD_STATUS */,
2697                     1213 /* PATRON_BARRED */,
2698                     1217 /* PATRON_INACTIVE */,
2699                     1224 /* PATRON_ACCOUNT_EXPIRED */,
2700                     1234 /* ITEM_DEPOSIT_PAID */,
2701                     7009 /* CIRC_CLAIMS_RETURNED */,
2702                     7010 /* COPY_ALERT_MESSAGE */,
2703                     7011 /* COPY_STATUS_LOST */,
2704                     7025 /* COPY_STATUS_LONG_OVERDUE */, 
2705                     7026 /* COPY_STATUS_LOST_AND_PAID */,
2706                     7012 /* COPY_STATUS_MISSING */,
2707                     7013 /* PATRON_EXCEEDS_FINES */,
2708                     11103 /* TRANSIT_CHECKIN_INTERVAL_BLOCK */ 
2709                 ],
2710                 'text' : {
2711                     '1203' : function(r) {
2712                         return typeof r.payload.status() == 'object' ? r.payload.status().name() : data.hash.ccs[ r.payload.status() ].name();
2713                     },
2714                     '1234' : function(r) {
2715                         return document.getElementById('circStrings').getString('staff.circ.utils.checkin.override.item_deposit_paid.warning');
2716                     },
2717                     '7010' : function(r) {
2718                         return r.payload;
2719                     }
2720                 }
2721             }
2722         );
2723         if (! async ) {
2724             return checkin_callback( { 'getResultObject' : function() { return check; } } );
2725         }
2726
2727
2728     } catch(E) {
2729         JSAN.use('util.error'); var error = new util.error();
2730         error.standard_unexpected_error_alert(document.getElementById('circStrings').getFormattedString('staff.circ.checkin.error', ['2']), E);
2731         if (typeof params.enable_textbox == 'function') {
2732             try { params.enable_textbox(); } catch(E) { error.sdump('D_ERROR','params.disable_textbox() = ' + E); };
2733         }
2734         return null;
2735     }
2736 };
2737
2738 circ.util.checkin_via_barcode2 = function(session,params,backdate,auto_print,check) {
2739     try {
2740         JSAN.use('util.error'); var error = new util.error();
2741         JSAN.use('util.network'); var network = new util.network();
2742         JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.init({'via':'stash'});
2743         JSAN.use('util.date');
2744         JSAN.use('util.sound'); var sound = new util.sound();
2745
2746         dump('check = ' + error.pretty_print( js2JSON( check ) ) + '\n' );
2747
2748         check.message = check.textcode;
2749
2750         if (check.payload && check.payload.copy) { check.copy = check.payload.copy; }
2751         if (check.payload && check.payload.volume) { check.volume = check.payload.volume; }
2752         if (check.payload && check.payload.record) { check.record = check.payload.record; }
2753         if (check.payload && check.payload.circ) { check.circ = check.payload.circ; }
2754         if (check.payload && check.payload.patron) { check.patron = check.payload.patron; }
2755
2756         if (!check.route_to) { check.route_to = '   '; }
2757
2758         var no_change_label = document.getElementById('no_change_label');
2759
2760         if (no_change_label) {
2761             no_change_label.setAttribute('value','');
2762             no_change_label.setAttribute('hidden','true');
2763             no_change_label.setAttribute('onclick','');
2764             removeCSSClass(no_change_label,'click_link');
2765             no_change_label.setAttribute('unique_row_counter','');
2766         }
2767
2768         var msg = '';
2769         var print_list = [];
2770         var print_data = { 
2771             'error' : '',
2772             'error_msg' : '',
2773             'cancelled' : '',
2774             'route_to' : '',
2775             'route_to_msg' : '',
2776             'route_to_org_fullname' : '',
2777             'destination_shelf' : '',
2778             'destination_shelf_msg' : '',
2779             'courier_code' : '',
2780             'street1' : '',
2781             'street2' : '',
2782             'city_state_zip' : '',
2783             'city' : '',
2784             'state' : '',
2785             'county' : '',
2786             'country' : '',
2787             'post_code' : '',
2788             'item_barcode' : '',
2789             'item_barcode_msg' : '',
2790             'item_title' : '',
2791             'item_title_msg' : '',
2792             'item_author' : '',
2793             'item_author_msg' : '',
2794             'hold_for_msg' : '',
2795             'hold_for_alias' : '',
2796             'hold_for_family_name' : '',
2797             'hold_for_first_given_name' : '',
2798             'hold_for_second_given_name' : '',
2799             'user_barcode' : '',
2800             'user_barcode_msg' : '',
2801             'notify_by_phone' : '',
2802             'notify_by_phone_msg' : '',
2803             'notify_by_email' : '',
2804             'notify_by_email_msg' : '',
2805             'notify_by_text' : '',
2806             'notify_by_text_msg' : '',
2807             'request_date' : '',
2808             'request_date_msg' : '',
2809             'shelf_expire_time' : '',
2810             'slip_date' : '',
2811             'slip_date_msg' : '',
2812             'user' : '',
2813             'user_stat_cat_entries' : '',
2814             'transit_copy_status' : ''
2815         };
2816
2817         if (check.payload && check.payload.cancelled_hold_transit) {
2818             print_data.cancelled = document.getElementById('circStrings').getString('staff.circ.utils.transit_hold_cancelled');
2819             msg += print_data.cancelled;
2820             msg += '\n\n';
2821         }
2822
2823         var suppress_popups = data.hash.aous['ui.circ.suppress_checkin_popups'];
2824
2825         /* SUCCESS  /  NO_CHANGE  /  ITEM_NOT_CATALOGED */
2826         if (check.ilsevent == 0 || check.ilsevent == 3 || check.ilsevent == 1202) {
2827             try {
2828                 var acpl = data.lookup('acpl', check.copy.location()); 
2829                 check.route_to = acpl.name();
2830                 check.checkin_alert = isTrue(acpl.checkin_alert()) && !suppress_popups;
2831             } catch(E) {
2832                 print_data.error_msg = document.getElementById('commonStrings').getString('common.error');
2833                 print_data.error_msg += '\nFIXME: ' + E + '\n';
2834                 msg += print_data.error_msg;
2835             }
2836             if (check.ilsevent == 3 /* NO_CHANGE */) {
2837                 //msg = 'This item is already checked in.\n';
2838                 check.what_happened = 'no_change';
2839                 sound.special('checkin.no_change');
2840                 if (no_change_label) {
2841                     var m = no_change_label.getAttribute('value');
2842                     var text = document.getElementById('circStrings').getFormattedString('staff.circ.utils.item_checked_in', [params.barcode]);
2843                     no_change_label.setAttribute('value', m + text + '  ');
2844                     no_change_label.setAttribute('hidden','false');
2845                     no_change_label.setAttribute('onclick','');
2846                     removeCSSClass(no_change_label,'click_link');
2847                     no_change_label.setAttribute('unique_row_counter','');
2848                     if (typeof params.info_blurb == 'function') {
2849                         params.info_blurb( text );
2850                     }
2851                 }
2852             }
2853             if (check.ilsevent == 1202 /* ITEM_NOT_CATALOGED */ && check.copy.status() != 11) {
2854                 check.what_happened = 'error';
2855                 sound.special('checkin.error');
2856                 var copy_status = (data.hash.ccs[ check.copy.status() ] ? data.hash.ccs[ check.copy.status() ].name() : check.copy.status().name() );
2857                 var err_msg = document.getElementById('commonStrings').getString('common.error');
2858                 err_msg += '\nFIXME --';
2859                 err_msg += document.getElementById('circStrings').getFormattedString('staff.circ.utils.item_not_cataloged', [copy_status]);
2860                 err_msg += '\n';
2861                 msg += err_msg;
2862                 print_data.error_msg += err_msg;
2863             }
2864             switch(Number(check.copy.status())) {
2865                 case 0: /* AVAILABLE */
2866                 case 4: /* MISSING */
2867                 case 7: /* RESHELVING */
2868                     check.what_happened = 'success';
2869                     sound.special('checkin.success');
2870                     if (msg || check.checkin_alert) {
2871                         print_data.route_to_msg = document.getElementById('circStrings').getFormattedString('staff.circ.utils.route_to.msg', [check.route_to]);
2872                         print_data.route_to = check.route_to;
2873                         msg += print_data.route_to_msg;
2874                         msg += '\n';
2875                     }
2876                 break;
2877                 case 8: /* ON HOLDS SHELF */
2878                     check.what_happened = 'hold_shelf';
2879                     sound.special('checkin.hold_shelf');
2880                     check.route_to = document.getElementById('circStrings').getString('staff.circ.route_to.hold_shelf');
2881                     if (check.payload.hold) {
2882                         if (check.payload.hold.pickup_lib() != data.list.au[0].ws_ou()) {
2883                             check.what_happened = 'error';
2884                             sound.special('checkin.error');
2885                             var err_msg = document.getElementById('commonStrings').getString('common.error');
2886                             err_msg += '\nFIXME: ';
2887                             err_msg += document.getElementById('circStrings').getString('staff.circ.utils.route_item_error');
2888                             err_msg += '\n';
2889                             msg += err_msg;
2890                             print_data.error_msg += err_msg;
2891                         } else {
2892                             print_data.route_to_msg = document.getElementById('circStrings').getFormattedString('staff.circ.utils.route_to.msg', [check.route_to]);
2893                             print_data.route_to = check.route_to;
2894
2895                             // If the hold is marked as behind-shelf, report it as such 
2896                             // in the receipt, regardless of any org or user settings.  
2897                             if (isTrue(check.payload.hold.behind_desk())) {
2898                                 print_data.prefer_behind_holds_desk = true;
2899                                 check.route_to = document.getElementById('circStrings').getString('staff.circ.route_to.private_hold_shelf');
2900                                 print_data.route_to_msg = document.getElementById('circStrings').getFormattedString('staff.circ.utils.route_to.msg', [check.route_to]);
2901                                 print_data.route_to = check.route_to;
2902                             } else {
2903                                 check.route_to = document.getElementById('circStrings').getString('staff.circ.route_to.public_hold_shelf');
2904                                 print_data.route_to_msg = document.getElementById('circStrings').getFormattedString('staff.circ.utils.route_to.msg', [check.route_to]);
2905                                 print_data.route_to = check.route_to;
2906                             }
2907
2908                             print_data.destination_shelf_msg = print_data.route_to_msg;
2909                             print_data.destination_shelf = print_data.route_to;
2910                             msg += print_data.route_to_msg;
2911                             msg += '\n';
2912                         }
2913                     } else {
2914                         check.what_happened = 'error';
2915                         sound.special('checkin.error');
2916                         var err_msg = document.getElementById('commonStrings').getString('common.error');
2917                         err_msg += '\nFIXME: ';
2918                         err_msg += document.getElementById('circStrings').getString('staff.circ.utils.route_item_status_error');
2919                         err_msg += '\n';
2920                         msg += err_msg;
2921                         print_data.error_msg += err_msg;
2922                     }
2923                     JSAN.use('util.date');
2924                     if (check.payload.hold) {
2925                         JSAN.use('patron.util');
2926                         msg += '\n';
2927                         print_data.item_barcode_msg = document.getElementById('circStrings').getFormattedString('staff.circ.utils.payload.hold.barcode', [check.payload.copy.barcode()]);
2928                         print_data.item_barcode = check.payload.copy.barcode();
2929                         msg += print_data.item_barcode_msg;
2930                         msg += '\n';
2931                         var payload_title  = (check.payload.record ? check.payload.record.title() : check.payload.copy.dummy_title() );
2932                         print_data.item_title_msg = document.getElementById('circStrings').getFormattedString('staff.circ.utils.payload.hold.title', [payload_title]);
2933                         print_data.item_title = payload_title;
2934                         msg += print_data.item_title_msg;
2935                         msg += '\n';
2936                         var au_obj = patron.util.retrieve_fleshed_au_via_id( session, check.payload.hold.usr() );
2937                         print_data.user = au_obj;
2938                         print_data.user_stat_cat_entries = [];
2939                         var entries = au_obj.stat_cat_entries();
2940                         for (var i = 0; i < entries.length; i++) {
2941                             var stat_cat = data.hash.my_actsc[ entries[i].stat_cat() ];
2942                             if (!stat_cat) {
2943                                 stat_cat = data.lookup('actsc', entries[i].stat_cat());
2944                             }
2945                             print_data.user_stat_cat_entries.push( { 
2946                                 'id' : entries[i].id(),
2947                                 'stat_cat' : {
2948                                     'id' : stat_cat.id(),
2949                                     'name' : stat_cat.name(),
2950                                     'opac_visible' : stat_cat.opac_visible(),
2951                                     'owner' : stat_cat.owner(),
2952                                     'usr_summary' : stat_cat.usr_summary()
2953                                 },
2954                                 'stat_cat_entry' : entries[i].stat_cat_entry(),
2955                                 'target_usr' : entries[i].target_usr() 
2956                             } );
2957                         }
2958                         msg += '\n';
2959                         if (au_obj.alias()) {
2960                             print_data.hold_for_msg = document.getElementById('circStrings').getFormattedString('staff.circ.utils.payload.hold.patron_alias',  [au_obj.alias()]);
2961                             print_data.hold_for_alias = au_obj.alias();
2962                             msg += print_data.hold_for_msg;
2963                         } else {
2964                             print_data.hold_for_msg = document.getElementById('circStrings').getFormattedString('staff.circ.utils.payload.hold.patron',  [au_obj.family_name() ? au_obj.family_name() : '', au_obj.first_given_name() ? au_obj.first_given_name() : '', au_obj.second_given_name() ? au_obj.second_given_name() : '']);
2965                             msg += print_data.hold_for_msg;
2966                             print_data.hold_for_family_name = au_obj.family_name() ? au_obj.family_name() : '';
2967                             print_data.hold_for_first_given_name = au_obj.first_given_name() ? au_obj.first_given_name() : '';
2968                             print_data.hold_for_second_given_name = au_obj.second_given_name() ? au_obj.second_given_name() : '';
2969                         }
2970                         msg += '\n';
2971                         print_data.user_barcode_msg = document.getElementById('circStrings').getFormattedString('staff.circ.utils.payload.hold.barcode', [au_obj.card().barcode()]);
2972                         print_data.user_barcode = au_obj.card().barcode();
2973                         msg += print_data.user_barcode_msg;
2974                         msg += '\n';
2975                         if (check.payload.hold.phone_notify()) {
2976                             print_data.notify_by_phone_msg = document.getElementById('circStrings').getFormattedString('staff.circ.utils.payload.hold.phone_notify', [check.payload.hold.phone_notify()]);
2977                             print_data.notify_by_phone = check.payload.hold.phone_notify();
2978                             msg += print_data.notify_by_phone_msg;
2979                             msg += '\n';
2980                         }
2981                         if (check.payload.hold.sms_notify()) {
2982                             print_data.notify_by_text_msg = document.getElementById('circStrings').getFormattedString('staff.circ.utils.payload.hold.sms_notify', [check.payload.hold.sms_notify()]);
2983                             print_data.notify_by_text = check.payload.hold.sms_notify();
2984                             msg += print_data.notify_by_text_msg;
2985                             msg += '\n';
2986                         }
2987                         if (get_bool(check.payload.hold.email_notify())) {
2988                             var payload_email = au_obj.email() ? au_obj.email() : '';
2989                             print_data.notify_by_email_msg = document.getElementById('circStrings').getFormattedString('staff.circ.utils.payload.hold.email_notify', [payload_email]);
2990                             print_data.notify_by_email = payload_email;
2991                             msg += print_data.notify_by_email_msg;
2992                             msg += '\n';
2993                         }
2994                         msg += '\n';
2995                         var notes = check.payload.hold.notes();
2996                         print_data.notes_raw = notes;
2997                         for (var i = 0; i < notes.length; i++) {
2998                             if ( get_bool( notes[i].slip() ) ) {
2999                                 var temp_msg;
3000                                 if ( get_bool( notes[i].staff() ) ) {
3001                                     temp_msg = document.getElementById('circStrings').getFormattedString('staff.circ.utils.payload.hold.notes.staff_note', [ notes[i].title(), notes[i].body() ]);
3002                                 } else {
3003                                     temp_msg = document.getElementById('circStrings').getFormattedString('staff.circ.utils.payload.hold.notes.patron_note', [ notes[i].title(), notes[i].body() ]);
3004                                 }
3005                                 msg += temp_msg + '\n';
3006                                 print_list.push(
3007                                     {
3008                                         'formatted_note' : temp_msg,
3009                                         'note_title' : notes[i].title(),
3010                                         'note_body' : notes[i].body(),
3011                                         'note_public' : notes[i].pub(),
3012                                         'note_by_staff' : notes[i].staff()
3013                                     }
3014                                 );
3015                             }
3016                         }
3017                         msg += '\n';
3018                         msg += '\n';
3019                         print_data.request_date = util.date.formatted_date(check.payload.hold.request_time(),'%F');
3020                         print_data.request_date_msg = document.getElementById('circStrings').getFormattedString('staff.circ.utils.payload.hold.request_date', [print_data.request_date]);
3021                         print_data.shelf_expire_time = check.payload.hold.shelf_expire_time();
3022                         msg += print_data.request_date_msg;
3023                         msg += '\n';
3024                     }
3025                     var rv = 0;
3026                     if (suppress_popups) {
3027                         rv = auto_print ? 0 : -1; auto_print = true; // skip dialog and PRINT or DO NOT PRINT based on Auto-Print checkbox
3028                     }
3029                     var x = data.hash.aous['circ.staff_client.do_not_auto_attempt_print'];
3030                     var no_print_prompting = x ? ( x.indexOf( "Hold Slip" ) > -1) : false;
3031                     if (no_print_prompting) {
3032                         rv = -1; auto_print = true; // DO NOT PRINT and skip dialog
3033                     }
3034                     print_data.slip_date = util.date.formatted_date(new Date(),'%F');
3035                     print_data.slip_date_msg = document.getElementById('circStrings').getFormattedString('staff.circ.utils.payload.hold.slip_date', [print_data.slip_date]);
3036                     msg += print_data.slip_date_msg;
3037                     msg += '\n';
3038                     print_data.payload = check.payload;
3039
3040                     if (!auto_print) {
3041                         rv = error.yns_alert_formatted(
3042                             msg,
3043                             document.getElementById('circStrings').getString('staff.circ.utils.hold_slip'),
3044                             document.getElementById('circStrings').getString('staff.circ.utils.hold_slip.print.yes'),
3045                             document.getElementById('circStrings').getString('staff.circ.utils.hold_slip.print.no'),
3046                             null,
3047                             document.getElementById('circStrings').getString('staff.circ.confirm.msg'),
3048                             '/xul/server/skin/media/images/turtle.gif'
3049                         );
3050                     } else {
3051                         if (suppress_popups && !no_print_prompting) {
3052                             // FIXME: Add SFX and/or GFX
3053                             sound.circ_bad();
3054                         }
3055                     }
3056                     if (rv == 0) {
3057                         try {
3058                             JSAN.use('util.print'); var print = new util.print();
3059                             var old_template = String( data.hash.aous['ui.circ.old_harcoded_slip_template'] ) == 'true';
3060                             if (old_template) {
3061                                 msg = msg.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/\n/g,'<br/>');
3062                                 print.simple( msg , { 'no_prompt' : true, 'content_type' : 'text/html' } );
3063                             } else {
3064                                 var template = 'hold_slip';
3065                                 var parms = {
3066                                     'patron' : print_data.user,
3067                                     'lib' : data.hash.aou[ check.payload.hold.pickup_lib() ],
3068                                     'staff' : data.list.au[0],
3069                                     'header' : data.print_list_templates[ template ].header,
3070                                     'line_item' : data.print_list_templates[ template ].line_item,
3071                                     'footer' : data.print_list_templates[ template ].footer,
3072                                     'type' : data.print_list_templates[ template ].type,
3073                                     'list' : print_list,
3074                                     'data' : print_data,
3075                                     'context' : data.print_list_templates[ template ].context,
3076                                 };
3077                                 if ($('printer_prompt')) {
3078                                     if (! $('printer_prompt').checked) { parms.no_prompt = true; }
3079                                 }
3080                                 print.tree_list( parms );
3081                             }
3082                         } catch(E) {
3083                             var err_msg = document.getElementById('commonStrings').getString('common.error');
3084                             err_msg += '\nFIXME: ' + E + '\n';
3085                             dump(err_msg);
3086                             alert(err_msg);
3087                         }
3088                     }
3089                     msg = '';
3090                     if (no_change_label) {
3091                         var m = no_change_label.getAttribute('value');
3092                         var text = document.getElementById('circStrings').getFormattedString('staff.circ.utils.capture', [params.barcode]);
3093                         m += text + '  ';
3094                         no_change_label.setAttribute('value', m);
3095                         no_change_label.setAttribute('hidden','false');
3096                         no_change_label.setAttribute('onclick','');
3097                         removeCSSClass(no_change_label,'click_link');
3098                         no_change_label.setAttribute('unique_row_counter','');
3099                         if (typeof params.info_blurb == 'function') {
3100                             params.info_blurb( text );
3101                         }
3102                     }
3103                 break;
3104                 case 6: /* IN TRANSIT */
3105                     check.what_happened = 'error';
3106                     sound.special('checkin.error');
3107                     check.route_to = 'TRANSIT SHELF??';
3108                     print_data.route_to;
3109                     var err_msg = document.getElementById('commonStrings').getString('common.error');
3110                     err_msg += "\nFIXME -- I didn't think we could get here.\n";
3111                     print_data.error_msg += err_msg;
3112                     msg += err_msg;
3113                 break;
3114                 case 11: /* CATALOGING */
3115                     check.what_happened = 'cataloging';
3116                     sound.special('checkin.cataloging');
3117                     check.route_to = 'CATALOGING';
3118                     print_data.route_to;
3119                     var x = document.getElementById('do_not_alert_on_precat');
3120                     var do_not_alert_on_precats = x ? ( x.getAttribute('checked') == 'true' ) : false;
3121                     if ( !suppress_popups && !do_not_alert_on_precats ) {
3122                         print_data.route_to_msg = document.getElementById('circStrings').getFormattedString('staff.circ.utils.route_to.msg', [check.route_to]);
3123                         msg += print_data.route_to_msg;
3124                     } else {
3125                         if (suppress_popups && !do_not_alert_on_precats) {
3126                             // FIXME: add SFX and/or GFX
3127                             sound.circ_bad();
3128                         }
3129                     }
3130                     if (no_change_label) {
3131                         var m = no_change_label.getAttribute('value');
3132                         var needs_cat = document.getElementById('circStrings').getFormattedString('staff.circ.utils.needs_cataloging', [params.barcode]);
3133                         no_change_label.setAttribute('value', m + needs_cat + '  ');
3134                         no_change_label.setAttribute('hidden','false');
3135                         no_change_label.setAttribute('onclick','');
3136                         removeCSSClass(no_change_label,'click_link');
3137                         no_change_label.setAttribute('unique_row_counter','');
3138                         if (typeof params.info_blurb == 'function') {
3139                             params.info_blurb( needs_cat );
3140                         }
3141                     }
3142                 break;
3143                 case 15: // ON_RESERVATION_SHELF
3144                     check.route_to = 'RESERVATION SHELF';
3145                     check.what_happened = "reservation_shelf";
3146                     sound.special('checkin.reservation_shelf');
3147                     if (check.payload.reservation) {
3148                         if (check.payload.reservation.pickup_lib() != data.list.au[0].ws_ou()) {
3149                             msg += document.getElementById('commonStrings').getString('common.error');
3150                             msg += '\nFIXME: ';
3151                             msg += document.getElementById('circStrings').getString('staff.circ.utils.route_item_error');
3152                             msg += '\n';
3153                         } else {
3154                             msg += document.getElementById('circStrings').getFormattedString('staff.circ.utils.route_to.msg', [check.route_to]);
3155                             msg += '.\n';
3156                         }
3157                     } else {
3158                         msg += document.getElementById('commonStrings').getString('common.error');
3159                         msg += '\nFIXME: ';
3160                         msg += document.getElementById('circStrings').getString('staff.circ.utils.reservation_status_error');
3161                         msg += '\n';
3162                     }
3163                     JSAN.use('util.date');
3164                     if (check.payload.reservation) {
3165                         JSAN.use('patron.util');
3166                         msg += '\n';
3167                         msg += document.getElementById('circStrings').getFormattedString('staff.circ.utils.payload.reservation.barcode', [check.payload.copy.barcode()]);
3168                         msg += '\n';
3169                         var payload_title  = (check.payload.record ? check.payload.record.title() : check.payload.copy.dummy_title() );
3170                         msg += document.getElementById('circStrings').getFormattedString('staff.circ.utils.payload.reservation.title', [payload_title]);
3171                         msg += '\n';
3172                         var au_obj =
3173                             typeof(check.payload.reservation.usr().card) == "function" ?
3174                                 check.payload.reservation.usr() :
3175                                 patron.util.retrieve_fleshed_au_via_id(session, check.payload.reservation.usr());
3176                         msg += '\n';
3177                         if (au_obj.alias()) {
3178                             msg += document.getElementById('circStrings').getFormattedString('staff.circ.utils.payload.reservation.patron_alias',  [au_obj.alias()]);
3179                         } else {
3180                             msg += document.getElementById('circStrings').getFormattedString('staff.circ.utils.payload.reservation.patron',  [au_obj.family_name() || "", au_obj.first_given_name() || "", au_obj.second_given_name() || ""]);
3181                         }
3182                         msg += '\n';
3183                         msg += document.getElementById('circStrings').getFormattedString('staff.circ.utils.payload.reservation.barcode', [au_obj.card().barcode()]);
3184                         msg += '\n';
3185                         msg += document.getElementById('circStrings').getFormattedString('staff.circ.utils.payload.reservation.request_date', [util.date.formatted_date(check.payload.reservation.request_time(),'%F %H:%M')]);
3186                         msg += '\n';
3187
3188                         msg += document.getElementById('circStrings').getFormattedString('staff.circ.utils.payload.reservation.start_date', [util.date.formatted_date(check.payload.reservation.start_time(),'%F %H:%M')]);
3189                         msg += '\n';
3190                     }
3191                     var rv = 0;
3192                     msg += document.getElementById('circStrings').getFormattedString('staff.circ.utils.payload.reservation.slip_date', [util.date.formatted_date(new Date(),'%F')]);
3193                     msg += '\n';
3194                     if (!auto_print) {
3195                         rv = error.yns_alert_formatted(
3196                             msg,
3197                             document.getElementById('circStrings').getString('staff.circ.utils.reservation_slip'),
3198                             document.getElementById('circStrings').getString('staff.circ.utils.reservation_slip.print.yes'),
3199                             document.getElementById('circStrings').getString('staff.circ.utils.reservation_slip.print.no'),
3200                             null,
3201                             document.getElementById('circStrings').getString('staff.circ.confirm.msg'),
3202                             '/xul/server/skin/media/images/turtle.gif'
3203                         );
3204                     }
3205                     if (rv == 0) {
3206                         try {
3207                             JSAN.use('util.print'); var print = new util.print();
3208                             msg = msg.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/\n/g,'<br/>');
3209                             print.simple( msg , { 'no_prompt' : true, 'content_type' : 'text/html' } );
3210                         } catch(E) {
3211                             var err_msg = document.getElementById('commonStrings').getString('common.error');
3212                             err_msg += '\nFIXME: ' + E + '\n';
3213                             dump(err_msg);
3214                             alert(err_msg);
3215                         }
3216                     }
3217                     msg = '';
3218                     if (no_change_label) {
3219                         var m = no_change_label.getAttribute('value');
3220                         var text = document.getElementById('circStrings').getFormattedString('staff.circ.utils.reservation_capture', [params.barcode]);
3221                         m += text + '  ';
3222                         no_change_label.setAttribute('value', m);
3223                         no_change_label.setAttribute('hidden','false');
3224                         no_change_label.setAttribute('onclick','');
3225                         removeCSSClass(no_change_label,'click_link');
3226                         no_change_label.setAttribute('unique_row_counter','');
3227                         if (typeof params.info_blurb == 'function') {
3228                             params.info_blurb( text );
3229                         }
3230                     }
3231                 break;
3232                 default:
3233                     check.what_happened = 'error';
3234                     sound.special('checkin.error');
3235                     msg += document.getElementById('commonStrings').getString('common.error');
3236                     var copy_status = data.hash.ccs[check.copy.status()] ? data.hash.ccs[check.copy.status()].name() : check.copy.status().name();
3237                     msg += '\n';
3238                     var error_msg = document.getElementById('circStrings').getFormattedString('staff.circ.utils.copy_status.error', [copy_status]);
3239                     print_data.error_msg += error_msg;
3240                     msg += error_msg;
3241                     msg += '\n';
3242                     print_data.route_to_msg = document.getElementById('circStrings').getFormattedString('staff.circ.utils.route_to.msg', [check.route_to]);
3243                     msg += print_data.route_to_msg;
3244                 break;
3245             }
3246             if (msg) {
3247                 error.yns_alert(
3248                     msg,
3249                     document.getElementById('circStrings').getString('staff.circ.alert'),
3250                     null,
3251                     document.getElementById('circStrings').getString('staff.circ.utils.msg.ok'),
3252                     null,
3253                     document.getElementById('circStrings').getString('staff.circ.confirm.msg')
3254                 );
3255             }
3256         } else /* ROUTE_ITEM */ if (check.ilsevent == 7000) {
3257
3258             check.what_happened = 'transit';
3259             sound.special('checkin.transit');
3260             var lib = data.hash.aou[ check.org ];
3261             check.route_to = lib.shortname();
3262             print_data.route_to = check.route_to;
3263             print_data.route_to_org = lib;
3264             print_data.route_to_msg = document.getElementById('circStrings').getFormattedString('staff.circ.utils.route_to.destination', [check.route_to]);
3265             print_data.route_to_org_fullname = lib.name();
3266             var aous_req = network.simple_request('FM_AOUS_SPECIFIC_RETRIEVE',[ lib.id(), 'lib.courier_code' ]);
3267             if (aous_req) {
3268                 print_data.courier_code = aous_req.value || '';
3269             }
3270             msg += print_data.route_to_msg;
3271             msg += '\n\n';
3272             msg += lib.name();
3273             msg += '\n';
3274             try {
3275                 if (lib.holds_address() ) {
3276                     var a = network.simple_request('FM_AOA_RETRIEVE',[ lib.holds_address() ]);
3277                     if (typeof a.ilsevent != 'undefined') throw(a);
3278                     if (a.street1()) { msg += a.street1() + '\n'; print_data.street1 = a.street1(); }
3279                     if (a.street2()) { msg += a.street2() + '\n'; print_data.street2 = a.street2(); }
3280                     print_data.city_state_zip = (a.city() ? a.city() + ', ' : '') + (a.state() ? a.state() + ' ' : '') + (a.post_code() ? a.post_code() : '');
3281                     print_data.city = a.city();
3282                     print_data.state = a.state();
3283                     print_data.county = a.county();
3284                     print_data.country = a.country();
3285                     print_data.post_code = a.post_code();
3286                     msg += print_data.city_state_zip + '\n';
3287                 } else {
3288                     print_data.street1 = document.getElementById('circStrings').getString('staff.circ.utils.route_to.no_address');
3289                     print_data.no_address = true;
3290                     msg += print_data.street1;
3291                     msg += '\n';
3292                 }
3293             } catch(E) {
3294                 var err_msg = document.getElementById('circStrings').getString('staff.circ.utils.route_to.no_address.error');
3295                 print_data.error_msg += err_msg + '\n';
3296                 msg += err_msg + '\n';
3297                 error.standard_unexpected_error_alert(document.getElementById('circStrings').getString('staff.circ.utils.route_to.no_address.error'), E);
3298             }
3299             msg += '\n';
3300             print_data.item_barcode_msg = document.getElementById('circStrings').getFormattedString('staff.circ.utils.payload.hold.barcode', [check.payload.copy.barcode()]);
3301             print_data.item_barcode = check.payload.copy.barcode();
3302             msg += print_data.item_barcode_msg;
3303             msg += '\n';
3304             var payload_title  = (check.payload.record ? check.payload.record.title() : check.payload.copy.dummy_title() );
3305             print_data.item_title_msg = document.getElementById('circStrings').getFormattedString('staff.circ.utils.payload.hold.title', [payload_title]);
3306             print_data.item_title = payload_title;
3307             msg += print_data.item_title_msg;
3308             msg += '\n';
3309             var payload_author = (check.payload.record ? check.payload.record.author() :check.payload.copy.dummy_author());
3310             print_data.item_author_msg = document.getElementById('circStrings').getFormattedString('staff.circ.utils.payload.author', [payload_author]);
3311             print_data.item_author = payload_author;
3312             msg += print_data.item_author_msg;
3313             msg += '\n';
3314             if (check.payload.transit) {
3315                 // by adding this here, we make the data available to the
3316                 // receipt printing engine, but since we are not appending it
3317                 // to the 'msg', it will not display in the pre-print dialog.
3318                 print_data.transit_copy_status = 
3319                     data.hash.ccs[check.payload.transit.copy_status()].name();
3320             }
3321             JSAN.use('util.date');
3322             if (check.payload.hold) {
3323                 check.what_happened = 'transit_for_hold';
3324                 sound.special('checkin.transit_for_hold');
3325                 JSAN.use('patron.util');
3326                 var au_obj = patron.util.retrieve_fleshed_au_via_id( session, check.payload.hold.usr() );
3327                 print_data.user = au_obj;
3328                 print_data.user_stat_cat_entries = [];
3329                 var entries = au_obj.stat_cat_entries();
3330                 for (var i = 0; i < entries.length; i++) {
3331                     var stat_cat = data.hash.my_actsc[ entries[i].stat_cat() ];
3332                     if (!stat_cat) {
3333                         stat_cat = data.lookup('actsc', entries[i].stat_cat());
3334                     }
3335                     print_data.user_stat_cat_entries.push( { 
3336                         'id' : entries[i].id(),
3337                         'stat_cat' : {
3338                             'id' : stat_cat.id(),
3339                             'name' : stat_cat.name(),
3340                             'opac_visible' : stat_cat.opac_visible(),
3341                             'owner' : stat_cat.owner(),
3342                             'usr_summary' : stat_cat.usr_summary()
3343                         },
3344                         'stat_cat_entry' : entries[i].stat_cat_entry(),
3345                         'target_usr' : entries[i].target_usr() 
3346                     } );
3347                 }
3348                 msg += '\n';
3349                 if (au_obj.alias()) {
3350                     print_data.hold_for_msg = document.getElementById('circStrings').getFormattedString('staff.circ.utils.payload.hold.patron_alias',  [au_obj.alias()]);
3351                     print_data.hold_for_alias = au_obj.alias();
3352                     msg += print_data.hold_for_msg;
3353                 } else {
3354                     print_data.hold_for_msg = document.getElementById('circStrings').getFormattedString('staff.circ.utils.payload.hold.patron',  [au_obj.family_name() ? au_obj.family_name() : '', au_obj.first_given_name() ? au_obj.first_given_name() : '', au_obj.second_given_name() ? au_obj.second_given_name() : '']);
3355                     msg += print_data.hold_for_msg;
3356                     print_data.hold_for_family_name = au_obj.family_name() ? au_obj.family_name() : '';
3357                     print_data.hold_for_first_given_name = au_obj.first_given_name() ? au_obj.first_given_name() : '';
3358                     print_data.hold_for_second_given_name = au_obj.second_given_name() ? au_obj.second_given_name() : '';
3359                 }
3360                 msg += '\n';
3361                 print_data.user_barcode_msg = document.getElementById('circStrings').getFormattedString('staff.circ.utils.payload.hold.barcode', [au_obj.card().barcode()]);
3362                 print_data.user_barcode = au_obj.card().barcode();
3363                 msg += print_data.user_barcode_msg;
3364                 msg += '\n';
3365                 if (check.payload.hold.phone_notify()) {
3366                     print_data.notify_by_phone_msg = document.getElementById('circStrings').getFormattedString('staff.circ.utils.payload.hold.phone_notify', [check.payload.hold.phone_notify()]);
3367                     print_data.notify_by_phone = check.payload.hold.phone_notify();
3368                     msg += print_data.notify_by_phone_msg;
3369                     msg += '\n';
3370                 }
3371                 if (check.payload.hold.sms_notify()) {
3372                     print_data.notify_by_text_msg = document.getElementById('circStrings').getFormattedString('staff.circ.utils.payload.hold.sms_notify', [check.payload.hold.sms_notify()]);
3373                     print_data.notify_by_text = check.payload.hold.sms_notify();
3374                     msg += print_data.notify_by_text_msg;
3375                     msg += '\n';
3376                 }
3377                 if (get_bool(check.payload.hold.email_notify())) {
3378                     var payload_email = au_obj.email() ? au_obj.email() : '';
3379                     print_data.notify_by_email_msg = document.getElementById('circStrings').getFormattedString('staff.circ.utils.payload.hold.email_notify', [payload_email]);
3380                     print_data.notify_by_email = payload_email;
3381                     msg += print_data.notify_by_email_msg;
3382                     msg += '\n';
3383                 }
3384                 msg += '\n';
3385                 var notes = check.payload.hold.notes();
3386                 print_data.notes_raw = notes;
3387                 for (var i = 0; i < notes.length; i++) {
3388                     if ( get_bool( notes[i].slip() ) ) {
3389                         var temp_msg;
3390                         if ( get_bool( notes[i].staff() ) ) {
3391                             temp_msg = document.getElementById('circStrings').getFormattedString('staff.circ.utils.payload.hold.notes.staff_note', [ notes[i].title(), notes[i].body() ]);
3392                         } else {
3393                             temp_msg = document.getElementById('circStrings').getFormattedString('staff.circ.utils.payload.hold.notes.patron_note', [ notes[i].title(), notes[i].body() ]);
3394                         }
3395                         msg += temp_msg + '\n';
3396                         print_list.push(
3397                             {
3398                                 'formatted_note' : temp_msg,
3399                                 'note_title' : notes[i].title(),
3400                                 'note_body' : notes[i].body(),
3401                                 'note_public' : notes[i].pub(),
3402                                 'note_by_staff' : notes[i].staff()
3403                             }
3404                         );
3405                     }
3406                 }
3407                 msg += '\n';
3408                 msg += '\n';
3409                 print_data.request_date = util.date.formatted_date(check.payload.hold.request_time(),'%F');
3410                 print_data.request_date_msg = document.getElementById('circStrings').getFormattedString('staff.circ.utils.payload.hold.request_date', [print_data.request_date]);
3411                 msg += print_data.request_date_msg;
3412                 msg += '\n';
3413                 var destination_shelf = document.getElementById('circStrings').getString('staff.circ.route_to.hold_shelf');
3414                 print_data.destination_shelf_msg = document.getElementById('circStrings').getFormattedString('staff.circ.utils.route_to.msg', [destination_shelf]);
3415                 print_data.destination_shelf = destination_shelf;
3416                 var behind_the_desk_support = String( data.hash.aous['circ.holds.behind_desk_pickup_supported'] ) == 'true';
3417                 if (behind_the_desk_support) {
3418                    var usr_settings = network.simple_request('FM_AUS_RETRIEVE',[ses(),check.payload.hold.usr()]); 
3419                     if (typeof usr_settings['circ.holds_behind_desk'] != 'undefined') {
3420                         if (usr_settings['circ.holds_behind_desk']) {
3421                             print_data.prefer_behind_holds_desk = true;
3422                             destination_shelf = document.getElementById('circStrings').getString('staff.circ.route_to.private_hold_shelf');
3423                             print_data.destination_shelf_msg = document.getElementById('circStrings').getFormattedString('staff.circ.utils.route_to.msg', [destination_shelf]);
3424                             print_data.destination_shelf = destination_shelf;
3425                         } else {
3426                             destination_shelf = document.getElementById('circStrings').getString('staff.circ.route_to.public_hold_shelf');
3427                             print_data.destination_shelf_msg = document.getElementById('circStrings').getFormattedString('staff.circ.utils.route_to.msg', [destination_shelf]);
3428                             print_data.destination_shelf = destination_shelf;
3429                         }
3430                     } else {
3431                         destination_shelf = document.getElementById('circStrings').getString('staff.circ.route_to.public_hold_shelf');
3432                         print_data.destination_shelf_msg = document.getElementById('circStrings').getFormattedString('staff.circ.utils.route_to.msg', [destination_shelf]);
3433                         print_data.destination_shelf = destination_shelf;
3434                     }
3435                 }
3436             }
3437             var rv = 0;
3438             if (suppress_popups) {
3439                 rv = auto_print ? 0 : -1; auto_print = true; // skip dialog and PRINT or DO NOT PRINT based on Auto-Print checkbox
3440             }
3441             var x = data.hash.aous['circ.staff_client.do_not_auto_attempt_print'];
3442             var no_print_prompting = x ? (x.indexOf( check.payload.hold ? "Hold/Transit Slip" : "Transit Slip" ) > -1) : false;
3443             if (no_print_prompting) {
3444                 rv = -1; auto_print = true; // DO NOT PRINT and skip dialog
3445             }
3446             print_data.slip_date = util.date.formatted_date(new Date(),'%F');
3447             print_data.slip_date_msg = document.getElementById('circStrings').getFormattedString('staff.circ.utils.payload.hold.slip_date', [print_data.slip_date]);
3448             msg += print_data.slip_date_msg;
3449             print_data.payload = check.payload;
3450
3451             if (!auto_print) {
3452                 rv = error.yns_alert_formatted(
3453                     msg,
3454                     document.getElementById('circStrings').getString('staff.circ.utils.transit_slip'),
3455                     document.getElementById('circStrings').getString('staff.circ.utils.transit_slip.print.yes'),
3456                     document.getElementById('circStrings').getString('staff.circ.utils.transit_slip.print.no'),
3457                     null,
3458                     document.getElementById('circStrings').getString('staff.circ.confirm.msg'),
3459                     '/xul/server/skin/media/images/turtle.gif'
3460                 );
3461             } else {
3462                 if (suppress_popups && !no_print_prompting) {
3463                     // FIXME: add SFX and/or GFX
3464                     sound.circ_bad();
3465                 }
3466             }
3467             if (rv == 0) {
3468                 try {
3469                     JSAN.use('util.print'); var print = new util.print();
3470                     var old_template = String( data.hash.aous['ui.circ.old_harcoded_slip_template'] ) == 'true';
3471                     if (old_template) {
3472                         msg = msg.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/\n/g,'<br/>');
3473                         print.simple( msg , { 'no_prompt' : true, 'content_type' : 'text/html' } );
3474                     } else {
3475                         var template = check.payload.hold ? 'hold_transit_slip' : 'transit_slip';
3476                         var parms = {
3477                             'patron' : print_data.user,
3478                             'lib' : data.hash.aou[ data.list.au[0].ws_ou() ],
3479                             'staff' : data.list.au[0],
3480                             'header' : data.print_list_templates[ template ].header,
3481                             'line_item' : data.print_list_templates[ template ].line_item,
3482                             'footer' : data.print_list_templates[ template ].footer,
3483                             'type' : data.print_list_templates[ template ].type,
3484                             'list' : print_list,
3485                             'data' : print_data,
3486                             'context' : data.print_list_templates[ template ].context,
3487                         };
3488                         if ($('printer_prompt')) {
3489                             if (! $('printer_prompt').checked) { parms.no_prompt = true; }
3490                         }
3491                         print.tree_list( parms );
3492                     }
3493                 } catch(E) {
3494                     var err_msg = document.getElementById('commonStrings').getString('common.error');
3495                     err_msg += '\nFIXME: ' + E + '\n';
3496                     dump(err_msg);
3497                     alert(err_msg);
3498                 }
3499             }
3500             if (no_change_label) {
3501                 var m = no_change_label.getAttribute('value');
3502                 var trans_msg = document.getElementById('circStrings').getFormattedString('staff.circ.utils.payload.in_transit', [params.barcode]);
3503                 no_change_label.setAttribute('value', m + trans_msg + '  ');
3504                 no_change_label.setAttribute('hidden','false');
3505                 no_change_label.setAttribute('onclick','');
3506                 removeCSSClass(no_change_label,'click_link');
3507                 no_change_label.setAttribute('unique_row_counter','');
3508                 if (typeof params.info_blurb == 'function') {
3509                     params.info_blurb( trans_msg );
3510                 }
3511             }
3512
3513         } else /* ASSET_COPY_NOT_FOUND */ if (check.ilsevent == 1502) {
3514
3515             check.what_happened = 'not_found';
3516             sound.special('checkin.not_found');
3517             check.route_to = 'CATALOGING';
3518             var mis_scan_msg = document.getElementById('circStrings').getFormattedString('staff.circ.copy_status.status.copy_not_found', [params.barcode]);
3519             if (!suppress_popups) {
3520                 error.yns_alert(
3521                     mis_scan_msg,
3522                     document.getElementById('circStrings').getString('staff.circ.alert'),
3523                     null,
3524                     document.getElementById('circStrings').getString('staff.circ.utils.msg.ok'),
3525                     null,
3526                     document.getElementById('circStrings').getString('staff.circ.confirm.msg')
3527                 );
3528             } else {
3529                 // FIXME: add SFX and/or GFX
3530                 sound.circ_bad();
3531             }
3532             if (no_change_label) {
3533                 var m = no_change_label.getAttribute('value');
3534                 no_change_label.setAttribute('value',m + mis_scan_msg + '  ');
3535                 no_change_label.setAttribute('hidden','false');
3536                 no_change_label.setAttribute('onclick','');
3537                 removeCSSClass(no_change_label,'click_link');
3538                 no_change_label.setAttribute('unique_row_counter','');
3539                 if (typeof params.info_blurb == 'function') {
3540                     params.info_blurb( mis_scan_msg );
3541                 }
3542             }
3543
3544         } else /* HOLD_CAPTURE_DELAYED */ if (check.ilsevent == 7019) {
3545
3546             check.what_happened = 'hold_capture_delayed';
3547             sound.special('checkin.hold_capture_delayed');
3548             var rv = 0;
3549             msg += document.getElementById('circStrings').getString('staff.circ.utils.hold_capture_delayed.description');
3550             if (!suppress_popups) {
3551                 rv = error.yns_alert_formatted(
3552                     msg,
3553                     document.getElementById('circStrings').getString('staff.circ.utils.hold_capture_delayed.titlebar'),
3554                     document.getElementById('circStrings').getString('staff.circ.utils.hold_capture_delayed.prompt_for_nocapture'),
3555                     document.getElementById('circStrings').getString('staff.circ.utils.hold_capture_delayed.prompt_for_capture'),
3556                     null,
3557                     document.getElementById('circStrings').getString('staff.circ.confirm.msg'),
3558                     '/xul/server/skin/media/images/stop_sign.png'
3559                 );
3560             } else {
3561                 // FIXME: add SFX and/or GFX
3562                 sound.circ_bad();
3563             }
3564             params.capture = rv == 0 ? 'nocapture' : 'capture';
3565
3566             return circ.util.checkin_via_barcode(session,params,backdate,auto_print,false);
3567
3568         } else /* NETWORK TIMEOUT */ if (check.ilsevent == -1) {
3569             check.what_happened = 'error';
3570             sound.special('checkin.error');
3571             error.standard_network_error_alert(document.getElementById('circStrings').getString('staff.circ.checkin.suggest_offline'));
3572         } else {
3573
3574             if (check.ilsevent == null) { return null; /* handled */ }
3575             switch (Number(check.ilsevent)) {
3576                 case 1203 /* COPY_BAD_STATUS */ :
3577                 case 1213 /* PATRON_BARRED */ :
3578                 case 1217 /* PATRON_INACTIVE */ :
3579                 case 1224 /* PATRON_ACCOUNT_EXPIRED */ :
3580                 case 1234 /* ITEM_DEPOSIT_PAID */ :
3581                 case 7009 /* CIRC_CLAIMS_RETURNED */ :
3582                 case 7010 /* COPY_ALERT_MESSAGE */ :
3583                 case 7011 /* COPY_STATUS_LOST */ :
3584                 case 7025 /* COPY_STATUS_LONG_OVERDUE */ :
3585                 case 7012 /* COPY_STATUS_MISSING */ :
3586                 case 7013 /* PATRON_EXCEEDS_FINES */ :
3587                     return null; /* handled */
3588                 break;
3589             }
3590
3591             throw(check);
3592
3593         }
3594
3595         return check;
3596     } catch(E) {
3597         JSAN.use('util.error'); var error = new util.error();
3598         error.standard_unexpected_error_alert(document.getElementById('circStrings').getFormattedString('staff.circ.checkin.error', ['3']), E);
3599         return null;
3600     }
3601 };
3602
3603 circ.util.renew_via_barcode = function ( params, async ) {
3604     try {
3605         var obj = {};
3606         JSAN.use('util.network'); obj.network = new util.network();
3607         JSAN.use('OpenILS.data'); obj.data = new OpenILS.data(); obj.data.stash_retrieve();
3608
3609         function renew_callback(req) {
3610             try {
3611                 JSAN.use('util.error'); var error = new util.error();
3612                 var renew = req.getResultObject();
3613                 if (typeof renew.ilsevent != 'undefined') renew = [ renew ];
3614                 for (var j = 0; j < renew.length; j++) {
3615                     switch(renew[j].ilsevent == null ? null : Number(renew[j].ilsevent)) {
3616                         case 0 /* SUCCESS */ : break;
3617                         case null /* custom event */ : break;
3618                         case 5000 /* PERM_FAILURE */: break;
3619                         case 1212 /* PATRON_EXCEEDS_OVERDUE_COUNT */ : break;
3620                         case 7002 /* PATRON_EXCEEDS_CHECKOUT_COUNT */ : break;
3621                         case 1213 /* PATRON_BARRED */ : break;
3622                         case 1215 /* CIRC_EXCEEDS_COPY_RANGE */ : break;
3623                         case 1224 /* PATRON_ACCOUNT_EXPIRED */ : break;
3624                         case 1232 /* ITEM_DEPOSIT_REQUIRED */ : break;
3625                         case 1233 /* ITEM_RENTAL_FEE_REQUIRED */ : break;
3626                         case 1234 /* ITEM_DEPOSIT_PAID */ : break;
3627                         case 1236 /* PATRON_EXCEEDS_LOST_COUNT */ : break;
3628                         case 1500 /* ACTION_CIRCULATION_NOT_FOUND */ : break;
3629                         case 1502 /* ASSET_COPY_NOT_FOUND */ : 
3630                             var mis_scan_msg = document.getElementById('circStrings').getFormattedString('staff.circ.copy_status.status.copy_not_found', [params.barcode]);
3631                             error.yns_alert(
3632                                 mis_scan_msg,
3633                                 document.getElementById('circStrings').getString('staff.circ.alert'),
3634                                 null,
3635                                 document.getElementById('circStrings').getString('staff.circ.utils.msg.ok'),
3636                                 null,
3637                                 document.getElementById('circStrings').getString('staff.circ.confirm.msg')
3638                             );
3639                             if (no_change_label) {
3640                                 var m = no_change_label.getAttribute('value');
3641                                 no_change_label.setAttribute('value',m + mis_scan_msg + '  ');
3642                                 no_change_label.setAttribute('hidden','false');
3643                                 no_change_label.setAttribute('onclick','');
3644                                 removeCSSClass(no_change_label,'click_link');
3645                                 no_change_label.setAttribute('unique_row_counter','');
3646                                 if (typeof params.info_blurb == 'function') {
3647                                     params.info_blurb( mis_scan_msg );
3648                                 }
3649                             }
3650                         break;
3651                         case 7002 /* PATRON_EXCEEDS_CHECKOUT_COUNT */ : break;
3652                         case 7003 /* COPY_CIRC_NOT_ALLOWED */ : break;
3653                         case 7004 /* COPY_NOT_AVAILABLE */ : break;
3654                         case 7006 /* COPY_IS_REFERENCE */ : break;
3655                         case 7007 /* COPY_NEEDED_FOR_HOLD */ : break;
3656                         case 7008 /* MAX_RENEWALS_REACHED */ : break;
3657                         case 7009 /* CIRC_CLAIMS_RETURNED */ : break;
3658                         case 7010 /* COPY_ALERT_MESSAGE */ : break;
3659                         case 7013 /* PATRON_EXCEEDS_FINES */ : break;
3660                         default:
3661                             throw(renew);
3662                         break;
3663                     }
3664                 }
3665                 try {
3666                     var ibarcode = renew[0].payload.copy ? renew[0].payload.copy.barcode() : params.barcode;
3667                     var p_id = renew[0].payload.patron ? renew[0].payload.patron.id() : renew[0].payload.circ.usr();
3668                     var pname; var pbarcode; 
3669                     if (renew[0].patron) {
3670                         pname = renew[0].payload.patron.family_name();
3671                         pbarcode = typeof renew[0].payload.patron.card() == 'object' ? renew[0].payload.patron.card().barcode() : null;
3672                     } else {
3673                         if (circ.util.renew_via_barcode.last_usr_id == p_id) {
3674                             pname = circ.util.renew_via_barcode.last_pname;
3675                             pbarcode = circ.util.renew_via_barcode.last_pbarcode;
3676                         } else {
3677                             JSAN.use('patron.util'); var p = patron.util.retrieve_fleshed_au_via_id(ses(),p_id);
3678                             pname = p.family_name();
3679                             pbarcode = typeof p.card() == 'object' ? p.card().barcode() : null;
3680                             if (pname) {
3681                                 circ.util.renew_via_barcode.last_usr_id = p_id;
3682                                 circ.util.renew_via_barcode.last_pname = pname;
3683                                 circ.util.renew_via_barcode.last_pbarcode = pbarcode;
3684                             }
3685                         } 
3686                     }
3687                     error.work_log(
3688                         document.getElementById('circStrings').getFormattedString(
3689                             'staff.circ.work_log_renew.message',
3690                             [
3691                                 ses('staff_usrname'),
3692                                 pname ? pname : '???',
3693                                 pbarcode ? pbarcode : '???',
3694                                 ibarcode ? ibarcode : '???'
3695                             ]
3696                         ), {
3697                             'au_id' : p_id,
3698                             'au_family_name' : pname,
3699                             'au_barcode' : pbarcode,
3700                             'acp_barcode' : ibarcode
3701                         }
3702                     );
3703                 } catch(E) {
3704                     error.sdump('D_ERROR','Error with work_logging in server/circ/util.js, renew_via_barcode():' + E);
3705                 }
3706                 if (typeof async == 'function') async(renew);
3707                 return renew;
3708             } catch(E) {
3709                 JSAN.use('util.error'); var error = new util.error();
3710                 error.standard_unexpected_error_alert(document.getElementById('circStrings').getFormattedString('staff.circ.checkin.renew_failed.error', [params.barcode]), E);
3711                 return null;
3712             }
3713         }
3714
3715         var renew = obj.network.simple_request(
3716             'CHECKOUT_RENEW',
3717             [ ses(), params ],
3718             async ? renew_callback : null,
3719             {
3720                 'title' : document.getElementById('circStrings').getString('staff.circ.checkin.renew_failed.override'),
3721                 'overridable_events' : [
3722                     null /* custom event */,
3723                     1212 /* PATRON_EXCEEDS_OVERDUE_COUNT */,
3724                     1213 /* PATRON_BARRED */,
3725                     1215 /* CIRC_EXCEEDS_COPY_RANGE */,
3726                     1232 /* ITEM_DEPOSIT_REQUIRED */,
3727                     1233 /* ITEM_RENTAL_FEE_REQUIRED */,
3728                     1234 /* ITEM_DEPOSIT_PAID */,
3729                     1236 /* PATRON_EXCEEDS_LOST_COUNT */,
3730                     7002 /* PATRON_EXCEEDS_CHECKOUT_COUNT */,
3731                     7003 /* COPY_CIRC_NOT_ALLOWED */,
3732                     7004 /* COPY_NOT_AVAILABLE */,
3733                     7006 /* COPY_IS_REFERENCE */,
3734                     7007 /* COPY_NEEDED_FOR_HOLD */,
3735                     7008 /* MAX_RENEWALS_REACHED */,
3736                     7009 /* CIRC_CLAIMS_RETURNED */,
3737                     7010 /* COPY_ALERT_MESSAGE */,
3738                     7013 /* PATRON_EXCEEDS_FINES */,
3739                 ],
3740                 'text' : {
3741                     '1212' : function(r) { return document.getElementById('circStrings').getFormattedString('staff.circ.renew.barcode', [params.barcode]); },
3742                     '1213' : function(r) { return document.getElementById('circStrings').getFormattedString('staff.circ.renew.barcode', [params.barcode]); },
3743                     '1215' : function(r) { return document.getElementById('circStrings').getFormattedString('staff.circ.renew.barcode', [params.barcode]); },
3744                     '1232' : function(r) {
3745                         return document.getElementById('circStrings').getFormattedString('staff.circ.renew.override.item_deposit_required.warning.barcode', [params.barcode]);
3746                     },
3747                     '1233' : function(r) {
3748                         return document.getElementById('circStrings').getFormattedString('staff.circ.renew.override.item_rental_fee_required.warning.barcode', [params.barcode]);
3749                     },
3750                     '1234' : function(r) {
3751                         return document.getElementById('circStrings').getFormattedString('staff.circ.utils.checkin.override.item_deposit_paid.warning');
3752                     },
3753                     '1236' : function(r) { return document.getElementById('circStrings').getFormattedString('staff.circ.renew.barcode', [params.barcode]); },
3754                     '7002' : function(r) { return document.getElementById('circStrings').getFormattedString('staff.circ.renew.barcode', [params.barcode]); },
3755                     '7003' : function(r) { return document.getElementById('circStrings').getFormattedString('staff.circ.renew.barcode', [params.barcode]); },
3756                     '7004' : function(r) {
3757                         return document.getElementById('circStrings').getFormattedString('staff.circ.renew.barcode.status', [params.barcode, typeof r.payload.status() == 'object' ? r.payload.status().name() : obj.data.hash.ccs[ r.payload.status() ].name()]);
3758                     },
3759                     '7006' : function(r) { return document.getElementById('circStrings').getFormattedString('staff.circ.renew.barcode', [params.barcode]); },
3760                     '7007' : function(r) { return document.getElementById('circStrings').getFormattedString('staff.circ.renew.barcode', [params.barcode]); },
3761                     '7008' : function(r) { return document.getElementById('circStrings').getFormattedString('staff.circ.renew.barcode', [params.barcode]); },
3762                     '7009' : function(r) { return document.getElementById('circStrings').getFormattedString('staff.circ.renew.barcode', [params.barcode]); },
3763                     '7010' : function(r) {
3764                         return document.getElementById('circStrings').getFormattedString('staff.circ.renew.barcode.msg', [params.barcode, r.payload]);
3765                     },
3766                     '7013' : function(r) { return document.getElementById('circStrings').getFormattedString('staff.circ.renew.barcode', [params.barcode]); }
3767                 }
3768             }
3769         );
3770         if (! async ) {
3771             return renew_callback( { 'getResultObject' : function() { return renew; } } );
3772         }
3773
3774     } catch(E) {
3775         JSAN.use('util.error'); var error = new util.error();
3776         error.standard_unexpected_error_alert(document.getElementById('circStrings').getFormattedString('staff.circ.checkin.renew_failed.error', [params.barcode]), E);
3777         return null;
3778     }
3779 };
3780
3781 circ.util.batch_hold_update = function ( hold_ids, field_changes, params ) {
3782     try {
3783         JSAN.use('util.sound'); var sound = new util.sound();
3784         var change_list = []; var idx = -1; var bad_holds = [];
3785         dojo.forEach(
3786             hold_ids,
3787             function(el) {
3788                 change_list.push( function(id,fc){ var clone = JSON2js(js2JSON(fc)); clone.id = id; return clone; }(el,field_changes) ); // Is there a better way to do this?
3789             }
3790         );
3791         if (params.progressmeter) { params.progressmeter.value = 0; params.progressmeter.hidden = false; }
3792         fieldmapper.standardRequest(
3793             [ api.FM_AHR_UPDATE_BATCH.app, api.FM_AHR_UPDATE_BATCH.method ],
3794             {   async: true,
3795                 params: [ses(), null, change_list],
3796                 onresponse: function(r) {
3797                     idx++; 
3798                     if (params.progressmeter) { params.progressmeter.value = Number( params.progressmeter.value ) + 100/hold_ids.length; }
3799                     var result = r.recv().content();
3800                     if (result != hold_ids[ idx ]) {
3801                         bad_holds.push( { 'hold_id' : hold_ids[ idx ], 'result' : result } );
3802                     }
3803                 },
3804                 oncomplete: function() {
3805                     if (bad_holds.length > 0) {
3806                         sound.circ_bad();
3807                         alert( $('circStrings').getFormattedString('staff.circ.hold_update.hold_ids.failed',[ bad_holds.length ]) );
3808                     } else {
3809                         sound.circ_good();
3810                     }
3811                     if (typeof params.oncomplete == 'function') {
3812                         params.oncomplete( bad_holds );
3813                     }
3814                     if (params.progressmeter) { params.progressmeter.value = 0; params.progressmeter.hidden = true; }
3815                 },
3816                 onerror: function(r) {
3817                     alert('Error in circ/util.js, batch_hold_update(), onerror: ' + r);
3818                 }
3819             }
3820         );
3821     } catch(E) {
3822         alert('Error in circ.util.js, circ.util.batch_hold_update(): ' + E);
3823     }
3824 };
3825
3826 circ.util.find_acq_po = function(session, copy_id) {
3827     dojo.require("openils.Util");
3828     fieldmapper.standardRequest(
3829         ["open-ils.acq", "open-ils.acq.lineitem.retrieve.by_copy_id.authoritative"], {
3830             "params": [session, copy_id, {"clear_marc": true}],
3831             "onresponse": function(r) {
3832                 if (r = openils.Util.readResponse(r)) {
3833                     if (r.purchase_order()) {
3834                         var url = urls.XUL_BROWSER + "?url=" +
3835                             window.encodeURIComponent(
3836                                 xulG.url_prefix('EG_ACQ_PO_VIEW/')
3837                                     + r.purchase_order() + "/" + r.id()
3838                             );
3839                         window.xulG.new_tab(
3840                             url, {"browser": true}, {
3841                                 "no_xulG": false,
3842                                 "show_print_button": false,
3843                                 "show_nav_buttons": true
3844                             }
3845                         );
3846                     } else {
3847                         /* unlikely: got an LI with no PO */
3848                         alert(dojo.byId("circStrings").getFormattedString(
3849                             "staff.circ.utils.find_acq_po.no_po", [r.id()]
3850                         ));
3851                     }
3852                 }
3853             }
3854         }
3855     );
3856 };
3857
3858
3859 function  sort_call_numbers_by_label_sortkey(my, scratch_data, result_label){
3860                                 var acn_id;
3861                 if (my.acn) {
3862                     if (typeof my.acn == 'object') {
3863                         acn_id = my.acn.id();
3864                     } else {
3865                         acn_id = my.acn;
3866                     }
3867                 } else if (my.acp) {
3868                     if (typeof my.acp.call_number() == 'object' && my.acp.call_number() != null) {
3869                         acn_id = my.acp.call_number().id();
3870                     } else {
3871                         acn_id = my.acp.call_number();
3872                     }
3873                 }
3874                 if (!acn_id && acn_id != 0) {
3875                     return '';
3876                 } else if (acn_id == -1) {
3877                     return document.getElementById('circStrings').getString('staff.circ.utils.not_cataloged');
3878                 } else if (acn_id == -2) {
3879                     return document.getElementById('circStrings').getString('staff.circ.utils.retrieving');
3880                 } else {
3881                     if (!my.acn) {
3882                         if (typeof scratch_data == 'undefined' || scratch_data == null) {
3883                             scratch_data = {};
3884                         }
3885                         if (typeof scratch_data['acn_map'] == 'undefined') {
3886                             scratch_data['acn_map'] = {};
3887                         }
3888                         if (typeof scratch_data['acn_map'][ acn_id ] == 'undefined') {
3889                             var x = network.simple_request("FM_ACN_RETRIEVE.authoritative",[ acn_id ]);
3890                             if (x.ilsevent) {
3891                                 return document.getElementById('circStrings').getString('staff.circ.utils.not_cataloged');
3892                             } else {
3893                                 my.acn = x;
3894                                 scratch_data['acn_map'][ acn_id ] = my.acn;
3895                             }
3896                         } else {
3897                             my.acn = scratch_data['acn_map'][ acn_id ];
3898                         }
3899                     }
3900                     
3901                     if(result_label == "label_sortkey"){
3902                                                 return my.acn.label_sortkey();
3903                                         }
3904                                         else if(result_label == "render_label"){
3905                                                 return my.acn.label();
3906                                         }
3907                 }
3908             }; 
3909
3910
3911 dump('exiting circ/util.js\n');