]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/xul/staff_client/server/circ/util.js
handle custom events (which have ilsevent == null)
[working/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(Number(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) {
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         for (var i = 0; i < selection_list.length; i++) {
97                 try {
98                         if (typeof selection_list[i].copy_id == 'undefined' || selection_list[i].copy_id == null) continue;
99                         var url = xulG.url_prefix( urls.XUL_CIRC_SUMMARY ); // + '?copy_id=' + selection_list[i].copy_id + '&count=' + count;
100                         var my_xulG = obj.win.open( url, 'show_last_few_circs', 'chrome,resizable,modal', { 'copy_id' : selection_list[i].copy_id } );
101
102                         if (typeof my_xulG.retrieve_these_patrons == 'undefined') continue;
103                         var patrons = my_xulG.retrieve_these_patrons;
104                         for (var j = 0; j < patrons.length; j++) {
105                                 if (typeof window.xulG == 'object' && typeof window.xulG.new_tab == 'function') {
106                                         try {
107                                                 var url = urls.XUL_PATRON_DISPLAY; // + '?id=' + window.escape( patrons[j] );
108                                                 window.xulG.new_tab( url, {}, { 'id' : patrons[j] } );
109                                         } catch(E) {
110                                                 obj.error.standard_unexpected_error_alert(document.getElementById('circStrings').getString('staff.circ.utils.retrieve_patron.failure') ,E);
111                                         }
112                                 }
113                         }
114
115                 } catch(E) {
116                         obj.error.standard_unexpected_error_alert(document.getElementById('circStrings').getString('staff.circ.utils.retrieve_circs.failure') ,E);
117                 }
118         }
119 };
120
121 circ.util.offline_checkout_columns = function(modify,params) {
122         
123         var c = [
124                 {
125                         'id' : 'timestamp',
126                         'label' : document.getElementById('circStrings').getString('staff.circ.utils.offline.timestamp'),
127                         'flex' : 1,
128                         'primary' : false,
129                         '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,
136                         'primary' : false,
137                         'hidden' : true,
138                         'render' : function(my) { return my.checkout_time; }
139                 },
140                 {
141                         'id' : 'type',
142                         'label' : document.getElementById('circStrings').getString('staff.circ.utils.offline.type'),
143                         'flex' : 1,
144                         'primary' : false,
145                         'hidden' : true,
146                         'render' : function(my) { return my.type; }
147                 },
148                 {
149                         'id' : 'noncat',
150                         'label' : document.getElementById('circStrings').getString('staff.circ.utils.offline.noncat'),
151                         'flex' : 1,
152                         'primary' : false,
153                         'hidden' : true,
154                         'render' : function(my) { return my.noncat; }
155                 },
156                 {
157                         'id' : 'noncat_type',
158                         'label' : document.getElementById('circStrings').getString('staff.circ.utils.offline.noncat_type'),
159                         'flex' : 1,
160                         'primary' : false,
161                         'hidden' : true,
162                         'render' : function(my) { return my.noncat_type; }
163                 },
164                 {
165                         'id' : 'noncat_count',
166                         'label' : document.getElementById('circStrings').getString('staff.circ.utils.offline.count'),
167                         'sort_type' : 'number',
168                         'flex' : 1,
169                         'primary' : false,
170                         'hidden' : false,
171                         'render' : function(my) { return my.noncat_count; }
172                 },
173                 {
174                         'id' : 'patron_barcode',
175                         'label' : document.getElementById('circStrings').getString('staff.circ.utils.offline.patron_barcode'),
176                         'flex' : 1,
177                         'primary' : false,
178                         'hidden' : true,
179                         'render' : function(my) { return my.patron_barcode; }
180                 },
181                 {
182                         'id' : 'barcode',
183                         'label' : document.getElementById('circStrings').getString('staff.circ.utils.offline.item_barcode'),
184                         'flex' : 2,
185                         'primary' : true,
186                         'hidden' : false,
187                         'render' : function(my) { return my.barcode; }
188                 },
189                 {
190                         'id' : 'due_date',
191                         'label' : document.getElementById('circStrings').getString('staff.circ.utils.offline.due_date'),
192                         'flex' : 1,
193                         'primary' : false,
194                         'hidden' : false,
195                         'render' : function(my) { return my.due_date; }
196                 }
197         ];
198         if (modify) for (var i = 0; i < c.length; i++) {
199                 if (modify[ c[i].id ]) {
200                         for (var j in modify[ c[i].id ]) {
201                                 c[i][j] = modify[ c[i].id ][j];
202                         }
203                 }
204         }
205         if (params) {
206                 if (params.just_these) {
207                         JSAN.use('util.functional');
208                         var new_c = [];
209                         for (var i = 0; i < params.just_these.length; i++) {
210                                 var x = util.functional.find_list(c,function(d){return(d.id==params.just_these[i]);});
211                                 new_c.push( function(y){ return y; }( x ) );
212                         }
213                         c = new_c;
214                 }
215                 if (params.except_these) {
216                         JSAN.use('util.functional');
217                         var new_c = [];
218                         for (var i = 0; i < c.length; i++) {
219                                 var x = util.functional.find_list(params.except_these,function(d){return(d==c[i].id);});
220                                 if (!x) new_c.push(c[i]);
221                         }
222                         c = new_c;
223                 }
224
225         }
226         return c.sort( function(a,b) { if (a.label < b.label) return -1; if (a.label > b.label) return 1; return 0; } );
227 };
228
229 circ.util.offline_checkin_columns = function(modify,params) {
230         
231         var c = [
232                 {
233                         'id' : 'timestamp',
234                         'label' : document.getElementById('circStrings').getString('staff.circ.utils.offline.timestamp'),
235                         'flex' : 1,
236                         'primary' : false,
237                         'hidden' : true,
238                         'render' : function(my) { return my.timestamp; }
239                 },
240                 {
241                         'id' : 'backdate',
242                         'label' : document.getElementById('circStrings').getString('staff.circ.utils.offline.backdate'),
243                         'flex' : 1,
244                         'primary' : false,
245                         'hidden' : true,
246                         'render' : function(my) { return my.backdate; }
247                 },
248                 {
249                         'id' : 'type',
250                         'label' : document.getElementById('circStrings').getString('staff.circ.utils.offline.type'),
251                         'flex' : 1,
252                         'primary' : false,
253                         'hidden' : true,
254                         'render' : function(my) { return my.type; }
255                 },
256                 {
257                         'id' : 'barcode',
258                         'label' : document.getElementById('circStrings').getString('staff.circ.utils.offline.item_barcode'),
259                         'flex' : 2,
260                         'primary' : true,
261                         'hidden' : false,
262                         'render' : function(my) { return my.barcode; }
263                 }
264         ];
265         if (modify) for (var i = 0; i < c.length; i++) {
266                 if (modify[ c[i].id ]) {
267                         for (var j in modify[ c[i].id ]) {
268                                 c[i][j] = modify[ c[i].id ][j];
269                         }
270                 }
271         }
272         if (params) {
273                 if (params.just_these) {
274                         JSAN.use('util.functional');
275                         var new_c = [];
276                         for (var i = 0; i < params.just_these.length; i++) {
277                                 var x = util.functional.find_list(c,function(d){return(d.id==params.just_these[i]);});
278                                 new_c.push( function(y){ return y; }( x ) );
279                         }
280                         c = new_c;
281                 }
282                 if (params.except_these) {
283                         JSAN.use('util.functional');
284                         var new_c = [];
285                         for (var i = 0; i < c.length; i++) {
286                                 var x = util.functional.find_list(params.except_these,function(d){return(d==c[i].id);});
287                                 if (!x) new_c.push(c[i]);
288                         }
289                         c = new_c;
290                 }
291
292         }
293         return c.sort( function(a,b) { if (a.label < b.label) return -1; if (a.label > b.label) return 1; return 0; } );
294 };
295
296 circ.util.offline_renew_columns = function(modify,params) {
297         
298         var c = [
299                 {
300                         'id' : 'timestamp',
301                         'label' : document.getElementById('circStrings').getString('staff.circ.utils.offline.timestamp'),
302                         'flex' : 1,
303                         'primary' : false,
304                         'hidden' : true,
305                         'render' : function(my) { return my.timestamp; }
306                 },
307                 {
308                         'id' : 'checkout_time',
309                         'label' : document.getElementById('circStrings').getString('staff.circ.utils.offline.checkout_time'),
310                         'flex' : 1,
311                         'primary' : false,
312                         'hidden' : true,
313                         'render' : function(my) { return my.checkout_time; }
314                 },
315                 {
316                         'id' : 'type',
317                         'label' : document.getElementById('circStrings').getString('staff.circ.utils.offline.type'),
318                         'flex' : 1,
319                         'primary' : false,
320                         'hidden' : true,
321                         'render' : function(my) { return my.type; }
322                 },
323                 {
324                         'id' : 'patron_barcode',
325                         'label' : document.getElementById('circStrings').getString('staff.circ.utils.offline.patron_barcode'),
326                         'flex' : 1,
327                         'primary' : false,
328                         'hidden' : true,
329                         'render' : function(my) { return my.patron_barcode; }
330                 },
331                 {
332                         'id' : 'barcode',
333                         'label' : document.getElementById('circStrings').getString('staff.circ.utils.offline.item_barcode'),
334                         'flex' : 2,
335                         'primary' : true,
336                         'hidden' : false,
337                         'render' : function(my) { return my.barcode; }
338                 },
339                 {
340                         'id' : 'due_date',
341                         'label' : document.getElementById('circStrings').getString('staff.circ.utils.offline.due_date'),
342                         'flex' : 1,
343                         'primary' : false,
344                         'hidden' : false,
345                         'render' : function(my) { return my.due_date; }
346                 }
347         ];
348         if (modify) for (var i = 0; i < c.length; i++) {
349                 if (modify[ c[i].id ]) {
350                         for (var j in modify[ c[i].id ]) {
351                                 c[i][j] = modify[ c[i].id ][j];
352                         }
353                 }
354         }
355         if (params) {
356                 if (params.just_these) {
357                         JSAN.use('util.functional');
358                         var new_c = [];
359                         for (var i = 0; i < params.just_these.length; i++) {
360                                 var x = util.functional.find_list(c,function(d){return(d.id==params.just_these[i]);});
361                                 new_c.push( function(y){ return y; }( x ) );
362                         }
363                         c = new_c;
364                 }
365                 if (params.except_these) {
366                         JSAN.use('util.functional');
367                         var new_c = [];
368                         for (var i = 0; i < c.length; i++) {
369                                 var x = util.functional.find_list(params.except_these,function(d){return(d==c[i].id);});
370                                 if (!x) new_c.push(c[i]);
371                         }
372                         c = new_c;
373                 }
374
375         }
376         return c.sort( function(a,b) { if (a.label < b.label) return -1; if (a.label > b.label) return 1; return 0; } );
377 };
378
379 circ.util.offline_inhouse_use_columns = function(modify,params) {
380         
381         var c = [
382                 {
383                         'id' : 'timestamp',
384                         'label' : document.getElementById('circStrings').getString('staff.circ.utils.offline.timestamp'),
385                         'flex' : 1,
386                         'primary' : false,
387                         'hidden' : true,
388                         'render' : function(my) { return my.timestamp; }
389                 },
390                 {
391                         'id' : 'use_time',
392                         'label' : document.getElementById('circStrings').getString('staff.circ.utils.offline.use_time'),
393                         'flex' : 1,
394                         'primary' : false,
395                         'hidden' : true,
396                         'render' : function(my) { return my.use_time; }
397                 },
398                 {
399                         'id' : 'type',
400                         'label' : document.getElementById('circStrings').getString('staff.circ.utils.offline.type'),
401                         'flex' : 1,
402                         'primary' : false,
403                         'hidden' : true,
404                         'render' : function(my) { return my.type; }
405                 },
406                 {
407                         'id' : 'count',
408                         'label' : document.getElementById('circStrings').getString('staff.circ.utils.offline.count'),
409                         'sort_type' : 'number',
410                         'flex' : 1,
411                         'primary' : false,
412                         'hidden' : false,
413                         'render' : function(my) { return my.count; }
414                 },
415                 {
416                         'id' : 'barcode',
417                         'label' : document.getElementById('circStrings').getString('staff.circ.utils.offline.item_barcode'),
418                         'flex' : 2,
419                         'primary' : true,
420                         'hidden' : false,
421                         'render' : function(my) { return my.barcode; }
422                 }
423         ];
424         if (modify) for (var i = 0; i < c.length; i++) {
425                 if (modify[ c[i].id ]) {
426                         for (var j in modify[ c[i].id ]) {
427                                 c[i][j] = modify[ c[i].id ][j];
428                         }
429                 }
430         }
431         if (params) {
432                 if (params.just_these) {
433                         JSAN.use('util.functional');
434                         var new_c = [];
435                         for (var i = 0; i < params.just_these.length; i++) {
436                                 var x = util.functional.find_list(c,function(d){return(d.id==params.just_these[i]);});
437                                 new_c.push( function(y){ return y; }( x ) );
438                         }
439                         c = new_c;
440                 }
441                 if (params.except_these) {
442                         JSAN.use('util.functional');
443                         var new_c = [];
444                         for (var i = 0; i < c.length; i++) {
445                                 var x = util.functional.find_list(params.except_these,function(d){return(d==c[i].id);});
446                                 if (!x) new_c.push(c[i]);
447                         }
448                         c = new_c;
449                 }
450
451         }
452         return c.sort( function(a,b) { if (a.label < b.label) return -1; if (a.label > b.label) return 1; return 0; } );
453 };
454
455 circ.util.columns = function(modify,params) {
456         
457         JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.init({'via':'stash'});
458         JSAN.use('util.network'); var network = new util.network();
459         JSAN.use('util.money');
460
461         var c = [
462                 {
463                         'id' : 'acp_id',
464                         'label' : document.getElementById('commonStrings').getString('staff.acp_label_id'),
465                         'flex' : 1,
466                         'primary' : false,
467                         'hidden' : true,
468                         'render' : function(my) { return my.acp.id(); },
469                         'persist' : 'hidden width ordinal'
470                 },
471                 {
472                         'id' : 'circ_id',
473                         'label' : document.getElementById('commonStrings').getString('staff.circ_label_id'),
474                         'flex' : 1,
475                         'primary' : false,
476                         'hidden' : true,
477                         'render' : function(my) { return my.circ ? my.circ.id() : ( my.acp.circulations() ? my.acp.circulations()[0].id() : ""); },
478                         'persist' : 'hidden width ordinal'
479                 },
480                 {
481                         'id' : 'mvr_doc_id',
482                         'label' : document.getElementById('commonStrings').getString('staff.mvr_label_doc_id'),
483                         'flex' : 1,
484                         'primary' : false,
485                         'hidden' : true,
486                         'render' : function(my) { return my.mvr.doc_id(); },
487                         'persist' : 'hidden width ordinal'
488                 },
489         {
490                         'persist' : 'hidden width ordinal',
491                         'id' : 'service',
492                         'label' : 'Service',
493                         'flex' : 1,
494                         'primary' : false,
495                         'hidden' : true,
496                         'render' : function(my) { return my.service; }
497         },
498                 {
499                         'id' : 'barcode',
500                         'label' : document.getElementById('commonStrings').getString('staff.acp_label_barcode'),
501                         'flex' : 1,
502                         'primary' : false,
503                         'hidden' : true,
504                         'render' : function(my) { return my.acp.barcode(); },
505                         'persist' : 'hidden width ordinal'
506                 },
507                 {
508                         'id' : 'call_number',
509                         'label' : document.getElementById('commonStrings').getString('staff.acp_label_call_number'),
510                         'flex' : 1,
511                         'primary' : false,
512                         'hidden' : true,
513                         'render' : function(my) {
514                                 if (my.acp && my.acp.call_number() == -1) {
515                                         return document.getElementById('circStrings').getString('staff.circ.utils.not_cataloged');
516                                 } else if (my.acp && my.acp.call_number() == -2) {
517                                         return document.getElementById('circStrings').getString('staff.circ.utils.retrieving');
518                                 } else {
519                                         if (!my.acn) {
520                                                 var x = network.simple_request("FM_ACN_RETRIEVE.authoritative",[ my.acp.call_number() ]);
521                                                 if (x.ilsevent) {
522                                                         return document.getElementById('circStrings').getString('staff.circ.utils.not_cataloged');
523                                                 } else {
524                                                         my.acn = x; return x.label();
525                                                 }
526                                         } else {
527                                                 return my.acn.label();
528                                         }
529                                 }
530                         },
531                         'persist' : 'hidden width ordinal'
532                 },
533                 {
534                         'id' : 'owning_lib',
535                         'label' : document.getElementById('circStrings').getString('staff.circ.utils.owning_lib'),
536                         'flex' : 1,
537                         'primary' : false,
538                         'hidden' : true,
539                         'render' : function(my) {
540                                 if (Number(my.acn.owning_lib())>=0) {
541                                         return data.hash.aou[ my.acn.owning_lib() ].shortname();
542                                 } else {
543                                         return my.acn.owning_lib().shortname();
544                                 }
545                         },
546                         'persist' : 'hidden width ordinal'
547                 },
548                 {
549                         'id' : 'copy_number',
550                         'label' : document.getElementById('commonStrings').getString('staff.acp_label_copy_number'),
551                         'flex' : 1,
552                         'sort_type' : 'number',
553                         'primary' : false,
554                         'hidden' : true,
555                         'render' : function(my) { return my.acp.copy_number(); },
556                         'persist' : 'hidden width ordinal'
557                 },
558                 {
559                         'id' : 'location',
560                         'label' : document.getElementById('commonStrings').getString('staff.acp_label_location'),
561                         'flex' : 1,
562                         'primary' : false,
563                         'hidden' : true,
564                         'render' : function(my) {
565                                 if (Number(my.acp.location())>=0) {
566                                         return data.lookup("acpl", my.acp.location() ).name();
567                                 } else {
568                                         return my.acp.location().name();
569                                 }
570                         },
571                         'persist' : 'hidden width ordinal'
572                 },
573                 {
574                         'id' : 'loan_duration',
575                         'label' : document.getElementById('commonStrings').getString('staff.acp_label_loan_duration'),
576                         'flex' : 1,
577                         'primary' : false,
578                         'hidden' : true,
579                         'render' : function(my) {
580                                 switch(Number(my.acp.loan_duration())) {
581                                         case 1:
582                                                 return document.getElementById('circStrings').getString('staff.circ.utils.loan_duration.short');
583                                                 break;
584                                         case 2:
585                                                 return document.getElementById('circStrings').getString('staff.circ.utils.loan_duration.normal');
586                                                 break;
587                                         case 3:
588                                                 return document.getElementById('circStrings').getString('staff.circ.utils.loan_duration.long');
589                                                 break;
590                                 };
591                         },
592                         'persist' : 'hidden width ordinal'
593                 },
594                 {
595                         'id' : 'circ_lib',
596                         'label' : document.getElementById('commonStrings').getString('staff.acp_label_circ_lib'),
597                         'flex' : 1,
598                         'primary' : false,
599                         'hidden' : true,
600                         'render' : function(my) {
601                                 if (Number(my.acp.circ_lib())>=0) {
602                                         return data.hash.aou[ my.acp.circ_lib() ].shortname();
603                                 } else {
604                                         return my.acp.circ_lib().shortname();
605                                 }
606                         },
607                         'persist' : 'hidden width ordinal'
608                 },
609                 {
610                         'id' : 'fine_level',
611                         'label' : document.getElementById('commonStrings').getString('staff.acp_label_fine_level'),
612                         'flex' : 1,
613                         'primary' : false,
614                         'hidden' : true,
615                         'render' : function(my) {
616                                 switch(Number(my.acp.fine_level())) {
617                                         case 1:
618                                                 return document.getElementById('circStrings').getString('staff.circ.utils.fine_level.low');
619                                                 break;
620                                         case 2:
621                                                 return document.getElementById('circStrings').getString('staff.circ.utils.fine_level.normal');
622                                                 break;
623                                         case 3:
624                                                 return document.getElementById('circStrings').getString('staff.circ.utils.fine_level.high');
625                                                 break;
626                                 };
627                         },
628                         'persist' : 'hidden width ordinal'
629                 },
630                 {
631                         'id' : 'circulate',
632                         'label' : document.getElementById('circStrings').getString('staff.circ.utils.circulate'),
633                         'flex' : 1,
634                         'primary' : false,
635                         'hidden' : true,
636                         'render' : function(my) {
637                                 if (get_bool( my.acp.circulate() )) {
638                                         return document.getElementById('circStrings').getString('staff.circ.utils.yes');
639                                 } else {
640                                         return document.getElementById('circStrings').getString('staff.circ.utils.no');
641                                 }
642                         },
643                         'persist' : 'hidden width ordinal'
644                 },
645                 {
646                         'id' : 'deleted',
647                         'label' : document.getElementById('circStrings').getString('staff.circ.utils.deleted'),
648                         'flex' : 1,
649                         'primary' : false,
650                         'hidden' : true,
651                         'render' : function(my) {
652                                 if (get_bool( my.acp.deleted() )) {
653                                         return document.getElementById('circStrings').getString('staff.circ.utils.yes');
654                                 } else {
655                                         return document.getElementById('circStrings').getString('staff.circ.utils.no');
656                                 }
657                         },
658                         'persist' : 'hidden width ordinal'
659                 },
660                 {
661                         'id' : 'holdable',
662                         'label' : document.getElementById('circStrings').getString('staff.circ.utils.holdable'),
663                         'flex' : 1,
664                         'primary' : false,
665                         'hidden' : true,
666                         'render' : function(my) {
667                                 if (get_bool( my.acp.holdable() )) {
668                                         return document.getElementById('circStrings').getString('staff.circ.utils.yes');
669                                 } else {
670                                         return document.getElementById('circStrings').getString('staff.circ.utils.no');
671                                 }
672                         },
673                         'persist' : 'hidden width ordinal'
674                 },
675                 {
676                         'id' : 'opac_visible',
677                         'label' : document.getElementById('circStrings').getString('staff.circ.utils.opac_visible'),
678                         'flex' : 1,
679                         'primary' : false,
680                         'hidden' : true,
681                         'render' : function(my) {
682                                 if (get_bool( my.acp.opac_visible() )) {
683                                         return document.getElementById('circStrings').getString('staff.circ.utils.yes');
684                                 } else {
685                                         return document.getElementById('circStrings').getString('staff.circ.utils.no');
686                                 }
687                         },
688                         'persist' : 'hidden width ordinal'
689                 },
690                 {
691                         'persist' : 'hidden width ordinal',
692                         'id' : 'ref',
693                         'label' : document.getElementById('circStrings').getString('staff.circ.utils.reference'),
694                         'flex' : 1,
695                         'primary' : false,
696                         'hidden' : true,
697                         'render' : function(my) {
698                                 if (get_bool( my.acp.ref() )) {
699                                         return document.getElementById('circStrings').getString('staff.circ.utils.yes');
700                                 } else {
701                                         return document.getElementById('circStrings').getString('staff.circ.utils.no');
702                                 }
703                         }
704                 },
705                 {
706                         'persist' : 'hidden width ordinal',
707                         'id' : 'deposit',
708                         'label' : document.getElementById('circStrings').getString('staff.circ.utils.deposit'),
709                         'flex' : 1,
710                         'primary' : false,
711                         'hidden' : true,
712                         'render' : function(my) {
713                                 if (get_bool( my.acp.deposit() )) {
714                                         return document.getElementById('circStrings').getString('staff.circ.utils.yes');
715                                 } else {
716                                         return document.getElementById('circStrings').getString('staff.circ.utils.no');
717                                 }
718                         }
719                 },
720                 {
721                         'persist' : 'hidden width ordinal',
722                         'id' : 'deposit_amount',
723                         'label' : document.getElementById('commonStrings').getString('staff.acp_label_deposit_amount'),
724                         'flex' : 1,
725                         'primary' : false,
726                         'hidden' : true,
727                         'render' : function(my) {
728                                 if (my.acp.price() == null) {
729                                         return document.getElementById('circStrings').getString('staff.circ.utils.unset');
730                                 } else {
731                                         return util.money.sanitize(my.acp.deposit_amount());
732                                 }
733                         },
734                         'sort_type' : 'money'
735                 },
736                 {
737                         'persist' : 'hidden width ordinal',
738                         'id' : 'price',
739                         'label' : document.getElementById('commonStrings').getString('staff.acp_label_price'),
740                         'flex' : 1,
741                         'primary' : false,
742                         'hidden' : true,
743                         'render' : function(my) {
744                                 if (my.acp.price() == null) {
745                                         return document.getElementById('circStrings').getString('staff.circ.utils.unset');
746                                 } else {
747                                         return util.money.sanitize(my.acp.price());
748                                 }
749                         },
750                         'sort_type' : 'money'
751                 },
752                 {
753                         'persist' : 'hidden width ordinal',
754                         'id' : 'circ_as_type',
755                         'label' : document.getElementById('commonStrings').getString('staff.acp_label_circ_as_type'),
756                         'flex' : 1,
757                         'primary' : false,
758                         'hidden' : true,
759                         'render' : function(my) { return my.acp.circ_as_type(); }
760                 },
761                 {
762                         'persist' : 'hidden width ordinal',
763                         'id' : 'circ_modifier',
764                         'label' : document.getElementById('commonStrings').getString('staff.acp_label_circ_modifier'),
765                         'flex' : 1,
766                         'primary' : false,
767                         'hidden' : true,
768                         'render' : function(my) { return my.acp.circ_modifier(); }
769                 },
770                 {
771                         'persist' : 'hidden width ordinal',
772                         'id' : 'checkout_lib',
773                         'label' : document.getElementById('circStrings').getString('staff.circ.utils.checkout_lib'),
774                         'flex' : 1,
775                         'primary' : false,
776                         'hidden' : true,
777                         'render' : function(my) {
778                                 if (my.circ) {
779                                         return data.hash.aou[ my.circ.circ_lib() ].shortname();
780                                 } else {
781                                         if (my.acp.circulations()) {
782                                                 return data.hash.aou[ my.acp.circulations()[0].circ_lib() ].shortname();
783                                         } else {
784                                                 return "";
785                                         }
786                                 }
787                         }
788                 },
789                 {
790                         'persist' : 'hidden width ordinal',
791                         'id' : 'xact_start_full',
792                         'label' : document.getElementById('circStrings').getString('staff.circ.utils.checkout_timestamp'),
793                         'flex' : 1,
794                         'primary' : false,
795                         'hidden' : true,
796                         'render' : function(my) {
797                                 if (my.circ) {
798                                         return my.circ.xact_start();
799                                 } else {
800                                         if (my.acp.circulations()) {
801                                                 return my.acp.circulations()[0].xact_start();
802                                         }
803                                         else {
804                                                 return  "";
805                                         }
806                                 }
807                         }
808                 },
809                 {
810                         'persist' : 'hidden width ordinal',
811                         'id' : 'checkin_time_full',
812                         'label' : document.getElementById('circStrings').getString('staff.circ.utils.checkin_timestamp'),
813                         'flex' : 1,
814                         'primary' : false,
815                         'hidden' : true,
816                         'render' : function(my) {
817                                 if (my.circ) {
818                                         return my.circ.checkin_time();
819                                 } else {
820                                         if (my.acp.circulations()) {
821                                                 return my.acp.circulations()[0].checkin_time();
822                                         } else {
823                                                 return "";
824                                         }
825                                 }
826                         }
827                 },
828                 {
829                         'persist' : 'hidden width ordinal',
830                         'id' : 'xact_start',
831                         'label' : document.getElementById('circStrings').getString('staff.circ.utils.xact_start'),
832                         'flex' : 1,
833                         'primary' : false,
834                         'hidden' : true,
835                         'render' : function(my) {
836                                 if (my.circ) {
837                                         return my.circ.xact_start().substr(0,10);
838                                 } else {
839                                         if (my.acp.circulations()) {
840                                                 return my.acp.circulations()[0].xact_start().substr(0,10);
841                                         } else {
842                                                 return "";
843                                         }
844                                 }
845                         }
846                 },
847                 {
848                         'persist' : 'hidden width ordinal',
849                         'id' : 'checkin_time',
850                         'label' : document.getElementById('circStrings').getString('staff.circ.utils.checkin_time'),
851                         'flex' : 1,
852                         'primary' : false,
853                         'hidden' : true,
854                         'render' : function(my) {
855                                 if (my.circ) {
856                                         return my.circ.checkin_time().substr(0,10);
857                                 } else {
858                                         if (my.acp.circulations()) {
859                                                 return my.acp.circulations()[0].checkin_time().substr(0,10);
860                                         } else {
861                                                 return "";
862                                         }
863                                 }
864                         }
865                 },
866                 {
867                         'persist' : 'hidden width ordinal',
868                         'id' : 'xact_finish',
869                         'label' : document.getElementById('circStrings').getString('staff.circ.utils.xact_finish'),
870                         'flex' : 1,
871                         'primary' : false,
872                         'hidden' : true,
873                         'render' : function(my) { return my.circ.xact_finish(); }
874                 },
875                 {
876                         'persist' : 'hidden width ordinal',
877                         'id' : 'due_date',
878                         'label' : document.getElementById('commonStrings').getString('staff.circ_label_due_date'),
879                         'flex' : 1,
880                         'primary' : false,
881                         'hidden' : true,
882                         'render' : function(my) {
883                                 if (my.circ) {
884                                         return my.circ.due_date().substr(0,10);
885                                 } else {
886                                         if (my.acp.circulations()) {
887                                                 return my.acp.circulations()[0].due_date().substr(0,10);
888                                         } else {
889                                                 return "";
890                                         }
891                                 }
892                         }
893                 },
894                 {
895                         'persist' : 'hidden width ordinal',
896                         'id' : 'create_date',
897                         'label' : document.getElementById('circStrings').getString('staff.circ.utils.create_date'),
898                         'flex' : 1,
899                         'primary' : false,
900                         'hidden' : true,
901                         'render' : function(my) { return my.acp.create_date().substr(0,10); }
902                 },
903                 {
904                         'persist' : 'hidden width ordinal',
905                         'id' : 'edit_date',
906                         'label' : document.getElementById('circStrings').getString('staff.circ.utils.edit_date'),
907                         'flex' : 1,
908                         'primary' : false,
909                         'hidden' : true,
910                         'render' : function(my) { return my.acp.edit_date().substr(0,10); }
911                 },
912                 {
913                         'persist' : 'hidden width ordinal',
914                         'id' : 'title',
915                         'label' : document.getElementById('commonStrings').getString('staff.mvr_label_title'),
916                         'flex' : 2,
917                         'sort_type' : 'title',
918                         'primary' : false,
919                         'hidden' : true,
920                         'render' : function(my) {
921                                 try {  return my.mvr.title(); }
922                                 catch(E) { return my.acp.dummy_title(); }
923                         }
924                 },
925                 {
926                         'persist' : 'hidden width ordinal',
927                         'id' : 'author',
928                         'label' : document.getElementById('commonStrings').getString('staff.mvr_label_author'),
929                         'flex' : 1,
930                         'primary' : false,
931                         'hidden' : true,
932                         'render' : function(my) {
933                                 try { return my.mvr.author(); }
934                                 catch(E) { return my.acp.dummy_author(); }
935                         }
936                 },
937                 {
938                         'persist' : 'hidden width ordinal',
939                         'id' : 'edition',
940                         'label' : document.getElementById('circStrings').getString('staff.circ.utils.edition'),
941                         'flex' : 1,
942                         'primary' : false,
943                         'hidden' : true,
944                         'render' : function(my) { return my.mvr.edition(); }
945                 },
946                 {
947                         'persist' : 'hidden width ordinal',
948                         'id' : 'isbn',
949                         'label' : document.getElementById('circStrings').getString('staff.circ.utils.isbn'),
950                         'flex' : 1,
951                         'primary' : false,
952                         'hidden' : true,
953                         'render' : function(my) { return my.mvr.isbn(); }
954                 },
955                 {
956                         'persist' : 'hidden width ordinal',
957                         'id' : 'pubdate',
958                         'label' : document.getElementById('circStrings').getString('staff.circ.utils.pubdate'),
959                         'flex' : 1,
960                         'primary' : false,
961                         'hidden' : true,
962                         'render' : function(my) { return my.mvr.pubdate(); }
963                 },
964                 {
965                         'persist' : 'hidden width ordinal',
966                         'id' : 'publisher',
967                         'label' : document.getElementById('circStrings').getString('staff.circ.utils.publisher'),
968                         'flex' : 1,
969                         'primary' : false,
970                         'hidden' : true,
971                         'render' : function(my) { return my.mvr.publisher(); }
972                 },
973                 {
974                         'persist' : 'hidden width ordinal',
975                         'id' : 'tcn',
976                         'label' : document.getElementById('circStrings').getString('staff.circ.utils.tcn'),
977                         'flex' : 1,
978                         'primary' : false,
979                         'hidden' : true,
980                         'render' : function(my) { return my.mvr.tcn(); }
981                 },
982                 {
983                         'persist' : 'hidden width ordinal',
984                         'id' : 'renewal_remaining',
985                         'label' : document.getElementById('commonStrings').getString('staff.circ_label_renewal_remaining'),
986                         'flex' : 0,
987                         'primary' : false,
988                         'hidden' : true,
989                         'render' : function(my) {
990                                 if (my.circ) {
991                                         return my.circ.renewal_remaining();
992                                 } else {
993                                         if (my.acp.circulations()) {
994                                                 return my.acp.circulations()[0].renewal_remaining();
995                                         } else {
996                                                 return "";
997                                         }
998                                 }
999                         },
1000                         'sort_type' : 'number'
1001                 },
1002                 {
1003                         'persist' : 'hidden width ordinal',
1004                         'id' : 'stop_fines',
1005                         'label' : document.getElementById('circStrings').getString('staff.circ.utils.stop_fines'),
1006                         'flex' : 0,
1007                         'primary' : false,
1008                         'hidden' : true,
1009                         'render' : function(my) {
1010                                 if (my.circ) {
1011                                         return my.circ.stop_fines();
1012                                 } else {
1013                                         if (my.acp.circulations()) {
1014                                                 return my.acp.circulations()[0].stop_fines();
1015                                         } else {
1016                                                 return "";
1017                                         }
1018                                 }
1019                         }
1020                 },
1021                 {
1022                         'persist' : 'hidden width ordinal',
1023                         'id' : 'stop_fines_time',
1024                         'label' : document.getElementById('circStrings').getString('staff.circ.utils.stop_fines_time'),
1025                         'flex' : 0,
1026                         'primary' : false,
1027                         'hidden' : true,
1028                         'render' : function(my) {
1029                                 if (my.circ) {
1030                                         return my.circ.stop_fines_time();
1031                                 } else {
1032                                         if (my.acp.circulations()) {
1033                                                 return my.acp.circulations()[0].stop_fines_time();
1034                                         } else {
1035                                                 return "";
1036                                         }
1037                                 }
1038                         }
1039                 },
1040                 {
1041                         'persist' : 'hidden width ordinal',
1042                         'id' : 'status',
1043                         'label' : document.getElementById('commonStrings').getString('staff.acp_label_status'),
1044                         'flex' : 1,
1045                         'primary' : false,
1046                         'hidden' : true,
1047                         'render' : function(my) {
1048                                 if (Number(my.acp.status())>=0) {
1049                                         return data.hash.ccs[ my.acp.status() ].name();
1050                                 } else {
1051                                         return my.acp.status().name();
1052                                 }
1053                         }
1054                 },
1055                 {
1056                         'persist' : 'hidden width ordinal',
1057                         'id' : 'route_to',
1058                         'label' : document.getElementById('circStrings').getString('staff.circ.utils.route_to'),
1059                         'flex' : 1,
1060                         'primary' : false,
1061                         'hidden' : true,
1062                         'render' : function(my) { return my.route_to.toString(); }
1063                 },
1064                 {
1065                         'persist' : 'hidden width ordinal',
1066                         'id' : 'message',
1067                         'label' : document.getElementById('circStrings').getString('staff.circ.utils.message'),
1068                         'flex' : 1,
1069                         'primary' : false,
1070                         'hidden' : true,
1071                         'render' : function(my) { return my.message.toString(); }
1072                 },
1073                 {
1074                         'persist' : 'hidden width ordinal',
1075                         'id' : 'uses',
1076                         'label' : document.getElementById('circStrings').getString('staff.circ.utils.uses'),
1077                         'flex' : 1,
1078                         'primary' : false,
1079                         'hidden' : true,
1080                         'render' : function(my) { return my.uses; },
1081                         'sort_type' : 'number'
1082                 },
1083                 {
1084                         'persist' : 'hidden width ordinal',
1085                         'id' : 'alert_message',
1086                         'label' : document.getElementById('circStrings').getString('staff.circ.utils.alert_message'),
1087                         'flex' : 1,
1088                         'primary' : false,
1089                         'hidden' : true,
1090                         'render' : function(my) { return my.acp.alert_message(); }
1091                 }
1092         ];
1093         for (var i = 0; i < c.length; i++) {
1094                 if (modify[ c[i].id ]) {
1095                         for (var j in modify[ c[i].id ]) {
1096                                 c[i][j] = modify[ c[i].id ][j];
1097                         }
1098                 }
1099         }
1100         if (params) {
1101                 if (params.just_these) {
1102                         JSAN.use('util.functional');
1103                         var new_c = [];
1104                         for (var i = 0; i < params.just_these.length; i++) {
1105                                 var x = util.functional.find_list(c,function(d){return(d.id==params.just_these[i]);});
1106                                 new_c.push( function(y){ return y; }( x ) );
1107                         }
1108                         c = new_c;
1109                 }
1110                 if (params.except_these) {
1111                         JSAN.use('util.functional');
1112                         var new_c = [];
1113                         for (var i = 0; i < c.length; i++) {
1114                                 var x = util.functional.find_list(params.except_these,function(d){return(d==c[i].id);});
1115                                 if (!x) new_c.push(c[i]);
1116                         }
1117                         c = new_c;
1118                 }
1119         }
1120         return c.sort( function(a,b) { if (a.label < b.label) return -1; if (a.label > b.label) return 1; return 0; } );
1121 };
1122
1123 circ.util.transit_columns = function(modify,params) {
1124         
1125         JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.init({'via':'stash'});
1126
1127         var c = [
1128                 {
1129                         'persist' : 'hidden width ordinal',
1130                         'id' : 'transit_item_barcode',
1131                         'label' : document.getElementById('circStrings').getString('staff.circ.utils.barcode'),
1132                         'flex' : 1,
1133                         'primary' : false,
1134                         'hidden' : true,
1135                         'render' : function(my) { return my.acp.barcode(); }
1136                 },
1137                 {
1138                         'persist' : 'hidden width ordinal',
1139                         'id' : 'transit_item_title',
1140                         'label' : document.getElementById('circStrings').getString('staff.circ.utils.title'),
1141                         'flex' : 1,
1142                         'primary' : false,
1143                         'hidden' : true,
1144                         'render' : function(my) {
1145                                 try { return my.mvr.title(); }
1146                                 catch(E) { return my.acp.dummy_title(); }
1147                         }
1148                 },
1149                 {
1150                         'persist' : 'hidden width ordinal',
1151                         'id' : 'transit_item_author',
1152                         'label' : document.getElementById('circStrings').getString('staff.circ.utils.author'),
1153                         'flex' : 1,
1154                         'primary' : false,
1155                         'hidden' : true,
1156                         'render' : function(my) {
1157                                 try { return my.mvr.author(); }
1158                                 catch(E) { return my.acp.dummy_author(); }
1159                         }
1160                 },
1161                 {
1162                         'persist' : 'hidden width ordinal',
1163                         'id' : 'transit_item_callnumber',
1164                         'label' : document.getElementById('circStrings').getString('staff.circ.utils.callnumber'),
1165                         'flex' : 1,
1166                         'primary' : false,
1167                         'hidden' : true,
1168                         'render' : function(my) { return my.acn.label(); }
1169                 },
1170                 {
1171                         'persist' : 'hidden width ordinal',
1172                         'id' : 'transit_id',
1173                         'label' : document.getElementById('circStrings').getString('staff.circ.utils.transit_id'),
1174                         'flex' : 1,
1175                         'primary' : false,
1176                         'hidden' : true,
1177                         'render' : function(my) { return my.atc.id(); }
1178                 },
1179                 {
1180                         'persist' : 'hidden width ordinal',
1181                         'id' : 'transit_source',
1182                         'label' : document.getElementById('circStrings').getString('staff.circ.utils.transit_source'),
1183                         'flex' : 1,
1184                         'primary' : false,
1185                         'hidden' : false,
1186                         'render' : function(my) {
1187                                 if (typeof my.atc.source() == "object") {
1188                                         return my.atc.source().shortname();
1189                                 } else {
1190                                         return data.hash.aou[ my.atc.source() ].shortname();
1191                                 }
1192                         }
1193                 },
1194                 {
1195                         'persist' : 'hidden width ordinal',
1196                         'id' : 'transit_source_send_time',
1197                         'label' : document.getElementById('circStrings').getString('staff.circ.utils.transit_source_send_time'),
1198                         'flex' : 1,
1199                         'primary' : false,
1200                         'hidden' : false,
1201                         'render' : function(my) { return my.atc.source_send_time(); }
1202                 },
1203                 {
1204                         'persist' : 'hidden width ordinal',
1205                         'id' : 'transit_dest_lib',
1206                         'label' : document.getElementById('circStrings').getString('staff.circ.utils.transit_dest'),
1207                         'flex' : 1,
1208                         'primary' : false,
1209                         'hidden' : false,
1210                         'render' : function(my) {
1211                                 if (typeof my.atc.dest() == "object") {
1212                                         return my.atc.dest().shortname();
1213                                 } else {
1214                                         return data.hash.aou[ my.atc.dest() ].shortname();
1215                                 }
1216                         }
1217                 },
1218                 {
1219                         'persist' : 'hidden width ordinal',
1220                         'id' : 'transit_dest_recv_time',
1221                         'label' : document.getElementById('circStrings').getString('staff.circ.utils.transit_dest_recv_time'),
1222                         'flex' : 1,
1223                         'primary' : false,
1224                         'hidden' : false,
1225                         'render' : function(my) { return my.atc.dest_recv_time(); }
1226                 },
1227                 {
1228                         'persist' : 'hidden width ordinal',
1229                         'id' : 'transit_target_copy',
1230                         'label' : document.getElementById('circStrings').getString('staff.circ.utils.transit_target_copy'),
1231                         'flex' : 1,
1232                         'primary' : false,
1233                         'hidden' : true,
1234                         'render' : function(my) { return my.atc.target_copy(); }
1235                 },
1236         ];
1237         for (var i = 0; i < c.length; i++) {
1238                 if (modify[ c[i].id ]) {
1239                         for (var j in modify[ c[i].id ]) {
1240                                 c[i][j] = modify[ c[i].id ][j];
1241                         }
1242                 }
1243         }
1244         if (params) {
1245                 if (params.just_these) {
1246                         JSAN.use('util.functional');
1247                         var new_c = [];
1248                         for (var i = 0; i < params.just_these.length; i++) {
1249                                 var x = util.functional.find_list(c,function(d){return(d.id==params.just_these[i]);});
1250                                 new_c.push( function(y){ return y; }( x ) );
1251                         }
1252                         c = new_c;
1253                 }
1254                 if (params.except_these) {
1255                         JSAN.use('util.functional');
1256                         var new_c = [];
1257                         for (var i = 0; i < c.length; i++) {
1258                                 var x = util.functional.find_list(params.except_these,function(d){return(d==c[i].id);});
1259                                 if (!x) new_c.push(c[i]);
1260                         }
1261                         c = new_c;
1262                 }
1263
1264         }
1265         return c.sort( function(a,b) { if (a.label < b.label) return -1; if (a.label > b.label) return 1; return 0; } );
1266 };
1267
1268 circ.util.hold_columns = function(modify,params) {
1269         
1270         JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.init({'via':'stash'});
1271
1272         var c = [
1273                 {
1274                         'persist' : 'hidden width ordinal',
1275                         'id' : 'request_lib',
1276                         'label' : document.getElementById('circStrings').getString('staff.circ.utils.request_lib'),
1277                         'flex' : 1,
1278                         'primary' : false,
1279                         'hidden' : true,
1280                         'render' : function(my) {
1281                                 if (Number(my.ahr.request_lib())>=0) {
1282                                         return data.hash.aou[ my.ahr.request_lib() ].name();
1283                                 } else {
1284                                         return my.ahr.request_lib().name();
1285                                 }
1286                         }
1287                 },
1288                 {
1289                         'persist' : 'hidden width ordinal',
1290                         'id' : 'request_lib_shortname',
1291                         'label' : document.getElementById('circStrings').getString('staff.circ.utils.request_lib_shortname'),
1292                         'flex' : 0,
1293                         'primary' : false,
1294                         'hidden' : true,
1295                         'render' : function(my) {
1296                                 if (Number(my.ahr.request_lib())>=0) {
1297                                         return data.hash.aou[ my.ahr.request_lib() ].shortname();
1298                                 } else {
1299                                         return my.ahr.request_lib().shortname();
1300                                 }
1301                         }
1302                 },
1303
1304                 {
1305                         'persist' : 'hidden width ordinal',
1306                         'id' : 'request_timestamp',
1307                         'label' : document.getElementById('circStrings').getString('staff.circ.utils.request_timestamp'),
1308                         'flex' : 0,
1309                         'primary' : false,
1310                         'hidden' : true,
1311                         'render' : function(my) { return my.ahr.request_time().toString(); }
1312                 },
1313                 {
1314                         'persist' : 'hidden width ordinal',
1315                         'id' : 'request_time',
1316                         'label' : document.getElementById('circStrings').getString('staff.circ.utils.request_time'),
1317                         'flex' : 0,
1318                         'primary' : false,
1319                         'hidden' : true,
1320                         'render' : function(my) { return my.ahr.request_time().toString().substr(0,10); }
1321                 },
1322                 {
1323                         'persist' : 'hidden width ordinal',
1324                         'id' : 'available_timestamp',
1325                         'label' : document.getElementById('circStrings').getString('staff.circ.utils.available_timestamp'),
1326                         'flex' : 1,
1327                         'primary' : false,
1328                         'hidden' : true,
1329                         'render' : function(my) {
1330                                 if (my.ahr.transit() && my.ahr.transit().dest_recv_time()) {
1331                                         return my.ahr.transit().dest_recv_time().toString();
1332                                 }
1333                                 if (my.ahr.capture_time()) {
1334                                         return my.ahr.capture_time().toString();
1335                                 }
1336                                 return "";
1337                         }
1338                 },
1339                 {
1340                         'persist' : 'hidden width ordinal',
1341                         'id' : 'available_time',
1342                         'label' : document.getElementById('circStrings').getString('staff.circ.utils.available_time'),
1343                         'flex' : 1,
1344                         'primary' : false,
1345                         'hidden' : false,
1346                         'render' : function(my) {
1347                                 if (my.ahr.transit() && my.ahr.transit().dest_recv_time()) {
1348                                         return my.ahr.transit().dest_recv_time().toString().substr(0,10);
1349                                 }
1350                                 if (my.ahr.capture_time()) {
1351                                         return my.ahr.capture_time().toString().substr(0,10);
1352                                 }
1353                                 return "";
1354                         }
1355                 },
1356                 {
1357                         'persist' : 'hidden width ordinal',
1358                         'id' : 'capture_timestamp',
1359                         'label' : document.getElementById('circStrings').getString('staff.circ.utils.capture_timestamp'),
1360                         'flex' : 1,
1361                         'primary' : false,
1362                         'hidden' : true,
1363                         'render' : function(my) { return my.ahr.capture_time() ? my.ahr.capture_time().toString() : ""; }
1364                 },
1365                 {
1366                         'persist' : 'hidden width ordinal',
1367                         'id' : 'capture_time',
1368                         'label' : document.getElementById('circStrings').getString('staff.circ.utils.capture_time'),
1369                         'flex' : 1,
1370                         'primary' : false,
1371                         'hidden' : true,
1372                         'render' : function(my) { return my.ahr.capture_time() ? my.ahr.capture_time().toString().substr(0,10) : ""; }
1373                 },
1374                 {
1375                         'persist' : 'hidden width ordinal',
1376                         'id' : 'status',
1377                         'label' : document.getElementById('commonStrings').getString('staff.ahr_status_label'),
1378                         'flex' : 1,
1379                         'primary' : false,
1380                         'hidden' : false,
1381                         'render' : function(my) {
1382                                 switch (Number(my.status)) {
1383                                         case 1:
1384                                                 return document.getElementById('circStrings').getString('staff.circ.utils.hold_status.1');
1385                                                 break;
1386                                         case 2:
1387                                                 return document.getElementById('circStrings').getString('staff.circ.utils.hold_status.2');
1388                                                 break;
1389                                         case 3:
1390                                                 return document.getElementById('circStrings').getString('staff.circ.utils.hold_status.3');
1391                                                 break;
1392                                         case 4:
1393                                                 return document.getElementById('circStrings').getString('staff.circ.utils.hold_status.4');
1394                                                 break;
1395                                         default:
1396                                                 return my.status;
1397                                                 break;
1398                                 };
1399                         }
1400                 },
1401                 {
1402                         'persist' : 'hidden width ordinal',
1403                         'id' : 'hold_type',
1404                         'label' : document.getElementById('commonStrings').getString('staff.ahr_hold_type_label'),
1405                         'flex' : 0,
1406                         'primary' : false,
1407                         'hidden' : true,
1408                         'render' : function(my) { return my.ahr.hold_type(); }
1409                 },
1410         {
1411                         'persist' : 'hidden width ordinal',
1412                         'id' : 'frozen',
1413                         'label' : document.getElementById('circStrings').getString('staff.circ.utils.active'),
1414                         'flex' : 0,
1415                         'primary' : false,
1416                         'hidden' : true,
1417                         'render' : function(my) {
1418                                 if (!get_bool( my.ahr.frozen() )) {
1419                                         return document.getElementById('circStrings').getString('staff.circ.utils.yes');
1420                                 } else {
1421                                         return document.getElementById('circStrings').getString('staff.circ.utils.no');
1422                                 }
1423                         }
1424         },
1425         {
1426                         'persist' : 'hidden width ordinal',
1427                         'id' : 'thaw_date',
1428                         'label' : document.getElementById('circStrings').getString('staff.circ.utils.thaw_date'),
1429                         'flex' : 0,
1430                         'primary' : false,
1431                         'hidden' : true,
1432                         'render' : function(my) {
1433                                 if (my.ahr.thaw_date() == null) {
1434                                         return document.getElementById('circStrings').getString('staff.circ.utils.thaw_date.none');
1435                                 } else {
1436                                         return my.ahr.thaw_date().substr(0,10);
1437                                 }
1438                         }
1439         },
1440                 {
1441                         'persist' : 'hidden width ordinal',
1442                         'id' : 'pickup_lib',
1443                         'label' : document.getElementById('circStrings').getString('staff.circ.utils.pickup_lib'),
1444                         'flex' : 1,
1445                         'primary' : false,
1446                         'hidden' : true,
1447                         'render' : function(my) {
1448                                 if (Number(my.ahr.pickup_lib())>=0) {
1449                                         return data.hash.aou[ my.ahr.pickup_lib() ].name();
1450                                 } else {
1451                                         return my.ahr.pickup_lib().name();
1452                                 }
1453                         }
1454                 },
1455                 {
1456                         'persist' : 'hidden width ordinal',
1457                         'id' : 'pickup_lib_shortname',
1458                         'label' : document.getElementById('commonStrings').getString('staff.ahr_pickup_lib_label'),
1459                         'flex' : 0,
1460                         'primary' : false,
1461                         'hidden' : true,
1462                         'render' : function(my) {
1463                                 if (Number(my.ahr.pickup_lib())>=0) {
1464                                         return data.hash.aou[ my.ahr.pickup_lib() ].shortname();
1465                                 } else {
1466                                         return my.ahr.pickup_lib().shortname();
1467                                 }
1468                         }
1469                 },
1470                 {
1471                         'persist' : 'hidden width ordinal',
1472                         'id' : 'current_copy',
1473                         'label' : document.getElementById('commonStrings').getString('staff.ahr_current_copy_label'),
1474                         'flex' : 1,
1475                         'primary' : false,
1476                         'hidden' : true,
1477                         'render' : function(my) {
1478                                 if (my.acp) {
1479                                         return my.acp.barcode();
1480                                 } else {
1481                                         return document.getElementById('circStrings').getString('staff.circ.utils.current_copy.none');
1482                                 }
1483                         }
1484                 },
1485                 {
1486                         'persist' : 'hidden width ordinal',
1487                         'id' : 'current_copy_location', 
1488                         'label' : document.getElementById('commonStrings').getString('staff.ahr_current_copy_location_label'),
1489             'flex' : 1,
1490                         'primary' : false, 
1491             'hidden' : true, 
1492             'render' : function(my) { 
1493                 if (!my.acp) { return ""; } else { if (Number(my.acp.location())>=0) return data.lookup("acpl", my.acp.location() ).name(); else return my.acp.location().name(); } 
1494             }
1495                 },
1496                 {
1497                         'persist' : 'hidden width ordinal',
1498                         'id' : 'email_notify',
1499                         'label' : document.getElementById('commonStrings').getString('staff.ahr_email_notify_label'),
1500                         'flex' : 1,
1501                         'primary' : false,
1502                         'hidden' : true,
1503                         'render' : function(my) {
1504                                 if (get_bool(my.ahr.email_notify())) {
1505                                         return document.getElementById('circStrings').getString('staff.circ.utils.yes');
1506                                 } else {
1507                                         return document.getElementById('circStrings').getString('staff.circ.utils.no');
1508                                 }
1509                         }
1510                 },
1511                 {
1512                         'persist' : 'hidden width ordinal',
1513                         'id' : 'expire_time',
1514                         'label' : document.getElementById('commonStrings').getString('staff.ahr_expire_time_label'),
1515                         'flex' : 1,
1516                         'primary' : false,
1517                         'hidden' : true,
1518                         'render' : function(my) { return my.ahr.expire_time(); }
1519                 },
1520                 {
1521                         'persist' : 'hidden width ordinal',
1522                         'id' : 'expire_date',
1523                         'label' : document.getElementById('commonStrings').getString('staff.ahr_expire_date_label'),
1524                         'flex' : 1,
1525                         'primary' : false,
1526                         'hidden' : true,
1527                         'render' : function(my) { return my.ahr.expire_time() ? my.ahr.expire_time().toString().substr(0,10) : ''; }
1528                 },
1529                 {
1530                         'persist' : 'hidden width ordinal',
1531                         'id' : 'fulfillment_time',
1532                         'label' : document.getElementById('commonStrings').getString('staff.ahr_fulfillment_time_label'),
1533                         'flex' : 1,
1534                         'primary' : false,
1535                         'hidden' : true,
1536                         'render' : function(my) { return my.ahr.fulfillment_time(); }
1537                 },
1538                 {
1539                         'persist' : 'hidden width ordinal',
1540                         'id' : 'holdable_formats',
1541                         'label' : document.getElementById('commonStrings').getString('staff.ahr_holdable_formats_label'),
1542                         'flex' : 1,
1543                         'primary' : false,
1544                         'hidden' : true,
1545                         'render' : function(my) { return my.ahr.holdable_formats(); }
1546                 },
1547                 {
1548                         'persist' : 'hidden width ordinal',
1549                         'id' : 'id',
1550                         'label' : document.getElementById('commonStrings').getString('staff.ahr_id_label'),
1551                         'flex' : 1,
1552                         'primary' : false,
1553                         'hidden' : true,
1554                         'render' : function(my) { return my.ahr.id(); }
1555                 },
1556                 {
1557                         'persist' : 'hidden width ordinal',
1558                         'id' : 'phone_notify',
1559                         'label' : document.getElementById('commonStrings').getString('staff.ahr_phone_notify_label'),
1560                         'flex' : 1,
1561                         'primary' : false,
1562                         'hidden' : true,
1563                         'render' : function(my) { return my.ahr.phone_notify(); }
1564                 },
1565                 {
1566                         'persist' : 'hidden width ordinal',
1567                         'id' : 'prev_check_time',
1568                         'label' : document.getElementById('commonStrings').getString('staff.ahr_prev_check_time_label'),
1569                         'flex' : 1,
1570                         'primary' : false,
1571                         'hidden' : true,
1572                         'render' : function(my) { return my.ahr.prev_check_time(); }
1573                 },
1574                 {
1575                         'persist' : 'hidden width ordinal',
1576                         'id' : 'requestor',
1577                         'label' : document.getElementById('commonStrings').getString('staff.ahr_requestor_label'),
1578                         'flex' : 1,
1579                         'primary' : false,
1580                         'hidden' : true,
1581                         'render' : function(my) { return my.ahr.requestor(); }
1582                 },
1583                 {
1584                         'persist' : 'hidden width ordinal',
1585                         'id' : 'selection_depth',
1586                         'label' : document.getElementById('commonStrings').getString('staff.ahr_selection_depth_label'),
1587                         'flex' : 1,
1588                         'primary' : false,
1589                         'hidden' : true,
1590                         'render' : function(my) { return my.ahr.selection_depth(); }
1591                 },
1592                 {
1593                         'persist' : 'hidden width ordinal',
1594                         'id' : 'target',
1595                         'label' : document.getElementById('commonStrings').getString('staff.ahr_target_label'),
1596                         'flex' : 1,
1597                         'primary' : false,
1598                         'hidden' : true,
1599                         'render' : function(my) { return my.ahr.target(); }
1600                 },
1601                 {
1602                         'persist' : 'hidden width ordinal',
1603                         'id' : 'usr',
1604                         'label' : document.getElementById('commonStrings').getString('staff.ahr_usr_label'),
1605                         'flex' : 1,
1606                         'primary' : false,
1607                         'hidden' : true,
1608                         'render' : function(my) { return my.ahr.usr(); }
1609                 },
1610                 {
1611                         'persist' : 'hidden width ordinal',
1612                         'id' : 'title',
1613                         'label' : document.getElementById('commonStrings').getString('staff.mvr_label_title'),
1614                         'flex' : 1,
1615                         'sort_type' : 'title',
1616                         'primary' : false,
1617                         'hidden' : true,
1618                         'render' : function(my) {
1619                                 if (my.mvr) {
1620                                         return my.mvr.title();
1621                                 } else {
1622                                         return document.getElementById('circStrings').getString('staff.circ.utils.title.none');
1623                                 }
1624                         }
1625                 },
1626                 {
1627                         'persist' : 'hidden width ordinal',
1628                         'id' : 'author',
1629                         'label' : document.getElementById('commonStrings').getString('staff.mvr_label_author'),
1630                         'flex' : 1,
1631                         'primary' : false,
1632                         'hidden' : true,
1633                         'render' : function(my) {
1634                                 if (my.mvr) {
1635                                         return my.mvr.author();
1636                                 } else {
1637                                         return document.getElementById('circStrings').getString('staff.circ.utils.author.none');
1638                                 }
1639                         }
1640                 },
1641                 {
1642                         'persist' : 'hidden width ordinal',
1643                         'id' : 'edition',
1644                         'label' : document.getElementById('circStrings').getString('staff.circ.utils.edition'),
1645                         'flex' : 1,
1646                         'primary' : false,
1647                         'hidden' : true,
1648                         'render' : function(my) { return my.mvr.edition(); }
1649                 },
1650                 {
1651                         'persist' : 'hidden width ordinal',
1652                         'id' : 'isbn',
1653                         'label' : document.getElementById('circStrings').getString('staff.circ.utils.isbn'),
1654                         'flex' : 1,
1655                         'primary' : false,
1656                         'hidden' : true,
1657                         'render' : function(my) { return my.mvr.isbn(); }
1658                 },
1659                 {
1660                         'persist' : 'hidden width ordinal',
1661                         'id' : 'pubdate',
1662                         'label' : document.getElementById('circStrings').getString('staff.circ.utils.pubdate'),
1663                         'flex' : 1,
1664                         'primary' : false,
1665                         'hidden' : true,
1666                         'render' : function(my) { return my.mvr.pubdate(); }
1667                 },
1668                 {
1669                         'persist' : 'hidden width ordinal',
1670                         'id' : 'publisher',
1671                         'label' : document.getElementById('circStrings').getString('staff.circ.utils.publisher'),
1672                         'flex' : 1,
1673                         'primary' : false,
1674                         'hidden' : true,
1675                         'render' : function(my) { return my.mvr.publisher(); }
1676                 },
1677                 {
1678                         'persist' : 'hidden width ordinal',
1679                         'id' : 'tcn',
1680                         'label' : document.getElementById('circStrings').getString('staff.circ.utils.tcn'),
1681                         'flex' : 1,
1682                         'primary' : false,
1683                         'hidden' : true,
1684                         'render' : function(my) { return my.mvr.tcn(); }
1685                 },
1686                 {
1687                         'persist' : 'hidden width ordinal',
1688                         'id' : 'notify_time',
1689                         'label' : document.getElementById('circStrings').getString('staff.circ.utils.notify_time'),
1690                         'flex' : 1,
1691                         'primary' : false,
1692                         'hidden' : true,
1693                         'render' : function(my) { return my.ahr.notify_time(); }
1694                 },
1695                 {
1696                         'persist' : 'hidden width ordinal',
1697                         'id' : 'notify_count',
1698                         'label' : document.getElementById('circStrings').getString('staff.circ.utils.notify_count'),
1699                         'flex' : 1,
1700                         'primary' : false,
1701                         'hidden' : true,
1702                         'render' : function(my) { return my.ahr.notify_count(); }
1703                 },
1704                 {
1705                         'persist' : 'hidden width ordinal',
1706                         'id' : 'transit_source',
1707                         'label' : document.getElementById('circStrings').getString('staff.circ.utils.transit_source'),
1708                         'flex' : 1,
1709                         'primary' : false,
1710                         'hidden' : true,
1711                         'render' : function(my) {
1712                                 if (my.ahr.transit()) {
1713                                         return data.hash.aou[ my.ahr.transit().source() ].shortname();
1714                                 } else {
1715                                         return "";
1716                                 }
1717                         }
1718                 },
1719                 {
1720                         'persist' : 'hidden width ordinal',
1721                         'id' : 'transit_source_send_time',
1722                         'label' : document.getElementById('circStrings').getString('staff.circ.utils.transit_source_send_time'),
1723                         'flex' : 1,
1724                         'primary' : false,
1725                         'hidden' : true,
1726                         'render' : function(my) { return my.ahr.transit() ?  my.ahr.transit().source_send_time() : ""; }
1727                 },
1728                 {
1729                         'persist' : 'hidden width ordinal',
1730                         'id' : 'transit_dest_lib',
1731                         'label' : document.getElementById('circStrings').getString('staff.circ.utils.transit_dest'),
1732                         'flex' : 1,
1733                         'primary' : false,
1734                         'hidden' : true,
1735                         'render' : function(my) { return my.ahr.transit() ?  data.hash.aou[ my.ahr.transit().dest() ].shortname() : ""; }
1736                 },
1737                 {
1738                         'persist' : 'hidden width ordinal',
1739                         'id' : 'transit_dest_recv_time',
1740                         'label' : document.getElementById('circStrings').getString('staff.circ.utils.transit_dest_recv_time'),
1741                         'flex' : 1,
1742                         'primary' : false,
1743                         'hidden' : true,
1744                         'render' : function(my) { return my.ahr.transit() ?  my.ahr.transit().dest_recv_time() : ""; }
1745                 },
1746                 {
1747                         'persist' : 'hidden width ordinal',
1748                         'id' : 'patron_barcode',
1749                         'label' : document.getElementById('circStrings').getString('staff.circ.utils.offline.patron_barcode'),
1750                         'flex' : 1,
1751                         'primary' : false,
1752                         'hidden' : true,
1753                         'render' : function(my) { return my.patron_barcode ? my.patron_barcode : ""; }
1754                 },
1755                 {
1756                         'persist' : 'hidden width ordinal',
1757                         'id' : 'patron_family_name',
1758                         'label' : document.getElementById('circStrings').getString('staff.circ.utils.patron_family_name'),
1759                         'flex' : 1,
1760                         'primary' : false,
1761                         'hidden' : true,
1762                         'render' : function(my) { return my.patron_family_name ? my.patron_family_name : ""; }
1763                 },
1764                 {
1765                         'persist' : 'hidden width ordinal',
1766                         'id' : 'patron_first_given_name',
1767                         'label' : document.getElementById('circStrings').getString('staff.circ.utils.patron_first_given_name'),
1768                         'flex' : 1,
1769                         'primary' : false,
1770                         'hidden' : true,
1771                         'render' : function(my) { return my.patron_first_given_name ? my.patron_first_given_name : ""; }
1772                 },
1773                 {
1774                         'persist' : 'hidden width ordinal',
1775                         'id' : 'callnumber',
1776                         'label' : document.getElementById('circStrings').getString('staff.circ.utils.callnumber'),
1777                         'flex' : 1,
1778                         'primary' : false,
1779                         'hidden' : true,
1780                         'render' : function(my) { return my.acn.label(); }
1781                 },
1782         ];
1783         for (var i = 0; i < c.length; i++) {
1784                 if (modify[ c[i].id ]) {
1785                         for (var j in modify[ c[i].id ]) {
1786                                 c[i][j] = modify[ c[i].id ][j];
1787                         }
1788                 }
1789         }
1790         if (params) {
1791                 if (params.just_these) {
1792                         JSAN.use('util.functional');
1793                         var new_c = [];
1794                         for (var i = 0; i < params.just_these.length; i++) {
1795                                 var x = util.functional.find_list(c,function(d){return(d.id==params.just_these[i]);});
1796                                 new_c.push( function(y){ return y; }( x ) );
1797                         }
1798                         c = new_c;
1799                 }
1800                 if (params.except_these) {
1801                         JSAN.use('util.functional');
1802                         var new_c = [];
1803                         for (var i = 0; i < c.length; i++) {
1804                                 var x = util.functional.find_list(params.except_these,function(d){return(d==c[i].id);});
1805                                 if (!x) new_c.push(c[i]);
1806                         }
1807                         c = new_c;
1808                 }
1809
1810         }
1811         return c.sort( function(a,b) { if (a.label < b.label) return -1; if (a.label > b.label) return 1; return 0; } );
1812 };
1813 /*
1814 circ.util.std_map_row_to_column = function(error_value) {
1815         return function(row,col) {
1816                 // row contains { 'my' : { 'acp' : {}, 'circ' : {}, 'mvr' : {} } }
1817                 // col contains one of the objects listed above in columns
1818                 
1819                 // mimicking some of the obj in circ.checkin and circ.checkout where map_row_to_column is usually defined
1820                 var obj = {};
1821                 JSAN.use('util.error'); obj.error = new util.error();
1822                 JSAN.use('OpenILS.data'); obj.data = new OpenILS.data(); obj.data.init({'via':'stash'});
1823                 JSAN.use('util.network'); obj.network = new util.network();
1824                 JSAN.use('util.money');
1825
1826                 var my = row.my;
1827                 var value;
1828                 try {
1829                         value = eval( col.render );
1830                 } catch(E) {
1831                         obj.error.sdump('D_WARN','map_row_to_column: ' + E);
1832                         if (error_value) value = error_value; else value = '   ';
1833                 }
1834                 return value;
1835         }
1836 };
1837 */
1838 circ.util.std_map_row_to_columns = function(error_value) {
1839         return function(row,cols) {
1840                 // row contains { 'my' : { 'acp' : {}, 'circ' : {}, 'mvr' : {} } }
1841                 // cols contains all of the objects listed above in columns
1842                 
1843                 var obj = {};
1844                 JSAN.use('util.error'); obj.error = new util.error();
1845                 JSAN.use('OpenILS.data'); obj.data = new OpenILS.data(); obj.data.init({'via':'stash'});
1846                 JSAN.use('util.network'); obj.network = new util.network();
1847                 JSAN.use('util.money');
1848
1849                 var my = row.my;
1850                 var values = [];
1851                 var cmd = '';
1852                 try {
1853                         for (var i = 0; i < cols.length; i++) {
1854                                 switch (typeof cols[i].render) {
1855                                         case 'function': try { values[i] = cols[i].render(my); } catch(E) { values[i] = error_value; obj.error.sdump('D_COLUMN_RENDER_ERROR',E); } break;
1856                                         case 'string' : cmd += 'try { ' + cols[i].render + '; values['+i+'] = v; } catch(E) { values['+i+'] = error_value; }'; break;
1857                                         default: cmd += 'values['+i+'] = "??? '+(typeof cols[i].render)+'"; ';
1858                                 }
1859                         }
1860                         if (cmd) eval( cmd );
1861                 } catch(E) {
1862                         obj.error.sdump('D_WARN','map_row_to_column: ' + E);
1863                         if (error_value) { value = error_value; } else { value = '   ' };
1864                 }
1865                 return values;
1866         }
1867 };
1868
1869 circ.util.checkin_via_barcode = function(session,params,backdate,auto_print,async) {
1870         try {
1871                 JSAN.use('util.error'); var error = new util.error();
1872                 JSAN.use('util.network'); var network = new util.network();
1873                 JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.init({'via':'stash'});
1874                 JSAN.use('util.date');
1875
1876                 if (backdate && (backdate == util.date.formatted_date(new Date(),'%Y-%m-%d')) ) backdate = null;
1877
1878                 //var params = { 'barcode' : barcode };
1879                 if (backdate) params.backdate = util.date.formatted_date(backdate + ' 00:00:00','%{iso8601}');
1880
1881                 if (typeof async == 'object') {
1882                         try { async.disable_textbox(); }
1883                         catch(E) { error.sdump('D_ERROR','async.disable_textbox() = ' + E); };
1884                 }
1885                 var check = network.request(
1886                         api.CHECKIN_VIA_BARCODE.app,
1887                         api.CHECKIN_VIA_BARCODE.method,
1888                         [ session, params ],
1889                         async ? function(req) {
1890                                 try {
1891                                         var check = req.getResultObject();
1892                                         var r = circ.util.checkin_via_barcode2(session,params,backdate,auto_print,check);
1893                                         if (typeof async == 'object') {
1894                                                 try { async.checkin_result(r); }
1895                                                 catch(E) { error.sdump('D_ERROR','async.checkin_result() = ' + E); };
1896                                         }
1897                                 } catch(E) {
1898                                         JSAN.use('util.error'); var error = new util.error();
1899                                         error.standard_unexpected_error_alert(document.getElementById('circStrings').getFormattedString('staff.circ.checkin.error', ['1']), E);
1900                                         if (typeof async == 'object') {
1901                                                 try { async.enable_textbox(); }
1902                                                 catch(E) { error.sdump('D_ERROR','async.disable_textbox() = ' + E); };
1903                                         }
1904                                         return null;
1905                                 }
1906                         } : null,
1907                         {
1908                                 'title' : document.getElementById('circStrings').getString('staff.circ.utils.checkin.override'),
1909                                 'overridable_events' : [
1910                     null /* custom event */,
1911                                         1203 /* COPY_BAD_STATUS */,
1912                                         1213 /* PATRON_BARRED */,
1913                                         1217 /* PATRON_INACTIVE */,
1914                                         1224 /* PATRON_ACCOUNT_EXPIRED */,
1915                                         1234 /* ITEM_DEPOSIT_PAID */,
1916                                         7009 /* CIRC_CLAIMS_RETURNED */,
1917                                         7010 /* COPY_ALERT_MESSAGE */,
1918                                         7011 /* COPY_STATUS_LOST */,
1919                                         7012 /* COPY_STATUS_MISSING */,
1920                                         7013 /* PATRON_EXCEEDS_FINES */,
1921                                 ],
1922                                 'text' : {
1923                                         '1203' : function(r) {
1924                                                 return r.payload.status().name();
1925                                         },
1926                                         '1234' : function(r) {
1927                                                 return document.getElementById('circStrings').getString('staff.circ.utils.checkin.override.item_deposit_paid.warning');
1928                                         },
1929                                         '7010' : function(r) {
1930                                                 return r.payload;
1931                                         }
1932                                 }
1933                         }
1934                 );
1935                 if (!async) {
1936                         return circ.util.checkin_via_barcode2(session,params,backdate,auto_print,check);
1937                 }
1938
1939
1940         } catch(E) {
1941                 JSAN.use('util.error'); var error = new util.error();
1942                 error.standard_unexpected_error_alert(document.getElementById('circStrings').getFormattedString('staff.circ.checkin.error', ['2']), E);
1943                 if (typeof async == 'object') {
1944                         try { async.enable_textbox(); } catch(E) { error.sdump('D_ERROR','async.disable_textbox() = ' + E); };
1945                 }
1946                 return null;
1947         }
1948 };
1949
1950 circ.util.checkin_via_barcode2 = function(session,params,backdate,auto_print,check) {
1951         try {
1952                 JSAN.use('util.error'); var error = new util.error();
1953                 JSAN.use('util.network'); var network = new util.network();
1954                 JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.init({'via':'stash'});
1955                 JSAN.use('util.date');
1956
1957                 error.sdump('D_DEBUG','check = ' + error.pretty_print( js2JSON( check ) ) );
1958
1959                 check.message = check.textcode;
1960
1961                 if (check.payload && check.payload.copy) { check.copy = check.payload.copy; }
1962                 if (check.payload && check.payload.record) { check.record = check.payload.record; }
1963                 if (check.payload && check.payload.circ) { check.circ = check.payload.circ; }
1964
1965                 if (!check.route_to) { check.route_to = '   '; }
1966
1967                 if (document.getElementById('no_change_label')) {
1968                         document.getElementById('no_change_label').setAttribute('value','');
1969                         document.getElementById('no_change_label').setAttribute('hidden','true');
1970                 }
1971
1972                 if (check.circ) {
1973                         network.simple_request('FM_MBTS_RETRIEVE.authoritative',[ses(),check.circ.id()], function(req) {
1974                                 JSAN.use('util.money');
1975                                 var bill = req.getResultObject();
1976                                 if (Number(bill.balance_owed()) == 0) { return; }
1977                                 if (document.getElementById('no_change_label')) {
1978                                         var m = document.getElementById('no_change_label').getAttribute('value');
1979                                         document.getElementById('no_change_label').setAttribute('value', m + document.getElementById('circStrings').getFormattedString('staff.circ.utils.billable.amount', [params.barcode, util.money.sanitize(bill.balance_owed())]) + '  ');
1980                                         document.getElementById('no_change_label').setAttribute('hidden','false');
1981                                 }
1982                         });
1983                 }
1984
1985                 var msg = '';
1986
1987                 if (check.payload && check.payload.cancelled_hold_transit) {
1988                         msg += document.getElementById('circStrings').getString('staff.circ.utils.transit_hold_cancelled');
1989                         msg += '\n\n';
1990                 }
1991
1992                 /* SUCCESS  /  NO_CHANGE  /  ITEM_NOT_CATALOGED */
1993                 if (check.ilsevent == 0 || check.ilsevent == 3 || check.ilsevent == 1202) {
1994                         try { check.route_to = data.lookup('acpl', check.copy.location() ).name(); }
1995                         catch(E) {
1996                                 msg += document.getElementById('commonStrings').getString('common.error');
1997                                 msg += '\nFIXME: ' + E + '\n';
1998                         }
1999                         if (check.ilsevent == 3 /* NO_CHANGE */) {
2000                                 //msg = 'This item is already checked in.\n';
2001                                 if (document.getElementById('no_change_label')) {
2002                                         var m = document.getElementById('no_change_label').getAttribute('value');
2003                                         document.getElementById('no_change_label').setAttribute('value', m + document.getElementById('circStrings').getFormattedString('staff.circ.utils.item_checked_in', [params.barcode]) + '  ');
2004                                         document.getElementById('no_change_label').setAttribute('hidden','false');
2005                                 }
2006                         }
2007                         if (check.ilsevent == 1202 /* ITEM_NOT_CATALOGED */ && check.copy.status() != 11) {
2008                                 var copy_status = (data.hash.ccs[ check.copy.status() ] ? data.hash.ccs[ check.copy.status() ].name() : check.copy.status().name() );
2009                                 msg = document.getElementById('commonStrings').getString('common.error');
2010                                 msg += '\nFIXME --';
2011                                 msg += document.getElementById('circStrings').getFormattedString('staff.circ.utils.item_not_cataloged', [copy_status]);
2012                                 msg + '\n';
2013                         }
2014                         switch(Number(check.copy.status())) {
2015                                 case 0: /* AVAILABLE */
2016                                 case 7: /* RESHELVING */
2017                                         if (msg) {
2018                                                 msg += document.getElementById('circStrings').getFormattedString('staff.circ.utils.route_to.msg', [check.route_to]);
2019                                                 msg += '\n';
2020                                         }
2021                                 break;
2022                                 case 8: /* ON HOLDS SHELF */
2023                                         check.route_to = 'HOLDS SHELF';
2024                                         if (check.payload.hold) {
2025                                                 if (check.payload.hold.pickup_lib() != data.list.au[0].ws_ou()) {
2026                                                         msg += document.getElementById('commonStrings').getString('common.error');
2027                                                         msg += '\nFIXME: ';
2028                                                         msg += document.getElementById('circStrings').getString('staff.circ.utils.route_item_error');
2029                                                         msg += '\n';
2030                                                 } else {
2031                                                         msg += document.getElementById('circStrings').getFormattedString('staff.circ.utils.route_to.msg', [check.route_to]);
2032                                                         msg += '.\n';
2033                                                 }
2034                                         } else {
2035                                                 msg += document.getElementById('commonStrings').getString('common.error');
2036                                                 msg += '\nFIXME: ';
2037                                                 msg += document.getElementById('circStrings').getString('staff.circ.utils.route_item_status_error');
2038                                                 msg += '\n';
2039                                         }
2040                                         JSAN.use('util.date');
2041                                         if (check.payload.hold) {
2042                                                 JSAN.use('patron.util');
2043                                                 msg += '\n';
2044                                                 msg += document.getElementById('circStrings').getFormattedString('staff.circ.utils.payload.hold.barcode', [check.payload.copy.barcode()]);
2045                                                 msg += '\n';
2046                                                 var payload_title  = (check.payload.record ? check.payload.record.title() : check.payload.copy.dummy_title() );
2047                                                 msg += document.getElementById('circStrings').getFormattedString('staff.circ.utils.payload.hold.title', [payload_title]);
2048                                                 msg += '\n';
2049                                                 var au_obj = patron.util.retrieve_fleshed_au_via_id( session, check.payload.hold.usr() );
2050                                                 msg += '\n';
2051                         if (au_obj.alias()) {
2052                                                 msg += document.getElementById('circStrings').getFormattedString('staff.circ.utils.payload.hold.patron_alias',  [au_obj.alias()]);
2053                         } else {
2054                                                 msg += document.getElementById('circStrings').getFormattedString('staff.circ.utils.payload.hold.patron',  [au_obj.family_name(), au_obj.first_given_name(), au_obj.second_given_name()]);
2055                         }
2056                                                 msg += '\n';
2057                                                 msg += document.getElementById('circStrings').getFormattedString('staff.circ.utils.payload.hold.barcode', [au_obj.card().barcode()]);
2058                                                 msg += '\n';
2059                                                 if (check.payload.hold.phone_notify()) {
2060                                                         msg += document.getElementById('circStrings').getFormattedString('staff.circ.utils.payload.hold.phone_notify', [check.payload.hold.phone_notify()]);
2061                                                         msg += '\n';
2062                                                 }
2063                                                 if (get_bool(check.payload.hold.email_notify())) {
2064                                                         var payload_email = au_obj.email() ? au_obj.email() : '';
2065                                                         msg += document.getElementById('circStrings').getFormattedString('staff.circ.utils.payload.hold.email_notify', [payload_email]);
2066                                                         msg += '\n';
2067                                                 }
2068                                                 msg += '\n';
2069                                                 msg += document.getElementById('circStrings').getFormattedString('staff.circ.utils.payload.hold.request_date', [util.date.formatted_date(check.payload.hold.request_time(),'%F')]);
2070                                                 msg += '\n';
2071                                         }
2072                                         var rv = 0;
2073                                         msg += document.getElementById('circStrings').getFormattedString('staff.circ.utils.payload.hold.slip_date', [util.date.formatted_date(new Date(),'%F')]);
2074                                         msg += '\n';
2075                                         if (!auto_print) {
2076                                                 rv = error.yns_alert_formatted(
2077                                                         msg,
2078                                                         document.getElementById('circStrings').getString('staff.circ.utils.hold_slip'),
2079                                                         document.getElementById('circStrings').getString('staff.circ.utils.hold_slip.print.yes'),
2080                                                         document.getElementById('circStrings').getString('staff.circ.utils.hold_slip.print.no'),
2081                                                         null,
2082                                                         document.getElementById('circStrings').getString('staff.circ.confirm.msg'),
2083                                                         '/xul/server/skin/media/images/turtle.gif'
2084                                                 );
2085                                         }
2086                                         if (rv == 0) {
2087                                                 try {
2088                                                         JSAN.use('util.print'); var print = new util.print();
2089                                                         msg = msg.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/\n/g,'<br/>');
2090                                                         print.simple( msg , { 'no_prompt' : true, 'content_type' : 'text/html' } );
2091                                                 } catch(E) {
2092                                                         var err_msg = document.getElementById('commonStrings').getString('common.error');
2093                                                         err_msg += '\nFIXME: ' + E + '\n';
2094                                                         dump(err_msg);
2095                                                         alert(err_msg);
2096                                                 }
2097                                         }
2098                                         msg = '';
2099                                         if (document.getElementById('no_change_label')) {
2100                                                 var m = document.getElementById('no_change_label').getAttribute('value');
2101                                                 m += document.getElementById('circStrings').getFormattedString('staff.circ.utils.capture', [params.barcode]);
2102                                                 document.getElementById('no_change_label').setAttribute('value', m);
2103                                                 document.getElementById('no_change_label').setAttribute('hidden','false');
2104                                         }
2105                                 break;
2106                                 case 6: /* IN TRANSIT */
2107                                         check.route_to = 'TRANSIT SHELF??';
2108                                         msg += document.getElementById('commonStrings').getString('common.error');
2109                                         msg += "\nFIXME -- I didn't think we could get here.\n";
2110                                 break;
2111                                 case 11: /* CATALOGING */
2112                                         check.route_to = 'CATALOGING';
2113                                         if (document.getElementById('do_not_alert_on_precat')) {
2114                                                 var x = document.getElementById('do_not_alert_on_precat');
2115                                                 if (! x.checked) {
2116                                                         msg += document.getElementById('circStrings').getFormattedString('staff.circ.utils.route_to.msg', [check.route_to]);
2117                                                 }
2118                                         } else {
2119                                                 msg += document.getElementById('circStrings').getFormattedString('staff.circ.utils.route_to.msg', [check.route_to]);
2120                                         }
2121                                         if (document.getElementById('no_change_label')) {
2122                                                 var m = document.getElementById('no_change_label').getAttribute('value');
2123                                                 var needs_cat = document.getElementById('circStrings').getFormattedString('staff.circ.utils.needs_cataloging', [params.barcode]);
2124                                                 document.getElementById('no_change_label').setAttribute('value', m + needs_cat + '  ');
2125                                                 document.getElementById('no_change_label').setAttribute('hidden','false');
2126                                         }
2127                                 break;
2128                                 default:
2129                                         msg += document.getElementById('commonStrings').getString('common.error');
2130                                         var copy_status = data.hash.ccs[check.copy.status()] ? data.hash.ccs[check.copy.status()].name() : check.copy.status().name();
2131                                         msg += '\n';
2132                                         msg += document.getElementById('circStrings').getFormattedString('staff.circ.utils.copy_status.error', [copy_status]);
2133                                         msg += '\n';
2134                                         msg += document.getElementById('circStrings').getFormattedString('staff.circ.utils.route_to.msg', [check.route_to]);
2135                                 break;
2136                         }
2137                         if (msg) {
2138                                 error.yns_alert(
2139                                         msg,
2140                                         document.getElementById('circStrings').getString('staff.circ.alert'),
2141                                         null,
2142                                         document.getElementById('circStrings').getString('staff.circ.utils.msg.ok'),
2143                                         null,
2144                                         document.getElementById('circStrings').getString('staff.circ.confirm.msg')
2145                                 );
2146                         }
2147                 } else /* ROUTE_ITEM */ if (check.ilsevent == 7000) {
2148
2149                         var lib = data.hash.aou[ check.org ];
2150                         check.route_to = lib.shortname();
2151                         msg += document.getElementById('circStrings').getFormattedString('staff.circ.utils.route_to.destination', [check.route_to]);
2152                         msg += '\n\n';
2153                         msg += lib.name();
2154                         msg += '\n';
2155                         try {
2156                                 if (lib.holds_address() ) {
2157                                         var a = network.simple_request('FM_AOA_RETRIEVE',[ lib.holds_address() ]);
2158                                         if (typeof a.ilsevent != 'undefined') throw(a);
2159                                         if (a.street1()) msg += a.street1() + '\n';
2160                                         if (a.street2()) msg += a.street2() + '\n';
2161                                         msg += (a.city() ? a.city() + ', ' : '') + (a.state() ? a.state() + ' ' : '') + (a.post_code() ? a.post_code() : '') + '\n';
2162                                 } else {
2163                                         msg += document.getElementById('circStrings').getString('staff.circ.utils.route_to.no_address');
2164                                         msg += '\n';
2165                                 }
2166                         } catch(E) {
2167                                 msg += document.getElementById('circStrings').getString('staff.circ.utils.route_to.no_address.error');
2168                                 msg += '\n';
2169                                 error.standard_unexpected_error_alert(document.getElementById('circStrings').getString('staff.circ.utils.route_to.no_address.error'), E);
2170                         }
2171                         msg += '\n';
2172                         msg += document.getElementById('circStrings').getFormattedString('staff.circ.utils.payload.hold.barcode', [check.payload.copy.barcode()]);
2173                         msg += '\n';
2174                         var payload_title  = (check.payload.record ? check.payload.record.title() : check.payload.copy.dummy_title() );
2175                         msg += document.getElementById('circStrings').getFormattedString('staff.circ.utils.payload.hold.title', [payload_title]);
2176                         msg += '\n';
2177                         var payload_author = (check.payload.record ? check.payload.record.author() :check.payload.copy.dummy_author());
2178                         msg += document.getElementById('circStrings').getFormattedString('staff.circ.utils.payload.author', [payload_author]);
2179                         msg += '\n';
2180                         JSAN.use('util.date');
2181                         if (check.payload.hold) {
2182                                 JSAN.use('patron.util');
2183                                 var au_obj = patron.util.retrieve_fleshed_au_via_id( session, check.payload.hold.usr() );
2184                                 msg += '\n';
2185                 if (au_obj.alias()) {
2186                     msg += document.getElementById('circStrings').getFormattedString('staff.circ.utils.payload.hold.patron_alias',  [au_obj.alias()]);
2187                 } else {
2188                                 msg += document.getElementById('circStrings').getFormattedString('staff.circ.utils.payload.hold.patron', [au_obj.family_name(), au_obj.first_given_name(), au_obj.second_given_name()]);
2189                 }
2190                                 msg += '\n';
2191                                 msg += document.getElementById('circStrings').getFormattedString('staff.circ.utils.payload.hold.barcode', [au_obj.card().barcode()]);
2192                                 msg += '\n';
2193                                 if (check.payload.hold.phone_notify()) {
2194                                         msg += document.getElementById('circStrings').getFormattedString('staff.circ.utils.payload.hold.phone_notify', [check.payload.hold.phone_notify()]);
2195                                         msg += '\n';
2196                                 }
2197                                 if (get_bool(check.payload.hold.email_notify())) {
2198                                         var payload_email = au_obj.email() ? au_obj.email() : '';
2199                                         msg += document.getElementById('circStrings').getFormattedString('staff.circ.utils.payload.hold.email_notify', [payload_email]);
2200                                         msg += '\n';
2201                                 }
2202                                 msg += '\n';
2203                                 msg += document.getElementById('circStrings').getFormattedString('staff.circ.utils.payload.hold.request_date', [util.date.formatted_date(check.payload.hold.request_time(),'%F')]);
2204                                 msg += '\n';
2205                         }
2206                         var rv = 0;
2207                         msg += document.getElementById('circStrings').getFormattedString('staff.circ.utils.payload.hold.slip_date', [util.date.formatted_date(new Date(),'%F')]);
2208                         if (!auto_print) {
2209                                 rv = error.yns_alert_formatted(
2210                                         msg,
2211                                         document.getElementById('circStrings').getString('staff.circ.utils.hold_slip'),
2212                                         document.getElementById('circStrings').getString('staff.circ.utils.hold_slip.print.yes'),
2213                                         document.getElementById('circStrings').getString('staff.circ.utils.hold_slip.print.no'),
2214                                         null,
2215                                         document.getElementById('circStrings').getString('staff.circ.confirm.msg'),
2216                                         '/xul/server/skin/media/images/turtle.gif'
2217                                 );
2218                         }
2219
2220                         if (rv == 0) {
2221                                 try {
2222                                         JSAN.use('util.print'); var print = new util.print();
2223                                         //print.simple( msg, { 'no_prompt' : true, 'content_type' : 'text/plain' } );
2224                                         msg = msg.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/\n/g,'<br/>');
2225                                         print.simple( msg , { 'no_prompt' : true, 'content_type' : 'text/html' } );
2226                                 } catch(E) {
2227                                         var err_msg = document.getElementById('commonStrings').getString('common.error');
2228                                         err_msg += '\nFIXME: ' + E + '\n';
2229                                         dump(err_msg);
2230                                         alert(err_msg);
2231                                 }
2232                         }
2233                         if (document.getElementById('no_change_label')) {
2234                                 var m = document.getElementById('no_change_label').getAttribute('value');
2235                                 var trans_msg = document.getElementById('circStrings').getFormattedString('staff.circ.utils.payload.in_transit', [params.barcode]);
2236                                 document.getElementById('no_change_label').setAttribute('value', m + trans_msg + '  ');
2237                                 document.getElementById('no_change_label').setAttribute('hidden','false');
2238                         }
2239
2240                 } else /* ASSET_COPY_NOT_FOUND */ if (check.ilsevent == 1502) {
2241
2242                         check.route_to = 'CATALOGING';
2243                         var mis_scan_msg = document.getElementById('circStrings').getFormattedString('staff.circ.copy_status.status.copy_not_found', [params.barcode]);
2244                         error.yns_alert(
2245                                 mis_scan_msg,
2246                                 document.getElementById('circStrings').getString('staff.circ.alert'),
2247                                 null,
2248                                 document.getElementById('circStrings').getString('staff.circ.utils.msg.ok'),
2249                                 null,
2250                                 document.getElementById('circStrings').getString('staff.circ.confirm.msg')
2251                         );
2252                         if (document.getElementById('no_change_label')) {
2253                                 var m = document.getElementById('no_change_label').getAttribute('value');
2254                                 document.getElementById('no_change_label').setAttribute('value',m + mis_scan_msg + '  ');
2255                                 document.getElementById('no_change_label').setAttribute('hidden','false');
2256                         }
2257
2258                 } else /* HOLD_CAPTURE_DELAYED */ if (check.ilsevent == 7019) {
2259
2260                         var rv = 0;
2261                         msg += document.getElementById('circStrings').getString('staff.circ.utils.hold_capture_delayed.description');
2262                         rv = error.yns_alert_formatted(
2263                                 msg,
2264                                 document.getElementById('circStrings').getString('staff.circ.utils.hold_capture_delayed.titlebar'),
2265                                 document.getElementById('circStrings').getString('staff.circ.utils.hold_capture_delayed.prompt_for_nocapture'),
2266                                 document.getElementById('circStrings').getString('staff.circ.utils.hold_capture_delayed.prompt_for_capture'),
2267                                 null,
2268                                 document.getElementById('circStrings').getString('staff.circ.confirm.msg'),
2269                                 '/xul/server/skin/media/images/stop_sign.png'
2270                         );
2271                         params.capture = rv == 0 ? 'nocapture' : 'capture';
2272
2273                         return circ.util.checkin_via_barcode(session,params,backdate,auto_print,false); 
2274
2275                 } else /* NETWORK TIMEOUT */ if (check.ilsevent == -1) {
2276                         error.standard_network_error_alert(document.getElementById('circStrings').getString('staff.circ.checkin.suggest_offline'));
2277                 } else {
2278
2279             if (check.ilsevent == null) { return null; /* handled */ }
2280                         switch (Number(check.ilsevent)) {
2281                                 case 1203 /* COPY_BAD_STATUS */ :
2282                                 case 1213 /* PATRON_BARRED */ :
2283                                 case 1217 /* PATRON_INACTIVE */ :
2284                                 case 1224 /* PATRON_ACCOUNT_EXPIRED */ :
2285                                 case 1234 /* ITEM_DEPOSIT_PAID */ :
2286                                 case 7009 /* CIRC_CLAIMS_RETURNED */ :
2287                                 case 7010 /* COPY_ALERT_MESSAGE */ :
2288                                 case 7011 /* COPY_STATUS_LOST */ :
2289                                 case 7012 /* COPY_STATUS_MISSING */ :
2290                                 case 7013 /* PATRON_EXCEEDS_FINES */ :
2291                                         return null; /* handled */
2292                                 break;
2293                         }
2294
2295                         throw(check);
2296
2297                 }
2298
2299                 return check;
2300         } catch(E) {
2301                 JSAN.use('util.error'); var error = new util.error();
2302                 error.standard_unexpected_error_alert(document.getElementById('circStrings').getFormattedString('staff.circ.checkin.error', ['3']), E);
2303                 return null;
2304         }
2305 };
2306
2307 circ.util.renew_via_barcode = function ( barcode, patron_id, async ) {
2308         try {
2309                 var obj = {};
2310                 JSAN.use('util.network'); obj.network = new util.network();
2311                 JSAN.use('OpenILS.data'); obj.data = new OpenILS.data(); obj.data.stash_retrieve();
2312
2313                 var params = { barcode: barcode };
2314                 if (patron_id) params.patron = patron_id;
2315
2316                 function renew_callback(req) {
2317                         try {
2318                                 var renew = req.getResultObject();
2319                                 if (typeof renew.ilsevent != 'undefined') renew = [ renew ];
2320                                 for (var j = 0; j < renew.length; j++) {
2321                                         switch(renew[j].ilsevent == null ? null : Number(renew[j].ilsevent)) {
2322                                                 case 0 /* SUCCESS */ : break;
2323                                                 case null /* custom event */ : break;
2324                                                 case 5000 /* PERM_FAILURE */: break;
2325                                                 case 1212 /* PATRON_EXCEEDS_OVERDUE_COUNT */ : break;
2326                                                 case 1213 /* PATRON_BARRED */ : break;
2327                                                 case 1215 /* CIRC_EXCEEDS_COPY_RANGE */ : break;
2328                                                 case 1224 /* PATRON_ACCOUNT_EXPIRED */ : break;
2329                         case 1232 /* ITEM_DEPOSIT_REQUIRED */ : break;
2330                         case 1233 /* ITEM_RENTAL_FEE_REQUIRED */ : break;
2331                                             case 1234 /* ITEM_DEPOSIT_PAID */ : break;
2332                                                 case 1500 /* ACTION_CIRCULATION_NOT_FOUND */ : break;
2333                                                 case 7002 /* PATRON_EXCEEDS_CHECKOUT_COUNT */ : break;
2334                                                 case 7003 /* COPY_CIRC_NOT_ALLOWED */ : break;
2335                                                 case 7004 /* COPY_NOT_AVAILABLE */ : break;
2336                                                 case 7006 /* COPY_IS_REFERENCE */ : break;
2337                                                 case 7007 /* COPY_NEEDED_FOR_HOLD */ : break;
2338                                                 case 7008 /* MAX_RENEWALS_REACHED */ : break;
2339                                                 case 7009 /* CIRC_CLAIMS_RETURNED */ : break;
2340                                                 case 7010 /* COPY_ALERT_MESSAGE */ : break;
2341                                                 case 7013 /* PATRON_EXCEEDS_FINES */ : break;
2342                                                 default:
2343                                                         throw(renew);
2344                                                 break;
2345                                         }
2346                                 }
2347                                 if (typeof async == 'function') async(renew);
2348                                 return renew;
2349                         } catch(E) {
2350                                 JSAN.use('util.error'); var error = new util.error();
2351                                 error.standard_unexpected_error_alert(document.getElementById('circStrings').getFormattedString('staff.circ.checkin.renew_failed.error', [barcode]), E);
2352                                 return null;
2353                         }
2354                 }
2355
2356                 var renew = obj.network.simple_request(
2357                         'CHECKOUT_RENEW',
2358                         [ ses(), params ],
2359                         async ? renew_callback : null,
2360                         {
2361                                 'title' : document.getElementById('circStrings').getString('staff.circ.checkin.renew_failed.override'),
2362                                 'overridable_events' : [
2363                     null /* custom event */,
2364                                         1212 /* PATRON_EXCEEDS_OVERDUE_COUNT */,
2365                                         1213 /* PATRON_BARRED */,
2366                                         1215 /* CIRC_EXCEEDS_COPY_RANGE */,
2367                     1232 /* ITEM_DEPOSIT_REQUIRED */,
2368                     1233 /* ITEM_RENTAL_FEE_REQUIRED */,
2369                                         1234 /* ITEM_DEPOSIT_PAID */,
2370                                         7002 /* PATRON_EXCEEDS_CHECKOUT_COUNT */,
2371                                         7003 /* COPY_CIRC_NOT_ALLOWED */,
2372                                         7004 /* COPY_NOT_AVAILABLE */,
2373                                         7006 /* COPY_IS_REFERENCE */,
2374                                         7007 /* COPY_NEEDED_FOR_HOLD */,
2375                                         7008 /* MAX_RENEWALS_REACHED */,
2376                                         7009 /* CIRC_CLAIMS_RETURNED */,
2377                                         7010 /* COPY_ALERT_MESSAGE */,
2378                                         7013 /* PATRON_EXCEEDS_FINES */,
2379                                 ],
2380                                 'text' : {
2381                                         '1212' : function(r) { return document.getElementById('circStrings').getFormattedString('staff.circ.renew.barcode', [barcode]); },
2382                                         '1213' : function(r) { return document.getElementById('circStrings').getFormattedString('staff.circ.renew.barcode', [barcode]); },
2383                                         '1215' : function(r) { return document.getElementById('circStrings').getFormattedString('staff.circ.renew.barcode', [barcode]); },
2384                     '1232' : function(r) {
2385                         return document.getElementById('circStrings').getFormattedString('staff.circ.renew.override.item_deposit_required.warning.barcode', [barcode]);
2386                     },
2387                     '1233' : function(r) {
2388                         return document.getElementById('circStrings').getFormattedString('staff.circ.renew.override.item_rental_fee_required.warning.barcode', [barcode]);
2389                     },
2390                                         '1234' : function(r) {
2391                                                 return document.getElementById('circStrings').getFormattedString('staff.circ.utils.checkin.override.item_deposit_paid.warning');
2392                                         },
2393                                         '7002' : function(r) { return document.getElementById('circStrings').getFormattedString('staff.circ.renew.barcode', [barcode]); },
2394                                         '7003' : function(r) { return document.getElementById('circStrings').getFormattedString('staff.circ.renew.barcode', [barcode]); },
2395                                         '7004' : function(r) {
2396                                                 return document.getElementById('circStrings').getFormattedString('staff.circ.renew.barcode.status', [barcode, r.payload.status().name()]);
2397                                         },
2398                                         '7006' : function(r) { return document.getElementById('circStrings').getFormattedString('staff.circ.renew.barcode', [barcode]); },
2399                                         '7007' : function(r) { return document.getElementById('circStrings').getFormattedString('staff.circ.renew.barcode', [barcode]); },
2400                                         '7008' : function(r) { return document.getElementById('circStrings').getFormattedString('staff.circ.renew.barcode', [barcode]); },
2401                                         '7009' : function(r) { return document.getElementById('circStrings').getFormattedString('staff.circ.renew.barcode', [barcode]); },
2402                                         '7010' : function(r) {
2403                                                 return document.getElementById('circStrings').getFormattedString('staff.circ.renew.barcode.msg', [barcode, r.payload]);
2404                                         },
2405                                         '7013' : function(r) { return document.getElementById('circStrings').getFormattedString('staff.circ.renew.barcode', [barcode]); }
2406                                 }
2407                         }
2408                 );
2409                 if (! async ) {
2410                         return renew_callback( { 'getResultObject' : function() { return renew; } } );
2411                 }
2412
2413         } catch(E) {
2414                 JSAN.use('util.error'); var error = new util.error();
2415                 error.standard_unexpected_error_alert(document.getElementById('circStrings').getFormattedString('staff.circ.checkin.renew_failed.error', [barcode]), E);
2416                 return null;
2417         }
2418 };
2419
2420 dump('exiting circ/util.js\n');