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