]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/xul/staff_client/server/circ/util.js
Start tackling circ/util.js i18n
[Evergreen.git] / Open-ILS / xul / staff_client / server / circ / util.js
1 dump('entering circ/util.js\n');
2 // vim:noet:sw=4:ts=4:
3
4 if (typeof circ == 'undefined') { var circ = {}; }
5 circ.util = {};
6
7 circ.util.EXPORT_OK     = [ 
8         'offline_checkout_columns', 'offline_checkin_columns', 'offline_renew_columns', 'offline_inhouse_use_columns', 
9         'columns', 'hold_columns', 'checkin_via_barcode', 'std_map_row_to_columns', 
10         'show_last_few_circs', 'abort_transits', 'transit_columns', 'renew_via_barcode'
11 ];
12 circ.util.EXPORT_TAGS   = { ':all' : circ.util.EXPORT_OK };
13
14 circ.util.abort_transits = function(selection_list) {
15         var obj = {};
16         JSAN.use('util.error'); obj.error = new util.error();
17         JSAN.use('util.network'); obj.network = new util.network();
18         JSAN.use('OpenILS.data'); obj.data = new OpenILS.data(); obj.data.init({'via':'stash'});
19         JSAN.use('util.functional');
20         var copies = util.functional.map_list( selection_list, function(o){return o.copy_id;}).join(', ');
21         var msg = document.getElementById('circStrings').getFormattedString('staff.circ.utils.abort_transits.confirm', [copies]);
22         var r = obj.error.yns_alert(
23                 msg,
24                 document.getElementById('circStrings').getString('staff.circ.utils.abort_transits.title'),
25                 document.getElementById('circStrings').getString('staff.circ.utils.yes'),
26                 document.getElementById('circStrings').getString('staff.circ.utils.no'),
27                 null,
28                 document.getElementById('circStrings').getString('staff.circ.confirm')
29         );
30         if (r == 0) {
31                 try {
32                         for (var i = 0; i < selection_list.length; i++) {
33                                 var copy_id = selection_list[i].copy_id;
34                                 var robj = obj.network.simple_request('FM_ATC_VOID',[ ses(), { 'copyid' : copy_id } ]);
35                                 if (typeof robj.ilsevent != 'undefined') {
36                                         switch(robj.ilsevent) {
37                                                 case 1225 /* TRANSIT_ABORT_NOT_ALLOWED */ :
38                                                         alert(document.getElementById('circString').getFormattedString('staff.circ.utils.abort_transits.not_allowed', [copy_id]) + '\n' + robj.desc);
39                                                 break;
40                                                 case 1504 /* ACTION_TRANSIT_COPY_NOT_FOUND */ :
41                                                         alert(document.getElementById('circString').getString('staff.circ.utils.abort_transits.not_found'));
42                                                 break;
43                                                 case 5000 /* PERM_FAILURE */ :
44                                                 break;
45                                                 default:
46                                                         throw(robj);
47                                                 break;
48                                         }
49                                 }
50                         }
51                 } catch(E) {
52                         obj.error.standard_unexpected_error_alert(document.getElementById('circString').getString('staff.circ.utils.abort_transits.unexpected_error'),E);
53                 }
54         }
55 }
56
57 circ.util.show_copy_details = function(copy_id) {
58         var obj = {};
59         JSAN.use('util.error'); obj.error = new util.error();
60         JSAN.use('util.window'); obj.win = new util.window();
61         JSAN.use('util.network'); obj.network = new util.network();
62         JSAN.use('OpenILS.data'); obj.data = new OpenILS.data(); obj.data.init({'via':'stash'});
63
64         if (typeof copy_id == 'object' && copy_id != null) copy_id = copy_id.id();
65
66         try {
67                 var url = xulG.url_prefix( urls.XUL_COPY_DETAILS ); // + '?copy_id=' + copy_id;
68                 var my_xulG = obj.win.open( url, 'show_copy_details', 'chrome,resizable,modal', { 'copy_id' : copy_id } );
69
70                 if (typeof my_xulG.retrieve_these_patrons == 'undefined') return;
71                 var patrons = my_xulG.retrieve_these_patrons;
72                 for (var j = 0; j < patrons.length; j++) {
73                         if (typeof window.xulG == 'object' && typeof window.xulG.new_tab == 'function') {
74                                 try {
75                                         var url = urls.XUL_PATRON_DISPLAY; // + '?id=' + window.escape( patrons[j] );
76                                         window.xulG.new_tab( url, {}, { 'id' : patrons[j] } );
77                                 } catch(E) {
78                                         obj.error.standard_unexpected_error_alert(document.getElementById('circStrings').getString('staff.circ.utils.retrieve_patron.failure'), E);
79                                 }
80                         }
81                 }
82
83         } catch(E) {
84                 obj.error.standard_unexpected_error_alert(document.getElementById('circStrings').getString('staff.circ.utils.retrieve_copy.failure'),E);
85         }
86 }
87
88
89 circ.util.show_last_few_circs = function(selection_list,count) {
90         var obj = {};
91         JSAN.use('util.error'); obj.error = new util.error();
92         JSAN.use('util.window'); obj.win = new util.window();
93         JSAN.use('util.network'); obj.network = new util.network();
94         JSAN.use('OpenILS.data'); obj.data = new OpenILS.data(); obj.data.init({'via':'stash'});
95
96         if (!count) count = 4;
97
98         for (var i = 0; i < selection_list.length; i++) {
99                 try {
100                         if (typeof selection_list[i].copy_id == 'undefined' || selection_list[i].copy_id == null) continue;
101                         var url = xulG.url_prefix( urls.XUL_CIRC_SUMMARY ); // + '?copy_id=' + selection_list[i].copy_id + '&count=' + count;
102                         var my_xulG = obj.win.open( url, 'show_last_few_circs', 'chrome,resizable,modal', { 'copy_id' : selection_list[i].copy_id, 'count' : count } );
103
104                         if (typeof my_xulG.retrieve_these_patrons == 'undefined') continue;
105                         var patrons = my_xulG.retrieve_these_patrons;
106                         for (var j = 0; j < patrons.length; j++) {
107                                 if (typeof window.xulG == 'object' && typeof window.xulG.new_tab == 'function') {
108                                         try {
109                                                 var url = urls.XUL_PATRON_DISPLAY; // + '?id=' + window.escape( patrons[j] );
110                                                 window.xulG.new_tab( url, {}, { 'id' : patrons[j] } );
111                                         } catch(E) {
112                                                 obj.error.standard_unexpected_error_alert(document.getElementById('circStrings').getString('staff.circ.utils.retrieve_patron.failure') ,E);
113                                         }
114                                 }
115                         }
116
117                 } catch(E) {
118                         obj.error.standard_unexpected_error_alert(document.getElementById('circStrings').getString('staff.circ.utils.retrieve_circs.failure') ,E);
119                 }
120         }
121 }
122
123 circ.util.offline_checkout_columns = function(modify,params) {
124         
125         var c = [
126                 { 
127                         'id' : 'timestamp', 
128                         'label' : document.getElementById('circStrings').getString('staff.circ.utils.offline.timestamp'),
129                         'flex' : 1, 'primary' : false, 'hidden' : true, 
130                         'render' : function(my) { return my.timestamp; },
131                 },
132                 { 
133                         'id' : 'checkout_time', 
134                         'label' : document.getElementById('circStrings').getString('staff.circ.utils.offline.checkout_time'), 
135                         'flex' : 1, 'primary' : false, 'hidden' : true, 
136                         'render' : function(my) { return my.checkout_time; },
137                 },
138                 { 
139                         'id' : 'type', 
140                         'label' : document.getElementById('circStrings').getString('staff.circ.utils.offline.type'),
141                         'flex' : 1, 'primary' : false, 'hidden' : true, 
142                         'render' : function(my) { return my.type; }, 
143                 },
144                 {
145                         'id' : 'noncat',
146                         'label' : document.getElementById('circStrings').getString('staff.circ.utils.offline.noncat'),
147                         'flex' : 1, 'primary' : false, 'hidden' : true, 
148                         'render' : function(my) { return my.noncat; },
149                 },
150                 {
151                         'id' : 'noncat_type',
152                         'label' : document.getElementById('circStrings').getString('staff.circ.utils.offline.noncat_type'),
153                         'flex' : 1, 'primary' : false, 'hidden' : true,
154                         'render' : function(my) { return my.noncat_type; },
155                 },
156                 {
157                         'id' : 'noncat_count',
158                         'label' : document.getElementById('circStrings').getString('staff.circ.utils.offline.count'),
159                         'sort_type' : 'number',
160                         'flex' : 1, 'primary' : false, 'hidden' : false,
161                         'render' : function(my) { return my.noncat_count; },
162                 },
163                 { 
164                         'id' : 'patron_barcode', 
165                         'label' : document.getElementById('circStrings').getString('staff.circ.utils.offline.patron_barcode'), 
166                         'flex' : 1, 'primary' : false, 'hidden' : true, 
167                         'render' : function(my) { return my.patron_barcode; },
168                 },
169                 { 
170                         'id' : 'barcode', 
171                         'label' : document.getElementById('circStrings').getString('staff.circ.utils.offline.item_barcode'),
172                         'flex' : 2, 'primary' : true, 'hidden' : false, 
173                         'render' : function(my) { return my.barcode; },
174                 },
175                 { 
176                         'id' : 'due_date', 
177                         'label' : document.getElementById('circStrings').getString('staff.circ.utils.offline.due_date'),
178                         'flex' : 1, 'primary' : false, 'hidden' : false, 
179                         'render' : function(my) { return my.due_date; },
180                 },
181         ];
182         if (modify) for (var i = 0; i < c.length; i++) {
183                 if (modify[ c[i].id ]) {
184                         for (var j in modify[ c[i].id ]) {
185                                 c[i][j] = modify[ c[i].id ][j];
186                         }
187                 }
188         }
189         if (params) {
190                 if (params.just_these) {
191                         JSAN.use('util.functional');
192                         var new_c = [];
193                         for (var i = 0; i < params.just_these.length; i++) {
194                                 var x = util.functional.find_list(c,function(d){return(d.id==params.just_these[i]);});
195                                 new_c.push( function(y){ return y; }( x ) );
196                         }
197                         c = new_c;
198                 }
199                 if (params.except_these) {
200                         JSAN.use('util.functional');
201                         var new_c = [];
202                         for (var i = 0; i < c.length; i++) {
203                                 var x = util.functional.find_list(params.except_these,function(d){return(d==c[i].id);});
204                                 if (!x) new_c.push(c[i]);
205                         }
206                         c = new_c;
207                 }
208
209         }
210         return c.sort( function(a,b) { if (a.label < b.label) return -1; if (a.label > b.label) return 1; return 0; } );
211 }
212
213 circ.util.offline_checkin_columns = function(modify,params) {
214         
215         var c = [
216                 { 
217                         'id' : 'timestamp', 
218                         'label' : document.getElementById('circStrings').getString('staff.circ.utils.offline.timestamp'),
219                         'flex' : 1, 'primary' : false, 'hidden' : true, 
220                         'render' : function(my) { return my.timestamp; },
221                 },
222                 { 
223                         'id' : 'backdate', 
224                         'label' : document.getElementById('circStrings').getString('staff.circ.utils.offline.backdate'),
225                         'flex' : 1, 'primary' : false, 'hidden' : true, 
226                         'render' : function(my) { return my.backdate; },
227                 },
228                 { 
229                         'id' : 'type', 
230                         'label' : document.getElementById('circStrings').getString('staff.circ.utils.offline.type'),
231                         'flex' : 1, 'primary' : false, 'hidden' : true, 
232                         'render' : function(my) { return my.type; },
233                 },
234                 { 
235                         'id' : 'barcode', 
236                         'label' : document.getElementById('circStrings').getString('staff.circ.utils.offline.item_barcode'),
237                         'flex' : 2, 'primary' : true, 'hidden' : false, 
238                         'render' : function(my) { return my.barcode; },
239                 },
240         ];
241         if (modify) for (var i = 0; i < c.length; i++) {
242                 if (modify[ c[i].id ]) {
243                         for (var j in modify[ c[i].id ]) {
244                                 c[i][j] = modify[ c[i].id ][j];
245                         }
246                 }
247         }
248         if (params) {
249                 if (params.just_these) {
250                         JSAN.use('util.functional');
251                         var new_c = [];
252                         for (var i = 0; i < params.just_these.length; i++) {
253                                 var x = util.functional.find_list(c,function(d){return(d.id==params.just_these[i]);});
254                                 new_c.push( function(y){ return y; }( x ) );
255                         }
256                         c = new_c;
257                 }
258                 if (params.except_these) {
259                         JSAN.use('util.functional');
260                         var new_c = [];
261                         for (var i = 0; i < c.length; i++) {
262                                 var x = util.functional.find_list(params.except_these,function(d){return(d==c[i].id);});
263                                 if (!x) new_c.push(c[i]);
264                         }
265                         c = new_c;
266                 }
267
268         }
269         return c.sort( function(a,b) { if (a.label < b.label) return -1; if (a.label > b.label) return 1; return 0; } );
270 }
271
272 circ.util.offline_renew_columns = function(modify,params) {
273         
274         var c = [
275                 { 
276                         'id' : 'timestamp', 
277                         'label' : document.getElementById('circStrings').getString('staff.circ.utils.offline.timestamp'),
278                         'flex' : 1, 'primary' : false, 'hidden' : true, 
279                         'render' : function(my) { return my.timestamp; },
280                 },
281                 { 
282                         'id' : 'checkout_time', 
283                         'label' : document.getElementById('circStrings').getString('staff.circ.utils.offline.checkout_time'),
284                         'flex' : 1, 'primary' : false, 'hidden' : true, 
285                         'render' : function(my) { return my.checkout_time; },
286                 },
287                 { 
288                         'id' : 'type', 
289                         'label' : document.getElementById('circStrings').getString('staff.circ.utils.offline.type'),
290                         'flex' : 1, 'primary' : false, 'hidden' : true, 
291                         'render' : function(my) { return my.type; },
292                 },
293                 { 
294                         'id' : 'patron_barcode', 
295                         'label' : document.getElementById('circStrings').getString('staff.circ.utils.offline.patron_barcode'),
296                         'flex' : 1, 'primary' : false, 'hidden' : true, 
297                         'render' : function(my) { return my.patron_barcode; },
298                 },
299                 { 
300                         'id' : 'barcode', 
301                         'label' : document.getElementById('circStrings').getString('staff.circ.utils.offline.item_barcode'),
302                         'flex' : 2, 'primary' : true, 'hidden' : false, 
303                         'render' : function(my) { return my.barcode; },
304                 },
305                 { 
306                         'id' : 'due_date', 
307                         'label' : document.getElementById('circStrings').getString('staff.circ.utils.offline.due_date'), 
308                         'flex' : 1, 'primary' : false, 'hidden' : false, 
309                         'render' : function(my) { return my.due_date; },
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_inhouse_use_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, 'primary' : false, 'hidden' : true, 
350                         'render' : function(my) { return my.timestamp; },
351                 },
352                 { 
353                         'id' : 'use_time', 
354                         'label' : document.getElementById('circStrings').getString('staff.circ.utils.offline.use_time'), 
355                         'flex' : 1, 'primary' : false, 'hidden' : true, 
356                         'render' : function(my) { return my.use_time; },
357                 },
358                 { 
359                         'id' : 'type', 
360                         'label' : document.getElementById('circStrings').getString('staff.circ.utils.offline.type'),
361                         'flex' : 1, 'primary' : false, 'hidden' : true, 
362                         'render' : function(my) { return my.type; },
363                 },
364                 {
365                         'id' : 'count',
366                         'label' : document.getElementById('circStrings').getString('staff.circ.utils.offline.count'),
367                         'sort_type' : 'number',
368                         'flex' : 1, 'primary' : false, 'hidden' : false,
369                         'render' : function(my) { return my.count; },
370                 },
371                 { 
372                         'id' : 'barcode', 
373                         'label' : document.getElementById('circStrings').getString('staff.circ.utils.offline.item_barcode'),
374                         'flex' : 2, 'primary' : true, 'hidden' : false, 
375                         'render' : function(my) { return my.barcode; },
376                 },
377         ];
378         if (modify) for (var i = 0; i < c.length; i++) {
379                 if (modify[ c[i].id ]) {
380                         for (var j in modify[ c[i].id ]) {
381                                 c[i][j] = modify[ c[i].id ][j];
382                         }
383                 }
384         }
385         if (params) {
386                 if (params.just_these) {
387                         JSAN.use('util.functional');
388                         var new_c = [];
389                         for (var i = 0; i < params.just_these.length; i++) {
390                                 var x = util.functional.find_list(c,function(d){return(d.id==params.just_these[i]);});
391                                 new_c.push( function(y){ return y; }( x ) );
392                         }
393                         c = new_c;
394                 }
395                 if (params.except_these) {
396                         JSAN.use('util.functional');
397                         var new_c = [];
398                         for (var i = 0; i < c.length; i++) {
399                                 var x = util.functional.find_list(params.except_these,function(d){return(d==c[i].id);});
400                                 if (!x) new_c.push(c[i]);
401                         }
402                         c = new_c;
403                 }
404
405         }
406         return c.sort( function(a,b) { if (a.label < b.label) return -1; if (a.label > b.label) return 1; return 0; } );
407 }
408
409
410
411 circ.util.columns = function(modify,params) {
412         
413         JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.init({'via':'stash'});
414         JSAN.use('util.network'); var network = new util.network();
415         JSAN.use('util.money');
416
417         var c = [
418                 {
419                         'id' : 'acp_id', 'label' : document.getElementById('commonStrings').getString('staff.acp_label_id'), 'flex' : 1,
420                         'primary' : false, 'hidden' : true, 'render' : function(my) { return my.acp.id(); }, 'persist' : 'hidden width ordinal',
421                 },
422                 {
423                         'id' : 'circ_id', 'label' : document.getElementById('commonStrings').getString('staff.circ_label_id'), 'flex' : 1,
424                         'primary' : false, 'hidden' : true, 'render' : function(my) { return my.circ ? my.circ.id() : ( my.acp.circulations() ? my.acp.circulations()[0].id() : ""); },
425                         'persist' : 'hidden width ordinal',
426                 },
427                 {
428                         'id' : 'mvr_doc_id', 'label' : document.getElementById('commonStrings').getString('staff.mvr_label_doc_id'), 'flex' : 1,
429                         'primary' : false, 'hidden' : true, 'render' : function(my) { return my.mvr.doc_id(); },
430                         'persist' : 'hidden width ordinal',
431                 },
432         {
433                         'persist' : 'hidden width ordinal', 'id' : 'service', 'label' : 'Service', 'flex' : 1,
434                         'primary' : false, 'hidden' : true, 'render' : function(my) { return my.service; },
435         },
436                 {
437                         'id' : 'barcode', 'label' : document.getElementById('commonStrings').getString('staff.acp_label_barcode'), 'flex' : 1,
438                         'primary' : false, 'hidden' : true, 'render' : function(my) { return my.acp.barcode(); },
439                         'persist' : 'hidden width ordinal',
440                 },
441                 {
442                         'id' : 'call_number',
443                         'label' : document.getElementById('commonStrings').getString('staff.acp_label_call_number'),
444                         'flex' : 1,
445                         'primary' : false, 'hidden' : true,
446                         'render' : function(my) {
447                                 if (my.acp && my.acp.call_number() == -1) {
448                                         return document.getElementById('commonStrings').getString('staff.circ.utils.not_cataloged');
449                                 } else {
450                                         if (!my.acn) {
451                                                 var x = network.simple_request("FM_ACN_RETRIEVE",[ my.acp.call_number() ]);
452                                                 if (x.ilsevent) {
453                                                         return document.getElementById('commonStrings').getString('staff.circ.utils.not_cataloged');
454                                                 } else {
455                                                         my.acn = x; return x.label();
456                                                 }
457                                         } else {
458                                                 return my.acn.label();
459                                         }
460                                 }
461                         },
462                         'persist' : 'hidden width ordinal',
463                 },
464                 {
465                         'id' : 'owning_lib',
466                         'label' : document.getElementById('commonStrings').getString('staff.circ.utils.owning_lib'),
467                         'flex' : 1,
468                         'primary' : false, 'hidden' : true,
469                         'render' : function(my) {
470                                 if (Number(my.acn.owning_lib())>=0) {
471                                         return data.hash.aou[ my.acn.owning_lib() ].shortname();
472                                 } else {
473                                         return my.acn.owning_lib().shortname();
474                                 }
475                         }, 
476                         'persist' : 'hidden width ordinal',
477                 },
478                 {
479                         'id' : 'copy_number',
480                         'label' : document.getElementById('commonStrings').getString('staff.acp_label_copy_number'),
481                         'flex' : 1,
482                         'sort_type' : 'number',
483                         'primary' : false, 'hidden' : true, 'render' : function(my) { return my.acp.copy_number(); },
484                         'persist' : 'hidden width ordinal',
485                 },
486                 {
487                         'id' : 'location',
488                         'label' : document.getElementById('commonStrings').getString('staff.acp_label_location'),
489                         'flex' : 1,
490                         'primary' : false, 'hidden' : true,
491                         'render' : function(my) {
492                                 if (Number(my.acp.location())>=0) {
493                                         return data.lookup("acpl", my.acp.location() ).name();
494                                 } else {
495                                         return my.acp.location().name();
496                                 }
497                         },
498                         'persist' : 'hidden width ordinal',
499                 },
500                 {
501                         'id' : 'loan_duration',
502                         'label' : document.getElementById('commonStrings').getString('staff.acp_label_loan_duration'),
503                         'flex' : 1,
504                         'primary' : false, 'hidden' : true, 
505                         'render' : function(my) {
506                                 switch(my.acp.loan_duration()) {
507                                         case 1:
508                                                 return document.getElementById('circStrings').getString('staff.circ.utils.loan_duration.short');
509                                                 break;
510                                         case 2:
511                                                 return document.getElementById('circStrings').getString('staff.circ.utils.loan_duration.normal');
512                                                 break;
513                                         case 3:
514                                                 return document.getElementById('circStrings').getString('staff.circ.utils.loan_duration.long');
515                                                 break;
516                                 };
517                         },
518                         'persist' : 'hidden width ordinal',
519                 },
520                 {
521                         'id' : 'circ_lib',
522                         'label' : document.getElementById('commonStrings').getString('staff.acp_label_circ_lib'),
523                         'flex' : 1,
524                         'primary' : false, 'hidden' : true,
525                         'render' : function(my) {
526                                 if (Number(my.acp.circ_lib())>=0) {
527                                         return data.hash.aou[ my.acp.circ_lib() ].shortname();
528                                 } else {
529                                         return my.acp.circ_lib().shortname();
530                                 }
531                         },
532                         'persist' : 'hidden width ordinal',
533                 },
534                 {
535                         'id' : 'fine_level',
536                         'label' : document.getElementById('commonStrings').getString('staff.acp_label_fine_level'), 'flex' : 1,
537                         'primary' : false, 'hidden' : true,
538                         'render' : function(my) {
539                                 switch(my.acp.fine_level()) {
540                                         case 1:
541                                                 return document.getElementById('circStrings').getString('staff.circ.utils.fine_level.low');
542                                                 break;
543                                         case 2:
544                                                 return document.getElementById('circStrings').getString('staff.circ.utils.fine_level.normal');
545                                                 break;
546                                         case 3:
547                                                 return document.getElementById('circStrings').getString('staff.circ.utils.fine_level.high');
548                                                 break;
549                                 };
550                         },
551                         'persist' : 'hidden width ordinal',
552                 },
553                 {
554                         'id' : 'circulate',
555                         'label' : document.getElementById('circStrings').getString('staff.circ.utils.circulate'),
556                         'flex' : 1,
557                         'primary' : false, 'hidden' : true,
558                         'render' : function(my) {
559                                 if (get_bool( my.acp.circulate() )) {
560                                         return document.getElementById('circStrings').getString('staff.circ.utils.yes');
561                                 } else {
562                                         return document.getElementById('circStrings').getString('staff.circ.utils.no');
563                                 }
564                         },
565                         'persist' : 'hidden width ordinal',
566                 },
567                 {
568                         'id' : 'deleted',
569                         'label' : document.getElementById('circStrings').getString('staff.circ.utils.deleted'),
570                         'flex' : 1,
571                         'primary' : false, 'hidden' : true,
572                         'render' : function(my) {
573                                 if (get_bool( my.acp.deleted() )) {
574                                         return document.getElementById('circStrings').getString('staff.circ.utils.yes');
575                                 } else {
576                                         return document.getElementById('circStrings').getString('staff.circ.utils.no');
577                                 }
578                         },
579                         'persist' : 'hidden width ordinal',
580                 },
581                 {
582                         'id' : 'holdable',
583                         'label' : document.getElementById('circStrings').getString('staff.circ.utils.holdable'),
584                         'flex' : 1,
585                         'primary' : false, 'hidden' : true,
586                         'render' : function(my) {
587                                 if (get_bool( my.acp.holdable() )) {
588                                         return document.getElementById('circStrings').getString('staff.circ.utils.yes');
589                                 } else {
590                                         return document.getElementById('circStrings').getString('staff.circ.utils.no');
591                                 }
592                         },
593                         'persist' : 'hidden width ordinal',
594                 },
595                 {
596                         'id' : 'opac_visible',
597                         'label' : document.getElementById('circStrings').getString('staff.circ.utils.opac_visible'),
598                         'flex' : 1,
599                         'primary' : false, 'hidden' : true,
600                         'render' : function(my) {
601                                 if (get_bool( my.acp.opac_visible() )) {
602                                         return document.getElementById('circStrings').getString('staff.circ.utils.yes');
603                                 } else {
604                                         return document.getElementById('circStrings').getString('staff.circ.utils.no');
605                                 }
606                         },
607                         'persist' : 'hidden width ordinal',
608                 },
609                 {
610                         'persist' : 'hidden width ordinal', 'id' : 'ref', 'label' : 'Reference?', 'flex' : 1,
611                         'primary' : false, 'hidden' : true, 'render' : function(my) { return get_bool( my.acp.ref() ) ? "Yes" : "No"; },
612                 },
613                 {
614                         'persist' : 'hidden width ordinal', 'id' : 'deposit', 'label' : 'Deposit?', 'flex' : 1,
615                         'primary' : false, 'hidden' : true, 'render' : function(my) { return get_bool( my.acp.deposit() ) ? "Yes" : "No"; },
616                 },
617                 {
618                         'persist' : 'hidden width ordinal', 'id' : 'deposit_amount', 'label' : document.getElementById('commonStrings').getString('staff.acp_label_deposit_amount'), 'flex' : 1,
619                         'primary' : false, 'hidden' : true, 'render' : function(my) { return my.acp.price() == null ? "<Unset>" : util.money.sanitize(my.acp.deposit_amount()); }, 'sort_type' : 'money',
620                 },
621                 {
622                         'persist' : 'hidden width ordinal', 'id' : 'price', 'label' : document.getElementById('commonStrings').getString('staff.acp_label_price'), 'flex' : 1,
623                         'primary' : false, 'hidden' : true, 'render' : function(my) { return my.acp.price() == null ? "<Unset>" : util.money.sanitize(my.acp.price()); }, 'sort_type' : 'money',
624                 },
625                 {
626                         'persist' : 'hidden width ordinal', 'id' : 'circ_as_type', 'label' : document.getElementById('commonStrings').getString('staff.acp_label_circ_as_type'), 'flex' : 1,
627                         'primary' : false, 'hidden' : true, 'render' : function(my) { return my.acp.circ_as_type(); },
628                 },
629                 {
630                         'persist' : 'hidden width ordinal', 'id' : 'circ_modifier', 'label' : document.getElementById('commonStrings').getString('staff.acp_label_circ_modifier'), 'flex' : 1,
631                         'primary' : false, 'hidden' : true, 'render' : function(my) { return my.acp.circ_modifier(); },
632                 },
633                 {
634                         'persist' : 'hidden width ordinal', 'id' : 'checkout_lib', 'label' : 'Checkout Lib', 'flex' : 1,
635                         'primary' : false, 'hidden' : true, 'render' : function(my) { return my.circ ? data.hash.aou[ my.circ.circ_lib() ].shortname() : ( my.acp.circulations() ? data.hash.aou[ my.acp.circulations()[0].circ_lib() ].shortname() : ""); },
636                 },
637                 {
638                         'persist' : 'hidden width ordinal', 'id' : 'xact_start_full', 'label' : 'Checkout Timestamp', 'flex' : 1,
639                         'primary' : false, 'hidden' : true, 'render' : function(my) { return my.circ ? my.circ.xact_start() : (my.acp.circulations() ? my.acp.circulations()[0].xact_start() : ""); },
640                 },
641                 {
642                         'persist' : 'hidden width ordinal', 'id' : 'checkin_time_full', 'label' : 'Checkin Timestamp', 'flex' : 1,
643                         'primary' : false, 'hidden' : true, 'render' : function(my) { return my.circ ? my.circ.checkin_time() : (my.acp.circulations() ? my.acp.circulations()[0].checkin_time() : ""); },
644                 },
645                 {
646                         'persist' : 'hidden width ordinal', 'id' : 'xact_start', 'label' : 'Checkout Date', 'flex' : 1,
647                         'primary' : false, 'hidden' : true, 'render' : function(my) { return my.circ ? my.circ.xact_start().substr(0,10) : (my.acp.circulations() ? my.acp.circulations()[0].xact_start().substr(0,10) : ""); },
648                 },
649                 {
650                         'persist' : 'hidden width ordinal', 'id' : 'checkin_time', 'label' : 'Checkin Date', 'flex' : 1,
651                         'primary' : false, 'hidden' : true, 'render' : function(my) { return my.circ ? my.circ.checkin_time().substr(0,10) : (my.acp.circulations() ? my.acp.circulations()[0].checkin_time().substr(0,10) : ""); },
652                 },
653
654                 {
655                         'persist' : 'hidden width ordinal', 'id' : 'xact_finish', 'label' : 'Transaction Finished', 'flex' : 1,
656                         'primary' : false, 'hidden' : true, 'render' : function(my) { return my.circ.xact_finish(); },
657                 },
658                 {
659                         'persist' : 'hidden width ordinal', 'id' : 'due_date', 'label' : document.getElementById('commonStrings').getString('staff.circ_label_due_date'), 'flex' : 1,
660                         'primary' : false, 'hidden' : true, 'render' : function(my) { return my.circ ? my.circ.due_date().substr(0,10) : (my.acp.circulations() ? my.acp.circulations()[0].due_date().substr(0,10) : ""); },
661                 },
662                 {
663                         'persist' : 'hidden width ordinal', 'id' : 'create_date', 'label' : 'Date Created', 'flex' : 1,
664                         'primary' : false, 'hidden' : true, 'render' : function(my) { return my.acp.create_date().substr(0,10); },
665                 },
666                 {
667                         'persist' : 'hidden width ordinal', 'id' : 'edit_date', 'label' : 'Date Last Edited', 'flex' : 1,
668                         'primary' : false, 'hidden' : true, 'render' : function(my) { return my.acp.edit_date().substr(0,10); },
669                 },
670                 {
671                         'persist' : 'hidden width ordinal', 'id' : 'title', 'label' : document.getElementById('commonStrings').getString('staff.mvr_label_title'), 'flex' : 2, 'sort_type' : 'title',
672                         'primary' : false, 'hidden' : true, 'render' : function(my) { try {  return my.mvr.title(); } catch(E) { return my.acp.dummy_title(); } }
673                 },
674                 {
675                         'persist' : 'hidden width ordinal', 'id' : 'author', 'label' : document.getElementById('commonStrings').getString('staff.mvr_label_author'), 'flex' : 1,
676                         'primary' : false, 'hidden' : true, 'render' : function(my) { try { return my.mvr.author(); } catch(E) { return my.acp.dummy_author(); } }
677                 },
678                 {
679                         'persist' : 'hidden width ordinal', 'id' : 'edition', 'label' : 'Edition', 'flex' : 1,
680                         'primary' : false, 'hidden' : true, 'render' : function(my) { return my.mvr.edition(); },
681                 },
682                 {
683                         'persist' : 'hidden width ordinal', 'id' : 'isbn', 'label' : 'ISBN', 'flex' : 1,
684                         'primary' : false, 'hidden' : true, 'render' : function(my) { return my.mvr.isbn(); },
685                 },
686                 {
687                         'persist' : 'hidden width ordinal', 'id' : 'pubdate', 'label' : 'PubDate', 'flex' : 1,
688                         'primary' : false, 'hidden' : true, 'render' : function(my) { return my.mvr.pubdate(); },
689                 },
690                 {
691                         'persist' : 'hidden width ordinal', 'id' : 'publisher', 'label' : 'Publisher', 'flex' : 1,
692                         'primary' : false, 'hidden' : true, 'render' : function(my) { return my.mvr.publisher(); },
693                 },
694                 {
695                         'persist' : 'hidden width ordinal', 'id' : 'tcn', 'label' : 'TCN', 'flex' : 1,
696                         'primary' : false, 'hidden' : true, 'render' : function(my) { return my.mvr.tcn(); },
697                 },
698                 {
699                         'persist' : 'hidden width ordinal', 'id' : 'renewal_remaining', 'label' : document.getElementById('commonStrings').getString('staff.circ_label_renewal_remaining'), 'flex' : 0,
700                         'primary' : false, 'hidden' : true, 'render' : function(my) { return my.circ ? my.circ.renewal_remaining() : (my.acp.circulations() ? my.acp.circulations()[0].renewal_remaining() : ""); }, 'sort_type' : 'number',
701                 },
702                 {
703                         'persist' : 'hidden width ordinal', 'id' : 'stop_fines', 'label' : 'Fines Stopped', 'flex' : 0,
704                         'primary' : false, 'hidden' : true, 'render' : function(my) { return my.circ ? my.circ.stop_fines() : (my.acp.circulations() ? my.acp.circulations()[0].stop_fines() : ""); },
705                 },
706                 {
707                         'persist' : 'hidden width ordinal', 'id' : 'stop_fines_time', 'label' : 'Fines Stopped Time', 'flex' : 0,
708                         'primary' : false, 'hidden' : true, 'render' : function(my) { return my.circ ? my.circ.stop_fines_time() : (my.acp.circulations() ? my.acp.circulations()[0].stop_fines_time() : ""); },
709                 },
710                 {
711                         'persist' : 'hidden width ordinal', 'id' : 'status', 'label' : document.getElementById('commonStrings').getString('staff.acp_label_status'), 'flex' : 1,
712                         'primary' : false, 'hidden' : true, 'render' : function(my) { if (Number(my.acp.status())>=0) return data.hash.ccs[ my.acp.status() ].name(); else return my.acp.status().name(); },
713                 },
714                 {
715                         'persist' : 'hidden width ordinal', 'id' : 'route_to', 'label' : 'Route To', 'flex' : 1,
716                         'primary' : false, 'hidden' : true, 'render' : function(my) { return my.route_to.toString(); },
717                 },
718                 {
719                         'persist' : 'hidden width ordinal', 'id' : 'message', 'label' : 'Message', 'flex' : 1,
720                         'primary' : false, 'hidden' : true, 'render' : function(my) { return my.message.toString(); },
721                 },
722                 {
723                         'persist' : 'hidden width ordinal', 'id' : 'uses', 'label' : '# of Uses', 'flex' : 1,
724                         'primary' : false, 'hidden' : true, 'render' : function(my) { return my.uses; }, 'sort_type' : 'number',
725                 },
726                 {
727                         'persist' : 'hidden width ordinal', 'id' : 'alert_message', 'label' : 'Alert Message', 'flex' : 1,
728                         'primary' : false, 'hidden' : true, 'render' : function(my) { return my.acp.alert_message(); },
729                 }
730         ];
731         for (var i = 0; i < c.length; i++) {
732                 if (modify[ c[i].id ]) {
733                         for (var j in modify[ c[i].id ]) {
734                                 c[i][j] = modify[ c[i].id ][j];
735                         }
736                 }
737         }
738         if (params) {
739                 if (params.just_these) {
740                         JSAN.use('util.functional');
741                         var new_c = [];
742                         for (var i = 0; i < params.just_these.length; i++) {
743                                 var x = util.functional.find_list(c,function(d){return(d.id==params.just_these[i]);});
744                                 new_c.push( function(y){ return y; }( x ) );
745                         }
746                         c = new_c;
747                 }
748                 if (params.except_these) {
749                         JSAN.use('util.functional');
750                         var new_c = [];
751                         for (var i = 0; i < c.length; i++) {
752                                 var x = util.functional.find_list(params.except_these,function(d){return(d==c[i].id);});
753                                 if (!x) new_c.push(c[i]);
754                         }
755                         c = new_c;
756                 }
757         }
758         return c.sort( function(a,b) { if (a.label < b.label) return -1; if (a.label > b.label) return 1; return 0; } );
759 }
760
761 circ.util.transit_columns = function(modify,params) {
762         
763         JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.init({'via':'stash'});
764
765         var c = [
766                 {
767                         'persist' : 'hidden width ordinal', 'id' : 'transit_item_barcode', 'label' : 'Barcode', 'flex' : 1,
768                         'primary' : false, 'hidden' : true,  'render' : function(my) { return my.acp.barcode(); },
769                 },
770                 {
771                         'persist' : 'hidden width ordinal', 'id' : 'transit_item_title', 'label' : 'Title', 'flex' : 1,
772                         'primary' : false, 'hidden' : true,  'render' : function(my) { try { return my.mvr.title(); } catch(E) { return my.acp.dummy_title(); } },
773                 },
774                 {
775                         'persist' : 'hidden width ordinal', 'id' : 'transit_item_author', 'label' : 'Author', 'flex' : 1,
776                         'primary' : false, 'hidden' : true,  'render' : function(my) { try { return my.mvr.author(); } catch(E) { return my.acp.dummy_author(); } },
777                 },
778                 {
779                         'persist' : 'hidden width ordinal', 'id' : 'transit_item_callnumber', 'label' : 'Call Number', 'flex' : 1,
780                         'primary' : false, 'hidden' : true,  'render' : function(my) { return my.acn.label(); },
781                 },
782                 {
783                         'persist' : 'hidden width ordinal', 'id' : 'transit_id', 'label' : 'Transit ID', 'flex' : 1,
784                         'primary' : false, 'hidden' : true,  'render' : function(my) { return my.atc.id(); },
785                 },
786                 {
787                         'persist' : 'hidden width ordinal', 'id' : 'transit_source', 'label' : 'Transit Source', 'flex' : 1,
788                         'primary' : false, 'hidden' : false, 'render' : function(my) { return typeof my.atc.source() == "object" ? my.atc.source().shortname() : data.hash.aou[ my.atc.source() ].shortname(); },
789                 },
790                 {
791                         'persist' : 'hidden width ordinal', 'id' : 'transit_source_send_time', 'label' : 'Transitted On', 'flex' : 1,
792                         'primary' : false, 'hidden' : false, 'render' : function(my) { return my.atc.source_send_time(); },
793                 },
794                 {
795                         'persist' : 'hidden width ordinal', 'id' : 'transit_dest_lib', 'label' : 'Transit Destination', 'flex' : 1,
796                         'primary' : false, 'hidden' : false, 'render' : function(my) { return typeof my.atc.dest() == "object" ? my.atc.dest().shortname() : data.hash.aou[ my.atc.dest() ].shortname(); },
797                 },
798                 {
799                         'persist' : 'hidden width ordinal', 'id' : 'transit_dest_recv_time', 'label' : 'Transit Completed On', 'flex' : 1,
800                         'primary' : false, 'hidden' : false, 'render' : function(my) { return my.atc.dest_recv_time(); },
801                 },
802                 {
803                         'persist' : 'hidden width ordinal', 'id' : 'transit_target_copy', 'label' : 'Transit Copy ID', 'flex' : 1,
804                         'primary' : false, 'hidden' : true, 'render' : function(my) { return my.atc.target_copy(); },
805                 },
806         ];
807         for (var i = 0; i < c.length; i++) {
808                 if (modify[ c[i].id ]) {
809                         for (var j in modify[ c[i].id ]) {
810                                 c[i][j] = modify[ c[i].id ][j];
811                         }
812                 }
813         }
814         if (params) {
815                 if (params.just_these) {
816                         JSAN.use('util.functional');
817                         var new_c = [];
818                         for (var i = 0; i < params.just_these.length; i++) {
819                                 var x = util.functional.find_list(c,function(d){return(d.id==params.just_these[i]);});
820                                 new_c.push( function(y){ return y; }( x ) );
821                         }
822                         c = new_c;
823                 }
824                 if (params.except_these) {
825                         JSAN.use('util.functional');
826                         var new_c = [];
827                         for (var i = 0; i < c.length; i++) {
828                                 var x = util.functional.find_list(params.except_these,function(d){return(d==c[i].id);});
829                                 if (!x) new_c.push(c[i]);
830                         }
831                         c = new_c;
832                 }
833
834         }
835         return c.sort( function(a,b) { if (a.label < b.label) return -1; if (a.label > b.label) return 1; return 0; } );
836 }
837
838
839 circ.util.hold_columns = function(modify,params) {
840         
841         JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.init({'via':'stash'});
842
843         var c = [
844                 {
845                         'persist' : 'hidden width ordinal', 'id' : 'request_lib', 'label' : 'Request Lib (Full Name)', 'flex' : 1,
846                         'primary' : false, 'hidden' : true,  
847                         'render' : function(my) { if (Number(my.ahr.request_lib())>=0) return data.hash.aou[ my.ahr.request_lib() ].name(); else return my.ahr.request_lib().name(); },
848                 },
849                 {
850                         'persist' : 'hidden width ordinal', 'id' : 'request_lib_shortname', 'label' : 'Request Lib', 'flex' : 0,
851                         'primary' : false, 'hidden' : true,  
852                         'render' : function(my) { if (Number(my.ahr.request_lib())>=0) return data.hash.aou[ my.ahr.request_lib() ].shortname(); else return my.ahr.request_lib().shortname(); },
853                 },
854
855                 {
856                         'persist' : 'hidden width ordinal', 'id' : 'request_timestamp', 'label' : 'Request Timestamp', 'flex' : 0,
857                         'primary' : false, 'hidden' : true,  
858                         'render' : function(my) { return my.ahr.request_time().toString(); },
859                 },
860                 {
861                         'persist' : 'hidden width ordinal', 'id' : 'request_time', 'label' : 'Request Date', 'flex' : 0,
862                         'primary' : false, 'hidden' : true,  
863                         'render' : function(my) { return my.ahr.request_time().toString().substr(0,10); },
864                 },
865                 {
866                         'persist' : 'hidden width ordinal', 'id' : 'available_timestamp', 'label' : 'Available On (Timestamp)', 'flex' : 1,
867                         'primary' : false, 'hidden' : true,  'render' : function(my) { return my.ahr.transit() ? ( my.ahr.transit().dest_recv_time() ? my.ahr.transit().dest_recv_time().toString() : "") : ( my.ahr.capture_time() ? my.ahr.capture_time().toString() : "" ); },
868                 },
869                 {
870                         'persist' : 'hidden width ordinal', 'id' : 'available_time', 'label' : 'Available On', 'flex' : 1,
871                         'primary' : false, 'hidden' : false,  'render' : function(my) { return my.ahr.transit() ? ( my.ahr.transit().dest_recv_time() ? my.ahr.transit().dest_recv_time().toString().substr(0,10) : "") : ( my.ahr.capture_time() ? my.ahr.capture_time().toString().substr(0,10) : "" ); },
872                 },
873                 {
874                         'persist' : 'hidden width ordinal', 'id' : 'capture_timestamp', 'label' : 'Capture Timestamp', 'flex' : 1,
875                         'primary' : false, 'hidden' : true,  'render' : function(my) { return my.ahr.capture_time() ? my.ahr.capture_time().toString() : ""; },
876                 },
877                 {
878                         'persist' : 'hidden width ordinal', 'id' : 'capture_time', 'label' : 'Capture Date', 'flex' : 1,
879                         'primary' : false, 'hidden' : true,  'render' : function(my) { return my.ahr.capture_time() ? my.ahr.capture_time().toString().substr(0,10) : ""; },
880                 },
881                 {
882                         'persist' : 'hidden width ordinal', 'id' : 'status', 'label' : document.getElementById('commonStrings').getString('staff.ahr_status_label'), 'flex' : 1,
883                         'primary' : false, 'hidden' : false,  'render' : function(my) { switch(my.status) { case 1: case "1": return "Waiting for copy"; break; case 2: case "2": return "Waiting for capture"; break; case 3: case "3": return "In-Transit"; break; case 4: case "4" : return "Ready for pickup"; break; default: return my.status; break;}; },
884                 },
885                 {
886                         'persist' : 'hidden width ordinal', 'id' : 'hold_type', 'label' : document.getElementById('commonStrings').getString('staff.ahr_hold_type_label'), 'flex' : 0,
887                         'primary' : false, 'hidden' : true,  'render' : function(my) { return my.ahr.hold_type(); },
888                 },
889         {
890                         'persist' : 'hidden width ordinal', 'id' : 'frozen', 'label' : 'Frozen?', 'flex' : 0,
891                         'primary' : false, 'hidden' : true,  'render' : function(my) { return get_bool( my.ahr.frozen() ) ? 'Yes' : 'No'; },
892         },
893         {
894                         'persist' : 'hidden width ordinal', 'id' : 'thaw_date', 'label' : 'Thaw Date', 'flex' : 0,
895                         'primary' : false, 'hidden' : true,  'render' : function(my) { return my.ahr.thaw_date() == null ? 'No Date' : my.ahr.thaw_date().substr(0,10); },
896         },
897                 {
898                         'persist' : 'hidden width ordinal', 'id' : 'pickup_lib', 'label' : 'Pickup Lib (Full Name)', 'flex' : 1,
899                         'primary' : false, 'hidden' : true,  
900                         'render' : function(my) { if (Number(my.ahr.pickup_lib())>=0) return data.hash.aou[ my.ahr.pickup_lib() ].name(); else return my.ahr.pickup_lib().name(); },
901                 },
902                 {
903                         'persist' : 'hidden width ordinal', 'id' : 'pickup_lib_shortname', 'label' : document.getElementById('commonStrings').getString('staff.ahr_pickup_lib_label'), 'flex' : 0,
904                         'primary' : false, 'hidden' : true,  
905                         'render' : function(my) { if (Number(my.ahr.pickup_lib())>=0) return data.hash.aou[ my.ahr.pickup_lib() ].shortname(); else return my.ahr.pickup_lib().shortname(); },
906                 },
907                 {
908                         'persist' : 'hidden width ordinal', 'id' : 'current_copy', 'label' : document.getElementById('commonStrings').getString('staff.ahr_current_copy_label'), 'flex' : 1,
909                         'primary' : false, 'hidden' : true,  'render' : function(my) { return my.acp ? my.acp.barcode() : "No Copy"; },
910                 },
911                 {
912                         'persist' : 'hidden width ordinal', 'id' : 'email_notify', 'label' : document.getElementById('commonStrings').getString('staff.ahr_email_notify_label'), 'flex' : 1,
913                         'primary' : false, 'hidden' : true,  'render' : function(my) { return get_bool(my.ahr.email_notify()) ? "Yes" : "No"; },
914                 },
915                 {
916                         'persist' : 'hidden width ordinal', 'id' : 'expire_time', 'label' : document.getElementById('commonStrings').getString('staff.ahr_expire_time_label'), 'flex' : 1,
917                         'primary' : false, 'hidden' : true,  'render' : function(my) { return my.ahr.expire_time(); },
918                 },
919                 {
920                         'persist' : 'hidden width ordinal', 'id' : 'fulfillment_time', 'label' : document.getElementById('commonStrings').getString('staff.ahr_fulfillment_time_label'), 'flex' : 1,
921                         'primary' : false, 'hidden' : true,  'render' : function(my) { return my.ahr.fulfillment_time(); },
922                 },
923                 {
924                         'persist' : 'hidden width ordinal', 'id' : 'holdable_formats', 'label' : document.getElementById('commonStrings').getString('staff.ahr_holdable_formats_label'), 'flex' : 1,
925                         'primary' : false, 'hidden' : true,  'render' : function(my) { return my.ahr.holdable_formats(); },
926                 },
927                 {
928                         'persist' : 'hidden width ordinal', 'id' : 'id', 'label' : document.getElementById('commonStrings').getString('staff.ahr_id_label'), 'flex' : 1,
929                         'primary' : false, 'hidden' : true,  'render' : function(my) { return my.ahr.id(); },
930                 },
931                 {
932                         'persist' : 'hidden width ordinal', 'id' : 'phone_notify', 'label' : document.getElementById('commonStrings').getString('staff.ahr_phone_notify_label'), 'flex' : 1,
933                         'primary' : false, 'hidden' : true,  'render' : function(my) { return my.ahr.phone_notify(); },
934                 },
935                 {
936                         'persist' : 'hidden width ordinal', 'id' : 'prev_check_time', 'label' : document.getElementById('commonStrings').getString('staff.ahr_prev_check_time_label'), 'flex' : 1,
937                         'primary' : false, 'hidden' : true,  'render' : function(my) { return my.ahr.prev_check_time(); },
938                 },
939                 {
940                         'persist' : 'hidden width ordinal', 'id' : 'requestor', 'label' : document.getElementById('commonStrings').getString('staff.ahr_requestor_label'), 'flex' : 1,
941                         'primary' : false, 'hidden' : true,  'render' : function(my) { return my.ahr.requestor(); },
942                 },
943                 {
944                         'persist' : 'hidden width ordinal', 'id' : 'selection_depth', 'label' : document.getElementById('commonStrings').getString('staff.ahr_selection_depth_label'), 'flex' : 1,
945                         'primary' : false, 'hidden' : true,  'render' : function(my) { return my.ahr.selection_depth(); },
946                 },
947                 {
948                         'persist' : 'hidden width ordinal', 'id' : 'target', 'label' : document.getElementById('commonStrings').getString('staff.ahr_target_label'), 'flex' : 1,
949                         'primary' : false, 'hidden' : true,  'render' : function(my) { return my.ahr.target(); },
950                 },
951                 {
952                         'persist' : 'hidden width ordinal', 'id' : 'usr', 'label' : document.getElementById('commonStrings').getString('staff.ahr_usr_label'), 'flex' : 1,
953                         'primary' : false, 'hidden' : true,  'render' : function(my) { return my.ahr.usr(); },
954                 },
955                 {
956                         'persist' : 'hidden width ordinal', 'id' : 'title', 'label' : document.getElementById('commonStrings').getString('staff.mvr_label_title'), 'flex' : 1, 'sort_type' : 'title',
957                         'primary' : false, 'hidden' : true, 'render' : function(my) { return my.mvr ? my.mvr.title() : "No Title?"; },
958                 },
959                 {
960                         'persist' : 'hidden width ordinal', 'id' : 'author', 'label' : document.getElementById('commonStrings').getString('staff.mvr_label_author'), 'flex' : 1,
961                         'primary' : false, 'hidden' : true, 'render' : function(my) { return my.mvr ? my.mvr.author() : "No Author?"; },
962                 },
963                 {
964                         'persist' : 'hidden width ordinal', 'id' : 'edition', 'label' : 'Edition', 'flex' : 1,
965                         'primary' : false, 'hidden' : true, 'render' : function(my) { return my.mvr.edition(); },
966                 },
967                 {
968                         'persist' : 'hidden width ordinal', 'id' : 'isbn', 'label' : 'ISBN', 'flex' : 1,
969                         'primary' : false, 'hidden' : true, 'render' : function(my) { return my.mvr.isbn(); },
970                 },
971                 {
972                         'persist' : 'hidden width ordinal', 'id' : 'pubdate', 'label' : 'PubDate', 'flex' : 1,
973                         'primary' : false, 'hidden' : true, 'render' : function(my) { return my.mvr.pubdate(); },
974                 },
975                 {
976                         'persist' : 'hidden width ordinal', 'id' : 'publisher', 'label' : 'Publisher', 'flex' : 1,
977                         'primary' : false, 'hidden' : true, 'render' : function(my) { return my.mvr.publisher(); },
978                 },
979                 {
980                         'persist' : 'hidden width ordinal', 'id' : 'tcn', 'label' : 'TCN', 'flex' : 1,
981                         'primary' : false, 'hidden' : true, 'render' : function(my) { return my.mvr.tcn(); },
982                 },
983                 {
984                         'persist' : 'hidden width ordinal', 'id' : 'notify_time', 'label' : 'Last Notify Time', 'flex' : 1,
985                         'primary' : false, 'hidden' : true, 'render' : function(my) { return my.ahr.notify_time(); },
986                 },
987                 {
988                         'persist' : 'hidden width ordinal', 'id' : 'notify_count', 'label' : 'Notices', 'flex' : 1,
989                         'primary' : false, 'hidden' : true, 'render' : function(my) { return my.ahr.notify_count(); },
990                 },
991                 {
992                         'persist' : 'hidden width ordinal', 'id' : 'transit_source', 'label' : 'Transit Source', 'flex' : 1,
993                         'primary' : false, 'hidden' : true, 'render' : function(my) { return my.ahr.transit() ?  data.hash.aou[ my.ahr.transit().source() ].shortname() : ""; },
994                 },
995                 {
996                         'persist' : 'hidden width ordinal', 'id' : 'transit_source_send_time', 'label' : 'Transitted On', 'flex' : 1,
997                         'primary' : false, 'hidden' : true, 'render' : function(my) { return my.ahr.transit() ?  my.ahr.transit().source_send_time() : ""; },
998                 },
999                 {
1000                         'persist' : 'hidden width ordinal', 'id' : 'transit_dest_lib', 'label' : 'Transit Destination', 'flex' : 1,
1001                         'primary' : false, 'hidden' : true, 'render' : function(my) { return my.ahr.transit() ?  data.hash.aou[ my.ahr.transit().dest() ].shortname() : ""; },
1002                 },
1003                 {
1004                         'persist' : 'hidden width ordinal', 'id' : 'transit_dest_recv_time', 'label' : 'Transit Completed On', 'flex' : 1,
1005                         'primary' : false, 'hidden' : true, 'render' : function(my) { return my.ahr.transit() ?  my.ahr.transit().dest_recv_time() : ""; },
1006                 },
1007                 {
1008                         'persist' : 'hidden width ordinal', 'id' : 'patron_barcode', 'label' : 'Patron Barcode', 'flex' : 1,
1009                         'primary' : false, 'hidden' : true, 'render' : function(my) { return my.patron_barcode ? my.patron_barcode : ""; },
1010                 },
1011                 {
1012                         'persist' : 'hidden width ordinal', 'id' : 'patron_family_name', 'label' : 'Patron Last Name', 'flex' : 1,
1013                         'primary' : false, 'hidden' : true, 'render' : function(my) { return my.patron_family_name ? my.patron_family_name : ""; },
1014                 },
1015                 {
1016                         'persist' : 'hidden width ordinal', 'id' : 'patron_first_given_name', 'label' : 'Patron First Name', 'flex' : 1,
1017                         'primary' : false, 'hidden' : true, 'render' : function(my) { return my.patron_first_given_name ? my.patron_first_given_name : ""; },
1018                 },
1019                 {
1020                         'persist' : 'hidden width ordinal', 'id' : 'callnumber', 'label' : 'Call Number', 'flex' : 1,
1021                         'primary' : false, 'hidden' : true, 'render' : function(my) { return my.acn.label(); },
1022                 },
1023         ];
1024         for (var i = 0; i < c.length; i++) {
1025                 if (modify[ c[i].id ]) {
1026                         for (var j in modify[ c[i].id ]) {
1027                                 c[i][j] = modify[ c[i].id ][j];
1028                         }
1029                 }
1030         }
1031         if (params) {
1032                 if (params.just_these) {
1033                         JSAN.use('util.functional');
1034                         var new_c = [];
1035                         for (var i = 0; i < params.just_these.length; i++) {
1036                                 var x = util.functional.find_list(c,function(d){return(d.id==params.just_these[i]);});
1037                                 new_c.push( function(y){ return y; }( x ) );
1038                         }
1039                         c = new_c;
1040                 }
1041                 if (params.except_these) {
1042                         JSAN.use('util.functional');
1043                         var new_c = [];
1044                         for (var i = 0; i < c.length; i++) {
1045                                 var x = util.functional.find_list(params.except_these,function(d){return(d==c[i].id);});
1046                                 if (!x) new_c.push(c[i]);
1047                         }
1048                         c = new_c;
1049                 }
1050
1051         }
1052         return c.sort( function(a,b) { if (a.label < b.label) return -1; if (a.label > b.label) return 1; return 0; } );
1053 }
1054 /*
1055 circ.util.std_map_row_to_column = function(error_value) {
1056         return function(row,col) {
1057                 // row contains { 'my' : { 'acp' : {}, 'circ' : {}, 'mvr' : {} } }
1058                 // col contains one of the objects listed above in columns
1059                 
1060                 // mimicking some of the obj in circ.checkin and circ.checkout where map_row_to_column is usually defined
1061                 var obj = {}; 
1062                 JSAN.use('util.error'); obj.error = new util.error();
1063                 JSAN.use('OpenILS.data'); obj.data = new OpenILS.data(); obj.data.init({'via':'stash'});
1064                 JSAN.use('util.network'); obj.network = new util.network();
1065                 JSAN.use('util.money');
1066
1067                 var my = row.my;
1068                 var value;
1069                 try { 
1070                         value = eval( col.render );
1071                 } catch(E) {
1072                         obj.error.sdump('D_WARN','map_row_to_column: ' + E);
1073                         if (error_value) value = error_value; else value = '   ';
1074                 }
1075                 return value;
1076         }
1077 }
1078 */
1079 circ.util.std_map_row_to_columns = function(error_value) {
1080         return function(row,cols) {
1081                 // row contains { 'my' : { 'acp' : {}, 'circ' : {}, 'mvr' : {} } }
1082                 // cols contains all of the objects listed above in columns
1083                 
1084                 var obj = {}; 
1085                 JSAN.use('util.error'); obj.error = new util.error();
1086                 JSAN.use('OpenILS.data'); obj.data = new OpenILS.data(); obj.data.init({'via':'stash'});
1087                 JSAN.use('util.network'); obj.network = new util.network();
1088                 JSAN.use('util.money');
1089
1090                 var my = row.my;
1091                 var values = [];
1092                 var cmd = '';
1093                 try { 
1094                         for (var i = 0; i < cols.length; i++) {
1095                                 switch (typeof cols[i].render) {
1096                                         case 'function': try { values[i] = cols[i].render(my); } catch(E) { values[i] = error_value; dump(E+'\n'); } break;
1097                                         case 'string' : cmd += 'try { ' + cols[i].render + '; values['+i+'] = v; } catch(E) { values['+i+'] = error_value; }'; break;
1098                                         default: cmd += 'values['+i+'] = "??? '+(typeof cols[i].render)+'"; ';
1099                                 }
1100                         }
1101                         if (cmd) eval( cmd );
1102                 } catch(E) {
1103                         obj.error.sdump('D_WARN','map_row_to_column: ' + E);
1104                         if (error_value) { value = error_value; } else { value = '   ' };
1105                 }
1106                 return values;
1107         }
1108 }
1109
1110 circ.util.checkin_via_barcode = function(session,params,backdate,auto_print,async) {
1111         try {
1112                 JSAN.use('util.error'); var error = new util.error();
1113                 JSAN.use('util.network'); var network = new util.network();
1114                 JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.init({'via':'stash'});
1115                 JSAN.use('util.date');
1116
1117                 if (backdate && (backdate == util.date.formatted_date(new Date(),'%Y-%m-%d')) ) backdate = null;
1118
1119                 //var params = { 'barcode' : barcode };
1120                 if (backdate) params.backdate = util.date.formatted_date(backdate + ' 00:00:00','%{iso8601}');
1121
1122                 if (typeof async == 'object') {
1123                         try { async.disable_textbox(); } catch(E) { error.sdump('D_ERROR','async.disable_textbox() = ' + E); };
1124                 }
1125                 var check = network.request(
1126                         api.CHECKIN_VIA_BARCODE.app,
1127                         api.CHECKIN_VIA_BARCODE.method,
1128                         [ session, params ],
1129                         async ? function(req) { 
1130                                 try {
1131                                         var check = req.getResultObject();
1132                                         var r = circ.util.checkin_via_barcode2(session,params,backdate,auto_print,check); 
1133                                         if (typeof async == 'object') {
1134                                                 try { async.checkin_result(r); } catch(E) { error.sdump('D_ERROR','async.checkin_result() = ' + E); };
1135                                         }
1136                                 } catch(E) {
1137                                         JSAN.use('util.error'); var error = new util.error();
1138                                         error.standard_unexpected_error_alert('Check In Failed (in circ.util.checkin) (1): ',E);
1139                                         if (typeof async == 'object') {
1140                                                 try { async.enable_textbox(); } catch(E) { error.sdump('D_ERROR','async.disable_textbox() = ' + E); };
1141                                         }
1142                                         return null;
1143                                 }
1144                         } : null,
1145                         {
1146                                 'title' : 'Override Checkin Failure?',
1147                                 'overridable_events' : [ 
1148                                         1203 /* COPY_BAD_STATUS */, 
1149                                         1213 /* PATRON_BARRED */,
1150                                         1217 /* PATRON_INACTIVE */,
1151                                         1224 /* PATRON_ACCOUNT_EXPIRED */,
1152                                         7009 /* CIRC_CLAIMS_RETURNED */,
1153                                         7010 /* COPY_ALERT_MESSAGE */, 
1154                                         7011 /* COPY_STATUS_LOST */, 
1155                                         7012 /* COPY_STATUS_MISSING */, 
1156                                         7013 /* PATRON_EXCEEDS_FINES */,
1157                                 ],
1158                                 'text' : {
1159                                         '1203' : function(r) {
1160                                                 //return data.hash.ccs[ r.payload.status() ].name();
1161                                                 return r.payload.status().name();
1162                                         },
1163                                         '7010' : function(r) {
1164                                                 return r.payload;
1165                                         },
1166                                 }
1167                         }
1168                 );
1169                 if (!async) {
1170                         return circ.util.checkin_via_barcode2(session,params,backdate,auto_print,check); 
1171                 }
1172
1173
1174         } catch(E) {
1175                 JSAN.use('util.error'); var error = new util.error();
1176                 error.standard_unexpected_error_alert('Check In Failed (in circ.util.checkin) (2): ',E);
1177                 if (typeof async == 'object') {
1178                         try { async.enable_textbox(); } catch(E) { error.sdump('D_ERROR','async.disable_textbox() = ' + E); };
1179                 }
1180                 return null;
1181         }
1182 }
1183
1184 circ.util.checkin_via_barcode2 = function(session,params,backdate,auto_print,check) {
1185         try {
1186                 JSAN.use('util.error'); var error = new util.error();
1187                 JSAN.use('util.network'); var network = new util.network();
1188                 JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.init({'via':'stash'});
1189                 JSAN.use('util.date');
1190
1191                 error.sdump('D_DEBUG','check = ' + error.pretty_print( js2JSON( check ) ) );
1192
1193                 check.message = check.textcode;
1194
1195                 if (check.payload && check.payload.copy) check.copy = check.payload.copy;
1196                 if (check.payload && check.payload.record) check.record = check.payload.record;
1197                 if (check.payload && check.payload.circ) check.circ = check.payload.circ;
1198
1199                 if (!check.route_to) check.route_to = '   ';
1200
1201                 if (document.getElementById('no_change_label')) {
1202                         document.getElementById('no_change_label').setAttribute('value','');
1203                         document.getElementById('no_change_label').setAttribute('hidden','true');
1204                 }
1205
1206                 if (check.circ) {
1207                         network.simple_request('FM_MBTS_RETRIEVE',[ses(),check.circ.id()], function(req) {
1208                                 JSAN.use('util.money');
1209                                 var bill = req.getResultObject();
1210                                 if (Number(bill.balance_owed()) == 0) return;
1211                                 if (document.getElementById('no_change_label')) {
1212                                         var m = document.getElementById('no_change_label').getAttribute('value');
1213                                         document.getElementById('no_change_label').setAttribute('value', m + 'Transaction for ' + params.barcode + ' billable $' + util.money.sanitize(bill.balance_owed()) + '  ');
1214                                         document.getElementById('no_change_label').setAttribute('hidden','false');
1215                                 }
1216                         });
1217                 }
1218
1219                 var msg = '';
1220
1221                 if (check.payload && check.payload.cancelled_hold_transit) {
1222                         msg += 'Original hold for transit cancelled.\n\n';
1223                 }
1224
1225                 /* SUCCESS  /  NO_CHANGE  /  ITEM_NOT_CATALOGED */
1226                 if (check.ilsevent == 0 || check.ilsevent == 3 || check.ilsevent == 1202) {
1227                         try { check.route_to = data.lookup('acpl', check.copy.location() ).name(); } catch(E) { msg += 'Please inform your helpdesk/developers of this error:\nFIXME: ' + E + '\n'; }
1228                         if (check.ilsevent == 3 /* NO_CHANGE */) {
1229                                 //msg = 'This item is already checked in.\n';
1230                                 if (document.getElementById('no_change_label')) {
1231                                         var m = document.getElementById('no_change_label').getAttribute('value');
1232                                         document.getElementById('no_change_label').setAttribute('value',m + params.barcode + ' was already checked in.  ');
1233                                         document.getElementById('no_change_label').setAttribute('hidden','false');
1234                                 }
1235                         }
1236                         if (check.ilsevent == 1202 /* ITEM_NOT_CATALOGED */ && check.copy.status() != 11) {
1237                                 msg = 'Please inform your helpdesk/developers of this error:\nFIXME -- ITEM_NOT_CATALOGED event but copy status is '
1238                                         + (data.hash.ccs[ check.copy.status() ] ? data.hash.ccs[ check.copy.status() ].name() : check.copy.status().name() ) + '\n';
1239                         }
1240                         switch(check.copy.status()) {
1241                                 case 0: /* AVAILABLE */
1242                                 case 7: /* RESHELVING */
1243                                         if (msg) msg += 'This item needs to be routed to ' + check.route_to + '.\n';
1244                                 break;
1245                                 case 8: /* ON HOLDS SHELF */
1246                                         check.route_to = 'HOLDS SHELF';
1247                                         if (check.payload.hold) {
1248                                                 if (check.payload.hold.pickup_lib() != data.list.au[0].ws_ou()) {
1249                                                         msg += 'Please inform your helpdesk/developers of this error:\nFIXME:  We should have received a ROUTE_ITEM\n';
1250                                                 } else {
1251                                                         msg += 'This item needs to be routed to ' + check.route_to + '.\n';
1252                                                 }
1253                                         } else { 
1254                                                 msg += 'Please inform your helpdesk/developers of this error:\nFIXME: status of Holds Shelf, but no actual hold found.\n';
1255                                         }
1256                                         JSAN.use('util.date'); 
1257                                         if (check.payload.hold) {
1258                                                 JSAN.use('patron.util');
1259                                                 msg += '\nBarcode: ' + check.payload.copy.barcode() + '\n';
1260                                                 msg += 'Title: ' + (check.payload.record ? check.payload.record.title() : check.payload.copy.dummy_title() ) + '\n';
1261                                                 var au_obj = patron.util.retrieve_fleshed_au_via_id( session, check.payload.hold.usr() );
1262                                                 msg += '\nHold for patron ' + au_obj.family_name() + ', ' + au_obj.first_given_name() + ' ' + au_obj.second_given_name() + '\n';
1263                                                 msg += 'Barcode: ' + au_obj.card().barcode() + '\n';
1264                                                 if (check.payload.hold.phone_notify()) msg += 'Notify by phone: ' + check.payload.hold.phone_notify() + '\n';
1265                                                 if (check.payload.hold.email_notify()) msg += 'Notify by email: ' + (au_obj.email() ? au_obj.email() : '') + '\n';
1266                                                 msg += '\nRequest Date: ' + util.date.formatted_date(check.payload.hold.request_time(),'%F') + '\n';
1267                                         }
1268                                         var rv = 0;
1269                                         msg += 'Slip Date: ' + util.date.formatted_date(new Date(),'%F') + '\n';
1270                                         if (!auto_print) rv = error.yns_alert_formatted(
1271                                                 msg,
1272                                                 'Hold Slip',
1273                                                 "Print",
1274                                                 "Don't Print",
1275                                                 null,
1276                                                 "Check here to confirm this message",
1277                                                 '/xul/server/skin/media/images/turtle.gif'
1278                                         );
1279                                         if (rv == 0) {
1280                                                 try {
1281                                                         JSAN.use('util.print'); var print = new util.print();
1282                                                         msg = msg.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/\n/g,'<br/>');
1283                                                         print.simple( msg , { 'no_prompt' : true, 'content_type' : 'text/html' } );
1284                                                 } catch(E) {
1285                                                         dump('Please inform your helpdesk/developers of this error:\nFIXME: ' + E + '\n');
1286                                                         alert('Please inform your helpdesk/developers of this error:\nFIXME: ' + E + '\n');
1287                                                 }
1288                                         }
1289                                         msg = '';
1290                                         if (document.getElementById('no_change_label')) {
1291                                                 var m = document.getElementById('no_change_label').getAttribute('value');
1292                                                 document.getElementById('no_change_label').setAttribute('value',m + params.barcode + ' has been captured for a hold.  ');
1293                                                 document.getElementById('no_change_label').setAttribute('hidden','false');
1294                                         }
1295                                 break;
1296                                 case 6: /* IN TRANSIT */
1297                                         check.route_to = 'TRANSIT SHELF??';
1298                                         msg += ("Please inform your helpdesk/developers of this error:\nFIXME -- I didn't think we could get here.\n");
1299                                 break;
1300                                 case 11: /* CATALOGING */
1301                                         check.route_to = 'CATALOGING';
1302                                         if (document.getElementById('do_not_alert_on_precat')) {
1303                                                 var x = document.getElementById('do_not_alert_on_precat');
1304                                                 if (! x.checked) msg += 'This item needs to be routed to ' + check.route_to + '.';
1305                                         } else {
1306                                                 msg += 'This item needs to be routed to ' + check.route_to + '.';
1307                                         }
1308                                         if (document.getElementById('no_change_label')) {
1309                                                 var m = document.getElementById('no_change_label').getAttribute('value');
1310                                                 document.getElementById('no_change_label').setAttribute('value',m + params.barcode + ' needs to be cataloged.  ');
1311                                                 document.getElementById('no_change_label').setAttribute('hidden','false');
1312                                         }
1313                                 break;
1314                                 default:
1315                                         msg += ('Please inform your helpdesk/developers of this error:\nFIXME -- this case "' + (data.hash.ccs[check.copy.status()] ? data.hash.ccs[check.copy.status()].name() : check.copy.status().name()) + '" is unhandled.\n');
1316                                         msg += 'This item needs to be routed to ' + check.route_to + '.';
1317                                 break;
1318                         }
1319                         if (msg) error.yns_alert(msg,'Alert',null,'OK',null,"Check here to confirm this message");
1320
1321                 } else /* ROUTE_ITEM */ if (check.ilsevent == 7000) {
1322
1323                         var lib = data.hash.aou[ check.org ];
1324                         check.route_to = lib.shortname();
1325                         msg += 'Destination: ' + check.route_to + '.\n';
1326                         msg += '\n' + lib.name() + '\n';
1327                         try {
1328                                 if (lib.holds_address() ) {
1329                                         var a = network.simple_request('FM_AOA_RETRIEVE',[ lib.holds_address() ]);
1330                                         if (typeof a.ilsevent != 'undefined') throw(a);
1331                                         if (a.street1()) msg += a.street1() + '\n';
1332                                         if (a.street2()) msg += a.street2() + '\n';
1333                                         msg += (a.city() ? a.city() + ', ' : '') + (a.state() ? a.state() + ' ' : '') + (a.post_code() ? a.post_code() : '') + '\n';
1334                                 } else {
1335                                         msg += "We do not have a holds address for this library.\n";
1336                                 }
1337                         } catch(E) {
1338                                 msg += 'Unable to retrieve mailing address.\n';
1339                                 error.standard_unexpected_error_alert('Unable to retrieve mailing address.',E);
1340                         }
1341                         msg += '\nBarcode: ' + check.payload.copy.barcode() + '\n';
1342                         msg += 'Title: ' + (check.payload.record ? check.payload.record.title() : check.payload.copy.dummy_title() ) + '\n';
1343                         msg += 'Author: ' + (check.payload.record ? check.payload.record.author() :check.payload.copy.dummy_author()  ) + '\n';
1344                         JSAN.use('util.date');
1345                         if (check.payload.hold) {
1346                                 JSAN.use('patron.util');
1347                                 var au_obj = patron.util.retrieve_fleshed_au_via_id( session, check.payload.hold.usr() );
1348                                 msg += '\nHold for patron ' + au_obj.family_name() + ', ' + au_obj.first_given_name() + ' ' + au_obj.second_given_name() + '\n';
1349                                 msg += 'Barcode: ' + au_obj.card().barcode() + '\n';
1350                                 if (check.payload.hold.phone_notify()) msg += 'Notify by phone: ' + check.payload.hold.phone_notify() + '\n';
1351                                 if (check.payload.hold.email_notify()) msg += 'Notify by email: ' + (au_obj.email() ? au_obj.email() : '') + '\n';
1352                                 msg += '\nRequest Date: ' + util.date.formatted_date(check.payload.hold.request_time(),'%F');
1353                         }
1354                         var rv = 0;
1355                         msg += '\nSlip Date: ' + util.date.formatted_date(new Date(),'%F') + '\n';
1356                         if (!auto_print) rv = error.yns_alert_formatted(
1357                                 msg,
1358                                 'Transit Slip',
1359                                 "Print",
1360                                 "Don't Print",
1361                                 null,
1362                                 "Check here to confirm this message",
1363                                 '/xul/server/skin/media/images/turtle.gif'
1364                         );
1365                         if (rv == 0) {
1366                                 try {
1367                                         JSAN.use('util.print'); var print = new util.print();
1368                                         //print.simple( msg, { 'no_prompt' : true, 'content_type' : 'text/plain' } );
1369                                         msg = msg.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/\n/g,'<br/>');
1370                                         print.simple( msg , { 'no_prompt' : true, 'content_type' : 'text/html' } );
1371                                 } catch(E) {
1372                                         dump('Please inform your helpdesk/developers of this error:\nFIXME: ' + E + '\n');
1373                                         alert('Please inform your helpdesk/developers of this error:\nFIXME: ' + E + '\n');
1374                                 }
1375                         }
1376                         if (document.getElementById('no_change_label')) {
1377                                 var m = document.getElementById('no_change_label').getAttribute('value');
1378                                 document.getElementById('no_change_label').setAttribute('value',m + params.barcode + ' is in transit.  ');
1379                                 document.getElementById('no_change_label').setAttribute('hidden','false');
1380                         }
1381
1382                 } else /* ASSET_COPY_NOT_FOUND */ if (check.ilsevent == 1502) {
1383
1384                         check.route_to = 'CATALOGING';
1385                         error.yns_alert(
1386                                 'The barcode was either mis-scanned or the item needs to be cataloged.',
1387                                 'Alert',
1388                                 null,
1389                                 'OK',
1390                                 null,
1391                                 "Check here to confirm this message"
1392                         );
1393                         if (document.getElementById('no_change_label')) {
1394                                 var m = document.getElementById('no_change_label').getAttribute('value');
1395                                 document.getElementById('no_change_label').setAttribute('value',m + params.barcode + ' is mis-scanned or not cataloged.  ');
1396                                 document.getElementById('no_change_label').setAttribute('hidden','false');
1397                         }
1398
1399                 } else /* NETWORK TIMEOUT */ if (check.ilsevent == -1) {
1400                         error.standard_network_error_alert('Check In Failed.  If you wish to use the offline interface, in the top menubar select Circulation -> Offline Interface');
1401                 } else {
1402
1403                         switch (check.ilsevent) {
1404                                 case 1203 /* COPY_BAD_STATUS */ : 
1405                                 case 1213 /* PATRON_BARRED */ :
1406                                 case 1217 /* PATRON_INACTIVE */ :
1407                                 case 1224 /* PATRON_ACCOUNT_EXPIRED */ :
1408                                 case 7009 /* CIRC_CLAIMS_RETURNED */ :
1409                                 case 7010 /* COPY_ALERT_MESSAGE */ : 
1410                                 case 7011 /* COPY_STATUS_LOST */ : 
1411                                 case 7012 /* COPY_STATUS_MISSING */ : 
1412                                 case 7013 /* PATRON_EXCEEDS_FINES */ :
1413                                         return null; /* handled */
1414                                 break;
1415                         }
1416
1417                         throw(check);
1418
1419                 }
1420
1421                 return check;
1422         } catch(E) {
1423                 JSAN.use('util.error'); var error = new util.error();
1424                 error.standard_unexpected_error_alert('Check In Failed (in circ.util.checkin) (3): ',E);
1425                 return null;
1426         }
1427 }
1428
1429 circ.util.renew_via_barcode = function ( barcode, patron_id, async ) {
1430         try {
1431                 var obj = {};
1432                 JSAN.use('util.network'); obj.network = new util.network();
1433                 JSAN.use('OpenILS.data'); obj.data = new OpenILS.data(); obj.data.stash_retrieve();
1434
1435                 var params = { barcode: barcode };
1436                 if (patron_id) params.patron = patron_id;
1437
1438                 function renew_callback(req) {
1439                         try {
1440                                 var renew = req.getResultObject();
1441                                 if (typeof renew.ilsevent != 'undefined') renew = [ renew ];
1442                                 for (var j = 0; j < renew.length; j++) { 
1443                                         switch(renew[j].ilsevent) {
1444                                                 case 0 /* SUCCESS */ : break;
1445                                                 case 5000 /* PERM_FAILURE */: break;
1446                                                 case 1212 /* PATRON_EXCEEDS_OVERDUE_COUNT */ : break;
1447                                                 case 1213 /* PATRON_BARRED */ : break;
1448                                                 case 1215 /* CIRC_EXCEEDS_COPY_RANGE */ : break;
1449                                                 case 1224 /* PATRON_ACCOUNT_EXPIRED */ : break;
1450                                                 case 1500 /* ACTION_CIRCULATION_NOT_FOUND */ : break;
1451                                                 case 7002 /* PATRON_EXCEEDS_CHECKOUT_COUNT */ : break;
1452                                                 case 7003 /* COPY_CIRC_NOT_ALLOWED */ : break;
1453                                                 case 7004 /* COPY_NOT_AVAILABLE */ : break;
1454                                                 case 7006 /* COPY_IS_REFERENCE */ : break;
1455                                                 case 7007 /* COPY_NEEDED_FOR_HOLD */ : break;
1456                                                 case 7008 /* MAX_RENEWALS_REACHED */ : break; 
1457                                                 case 7009 /* CIRC_CLAIMS_RETURNED */ : break; 
1458                                                 case 7010 /* COPY_ALERT_MESSAGE */ : break;
1459                                                 case 7013 /* PATRON_EXCEEDS_FINES */ : break;
1460                                                 default:
1461                                                         throw(renew);
1462                                                 break;
1463                                         }
1464                                 }
1465                                 if (typeof async == 'function') async(renew);
1466                                 return renew;
1467                         } catch(E) {
1468                                 JSAN.use('util.error'); var error = new util.error();
1469                                 error.standard_unexpected_error_alert('Renew Failed for ' + barcode,E);
1470                                 return null;
1471                         }
1472                 }
1473
1474                 var renew = obj.network.simple_request(
1475                         'CHECKOUT_RENEW', 
1476                         [ ses(), params ],
1477                         async ? renew_callback : null,
1478                         {
1479                                 'title' : 'Override Renew Failure?',
1480                                 'overridable_events' : [ 
1481                                         1212 /* PATRON_EXCEEDS_OVERDUE_COUNT */,
1482                                         1213 /* PATRON_BARRED */,
1483                                         1215 /* CIRC_EXCEEDS_COPY_RANGE */,
1484                                         7002 /* PATRON_EXCEEDS_CHECKOUT_COUNT */,
1485                                         7003 /* COPY_CIRC_NOT_ALLOWED */,
1486                                         7004 /* COPY_NOT_AVAILABLE */,
1487                                         7006 /* COPY_IS_REFERENCE */,
1488                                         7007 /* COPY_NEEDED_FOR_HOLD */,
1489                                         7008 /* MAX_RENEWALS_REACHED */, 
1490                                         7009 /* CIRC_CLAIMS_RETURNED */, 
1491                                         7010 /* COPY_ALERT_MESSAGE */,
1492                                         7013 /* PATRON_EXCEEDS_FINES */,
1493                                 ],
1494                                 'text' : {
1495                                         '1212' : function(r) { return 'Barcode: ' + barcode; },
1496                                         '1213' : function(r) { return 'Barcode: ' + barcode; },
1497                                         '1215' : function(r) { return 'Barcode: ' + barcode; },
1498                                         '7002' : function(r) { return 'Barcode: ' + barcode; },
1499                                         '7003' : function(r) { return 'Barcode: ' + barcode; },
1500                                         '7004' : function(r) {
1501                                                 return 'Barcode: ' + barcode + ' Status: ' + r.payload.status().name();
1502                                         },
1503                                         '7006' : function(r) { return 'Barcode: ' + barcode; },
1504                                         '7007' : function(r) { return 'Barcode: ' + barcode; },
1505                                         '7008' : function(r) { return 'Barcode: ' + barcode; },
1506                                         '7009' : function(r) { return 'Barcode: ' + barcode; },
1507                                         '7010' : function(r) {
1508                                                 return 'Barcode: ' + barcode + ' Message: ' + r.payload;
1509                                         },
1510                                         '7013' : function(r) { return 'Barcode: ' + barcode; },
1511                                 }
1512                         }
1513                 );
1514                 if (! async ) return renew_callback( { 'getResultObject' : function() { return renew; } } );
1515
1516         } catch(E) {
1517                 JSAN.use('util.error'); var error = new util.error();
1518                 error.standard_unexpected_error_alert('Renew Failed for ' + barcode,E);
1519                 return null;
1520         }
1521 }
1522
1523
1524
1525 dump('exiting circ/util.js\n');