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