]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/xul/staff_client/server/patron/items.js
xul_param and modal xulG conversion
[Evergreen.git] / Open-ILS / xul / staff_client / server / patron / items.js
1 dump('entering patron.items.js\n');
2
3 if (typeof patron == 'undefined') patron = {};
4 patron.items = function (params) {
5
6         JSAN.use('util.error'); this.error = new util.error();
7         JSAN.use('util.network'); this.network = new util.network();
8         JSAN.use('OpenILS.data'); this.data = new OpenILS.data(); this.data.init({'via':'stash'});
9 }
10
11 patron.items.prototype = {
12
13         'init' : function( params ) {
14
15                 var obj = this;
16
17                 obj.patron_id = params['patron_id'];
18
19                 obj.init_lists();
20
21                 JSAN.use('util.controller'); obj.controller = new util.controller();
22                 obj.controller.init(
23                         {
24                                 'control_map' : {
25                                         'save_columns' : [ [ 'command' ], function() { obj.list.save_columns(); } ],
26                                         'save_columns2' : [ [ 'command' ], function() { obj.list2.save_columns(); } ],
27                                         'cmd_broken' : [ ['command'], function() { alert('Not Yet Implemented'); } ],
28                                         'sel_clip' : [ ['command'], function() { obj.list.clipboard(); } ],
29                                         'sel_clip2' : [ ['command'], function() { obj.list2.clipboard(); } ],
30                                         'sel_patron' : [ ['command'], function() { JSAN.use('circ.util'); circ.util.show_last_few_circs(obj.retrieve_ids); } ],
31                                         'sel_bucket' : [
32                                                 ['command'],
33                                                 function() {
34                                                         JSAN.use('cat.util');
35                                                         cat.util.add_copies_to_bucket(util.functional.map_list( obj.retrieve_ids, function(o) { return o.copy_id; } ) );
36                                                 }
37                                         ],
38                                         'sel_bucket2' : [
39                                                 ['command'],
40                                                 function() {
41                                                         JSAN.use('cat.util');
42                                                         cat.util.add_copies_to_bucket(util.functional.map_list( obj.retrieve_ids2, function(o) { return o.copy_id; } ) );
43                                                 }
44                                         ],
45                                         'sel_mark_items_damaged' : [
46                                                 ['command'],
47                                                 function() {
48                                                         JSAN.use('cat.util'); JSAN.use('util.functional');
49                                                         cat.util.mark_item_damaged( util.functional.map_list( obj.retrieve_ids, function(o) { return o.copy_id; } ) );
50                                                 }
51                                         ],
52                                         'sel_mark_items_missing' : [
53                                                 ['command'],
54                                                 function() {
55                                                         JSAN.use('cat.util'); JSAN.use('util.functional');
56                                                         cat.util.mark_item_missing( util.functional.map_list( obj.retrieve_ids, function(o) { return o.copy_id; } ) );
57                                                 }
58                                         ],
59                                         'sel_mark_items_damaged2' : [
60                                                 ['command'],
61                                                 function() {
62                                                         JSAN.use('cat.util'); JSAN.use('util.functional');
63                                                         cat.util.mark_item_damaged( util.functional.map_list( obj.retrieve_ids2, function(o) { return o.copy_id; } ) );
64                                                 }
65                                         ],
66                                         'sel_mark_items_missing2' : [
67                                                 ['command'],
68                                                 function() {
69                                                         JSAN.use('cat.util'); JSAN.use('util.functional');
70                                                         cat.util.mark_item_missing( util.functional.map_list( obj.retrieve_ids2, function(o) { return o.copy_id; } ) );
71                                                 }
72                                         ],
73                                         'sel_copy_details' : [ ['command'],
74                                                 function() {
75                                                         JSAN.use('circ.util');
76                                                         for (var i = 0; i < obj.retrieve_ids.length; i++) { circ.util.show_copy_details( obj.retrieve_ids[i].copy_id ); }
77                                                 }
78                                         ],
79                                         'sel_patron2' : [ ['command'], function() { JSAN.use('circ.util'); circ.util.show_last_few_circs(obj.retrieve_ids2); } ],
80                                         'sel_copy_details2' : [ ['command'],
81                                                 function() {
82                                                         JSAN.use('circ.util');
83                                                         for (var i = 0; i < obj.retrieve_ids2.length; i++) { circ.util.show_copy_details( obj.retrieve_ids2[i].copy_id ); }
84                                                 }
85                                         ],
86                                         'cmd_items_print' : [ ['command'], function() { obj.items_print(1); } ],
87                                         'cmd_items_print2' : [ ['command'], function() { obj.items_print(2); } ],
88                                         'cmd_items_export' : [ ['command'], function() { obj.items_export(1); } ],
89                                         'cmd_items_export2' : [ ['command'], function() { obj.items_export(2); } ],
90                                         'cmd_items_renew' : [ ['command'], function() { obj.items_renew(1); /*alert('Action complete.'); obj.retrieve();*/ } ],
91                                         'cmd_items_renew_all' : [ ['command'], function() { obj.items_renew_all(); } ],
92                                         'cmd_items_renew2' : [ ['command'], function() { obj.items_renew(2); /*alert('Action complete.'); obj.retrieve();*/ } ],
93                                         'cmd_items_edit' : [ ['command'], function() { obj.items_edit(1); alert('Action complete.'); obj.retrieve(); } ],
94                                         'cmd_items_edit2' : [ ['command'], function() { obj.items_edit(2); alert('Action complete.'); obj.retrieve(); } ],
95                                         'cmd_items_mark_lost' : [ ['command'], function() { obj.items_mark_lost(1); alert('Action complete.'); obj.retrieve(); } ],
96                                         'cmd_items_mark_lost2' : [ ['command'], function() { obj.items_mark_lost(2); alert('Action complete.'); obj.retrieve(); } ],
97                                         'cmd_items_claimed_returned' : [ ['command'], function() { obj.items_claimed_returned(1); alert('Action complete.'); obj.retrieve(); } ],
98                                         'cmd_items_claimed_returned2' : [ ['command'], function() { obj.items_claimed_returned(2); alert('Action complete.'); obj.retrieve(); } ],
99                                         'cmd_items_checkin' : [ ['command'], function() { obj.items_checkin(1); alert('Action complete.'); obj.retrieve(); } ],
100                                         'cmd_items_checkin2' : [ ['command'], function() { obj.items_checkin(2); alert('Action complete.'); obj.retrieve(); } ],
101                                         'cmd_show_catalog' : [ ['command'], function() { obj.show_catalog(1); } ],
102                                         'cmd_show_catalog2' : [ ['command'], function() { obj.show_catalog(2); } ],
103                                         'cmd_add_billing' : [ ['command'], function() { obj.add_billing(1); alert('Action complete.'); obj.retrieve(); } ],
104                                         'cmd_add_billing2' : [ ['command'], function() { obj.add_billing(2); alert('Action complete.'); obj.retrieve(); } ],
105                                         'cmd_show_noncats' : [ ['command'], function() { obj.show_noncats(); } ],
106                                 }
107                         }
108                 );
109
110                 obj.retrieve();
111
112                 obj.controller.view.sel_mark_items_damaged.setAttribute('disabled','true');
113                 obj.controller.view.sel_mark_items_missing.setAttribute('disabled','true');
114                 obj.controller.view.sel_mark_items_damaged2.setAttribute('disabled','true');
115                 obj.controller.view.sel_mark_items_missing2.setAttribute('disabled','true');
116                 obj.controller.view.sel_clip.setAttribute('disabled','true');
117                 obj.controller.view.sel_clip2.setAttribute('disabled','true');
118                 obj.controller.view.sel_bucket.setAttribute('disabled','true');
119                 obj.controller.view.sel_bucket2.setAttribute('disabled','true');
120                 obj.controller.view.sel_copy_details.setAttribute('disabled','true');
121                 obj.controller.view.sel_patron.setAttribute('disabled','true');
122                 obj.controller.view.sel_copy_details2.setAttribute('disabled','true');
123                 obj.controller.view.sel_patron2.setAttribute('disabled','true');
124                 obj.controller.view.cmd_items_claimed_returned.setAttribute('disabled','true');
125                 obj.controller.view.cmd_items_renew.setAttribute('disabled','true');
126                 obj.controller.view.cmd_items_checkin.setAttribute('disabled','true');
127                 obj.controller.view.cmd_items_edit.setAttribute('disabled','true');
128                 obj.controller.view.cmd_items_mark_lost.setAttribute('disabled','true');
129                 obj.controller.view.cmd_show_catalog.setAttribute('disabled','true');
130                 obj.controller.view.cmd_items_claimed_returned2.setAttribute('disabled','true');
131                 obj.controller.view.cmd_items_renew2.setAttribute('disabled','true');
132                 obj.controller.view.cmd_items_checkin2.setAttribute('disabled','true');
133                 obj.controller.view.cmd_items_edit2.setAttribute('disabled','true');
134                 obj.controller.view.cmd_items_mark_lost2.setAttribute('disabled','true');
135                 obj.controller.view.cmd_show_catalog2.setAttribute('disabled','true');
136         },
137
138         'show_noncats' : function() {
139                 var obj = this; var checkout = {};
140                 try {
141                         var robj = obj.network.simple_request('FM_ANCC_RETRIEVE_VIA_USER',[ ses(), obj.patron_id ]);
142                         if (typeof robj.ilsevent != 'undefined') throw(robj);
143
144                         for (var ii = 0; ii < robj.length; ii++) {
145                                 try {
146                                         var nc_circ = obj.network.simple_request('FM_ANCC_RETRIEVE_VIA_ID',[ ses(), robj[ii] ]);
147                                         if (typeof nc_circ.ilsevent != 'undefined') throw(nc_circ);
148                                         var fake_circ = new aoc();
149                                         fake_circ.circ_lib( nc_circ.circ_lib() );
150                                         fake_circ.circ_staff( nc_circ.staff() );
151                                         fake_circ.usr( nc_circ.patron() );
152                                         fake_circ.xact_start( nc_circ.circ_time() );
153                                         fake_circ.renewal_remaining(0);
154                                         fake_circ.stop_fines('Non-Cataloged');
155                                                 
156                                         JSAN.use('util.date');
157                                         var c = nc_circ.circ_time();
158                                         var d = c == "now" ? new Date() : util.date.db_date2Date( c );
159                                         var t = obj.data.hash.cnct[ nc_circ.item_type() ];
160                                         if (!t) {
161                                                 var robj2 = obj.network.simple_request('FM_CNCT_RETRIEVE',[ nc_circ.circ_lib() ]);
162                                                 if (typeof robj2.ilsevent != 'undefined') throw(robj);
163                                                 obj.data.stash_retrieve();
164                                                 for (var j = 0; j < robj2.length; j++) {
165                                                         if (! obj.data.hash.cnct[ robj2[j].id() ] ) {
166                                                                 obj.data.hash.cnct[ robj2[j].id() ] = robj2[j];
167                                                                 obj.data.list.cnct.push( robj2[j] );
168                                                         }
169                                                 }
170                                                 obj.data.stash('hash','list');
171                                                 t = obj.data.hash.cnct[ nc_circ.item_type() ];
172                                         }
173                                         var cd = t.circ_duration() || "14 days";
174                                         var i = util.date.interval_to_seconds( cd ) * 1000;
175                                         d.setTime( Date.parse(d) + i );
176                                         fake_circ.due_date( util.date.formatted_date(d,'%F') );
177         
178                                         var fake_record = new mvr();
179                                         fake_record.title( obj.data.hash.cnct[ nc_circ.item_type() ].name());
180         
181                                         var fake_copy = new acp();
182                                         fake_copy.barcode( '' );
183                                         fake_copy.circ_lib( nc_circ.circ_lib() );
184
185                                         obj.list.append( { 'row' : { 'my' : { 'circ' : fake_circ, 'mvr' : fake_record, 'acp' : fake_copy } }, 'to_bottom' : true, 'no_auto_select' : true } );
186
187                                 } catch(F) {
188                                         obj.error.standard_unexpected_error_alert('Error showing NonCat #' + robj[ii].id(),F);
189                                 }
190                         }
191
192                 } catch(E) {
193                         obj.error.standard_unexpected_error_alert('Error showing NonCat circulations',E);
194                 }
195         },
196
197         'items_print' : function(which) {
198                 var obj = this;
199                 try {
200                         var list = (which==2 ? obj.list2 : obj.list);
201                         dump(js2JSON( list.dump_with_keys() ) + '\n');
202                         function flesh_callback() {
203                                 try {
204                                         JSAN.use('patron.util');
205                                         var params = { 
206                                                 'patron' : patron.util.retrieve_fleshed_au_via_id(ses(),obj.patron_id), 
207                                                 'lib' : obj.data.hash.aou[ obj.data.list.au[0].ws_ou() ],
208                                                 'staff' : obj.data.list.au[0],
209                                                 'header' : obj.data.print_list_templates.items_out.header,
210                                                 'line_item' : obj.data.print_list_templates.items_out.line_item,
211                                                 'footer' : obj.data.print_list_templates.items_out.footer,
212                                                 'type' : obj.data.print_list_templates.items_out.type,
213                                                 'list' : list.dump_with_keys(),
214                                         };
215                                         JSAN.use('util.print'); var print = new util.print();
216                                         print.tree_list( params );
217                                         setTimeout(function(){list.on_all_fleshed = null;},0);
218                                 } catch(E) {
219                                         obj.error.standard_unexpected_error_alert('printing 2',E);
220                                 }
221                         }
222                         list.on_all_fleshed = flesh_callback;
223                         list.full_retrieve();
224                 } catch(E) {
225                         obj.error.standard_unexpected_error_alert('printing 1',E);
226                 }
227         },
228
229         'items_export' : function(which) {
230                 var obj = this;
231                 try {
232                         var list = (which==2 ? obj.list2 : obj.list);
233                         function flesh_callback() {
234                                 try {
235                                         dump( list.dump_csv() + '\n');
236                                         copy_to_clipboard(list.dump_csv());
237                                         setTimeout(function(){list.on_all_fleshed = null;},0);
238                                 } catch(E) {
239                                         obj.error.standard_unexpected_error_alert('export 2',E);
240                                 }
241                         }
242                         list.on_all_fleshed = flesh_callback;
243                         list.full_retrieve();
244                 } catch(E) {
245                         obj.error.standard_unexpected_error_alert('export 1',E);
246                 }
247         },
248
249         'items_renew_all' : function() {
250                 try {
251                         var obj = this; var list = obj.list;
252                         if (list.on_all_fleshed != null) {
253                                 var r = window.confirm('This is list is busy retrieving/rendering rows for a prior action.  Abort the prior action and proceed?');
254                                 if (!r) return;
255                         }
256                         var r = window.confirm('Renew all the items in this list?');
257                         if (!r) return;
258                         function flesh_callback() {
259                                 try {
260                                         obj.list.select_all();
261                                         obj.items_renew(1,true);        
262                                         setTimeout(function(){list.on_all_fleshed = null; /*alert('Action complete.'); obj.retrieve();*/ },0);
263                                 } catch(E) {
264                                         obj.error.standard_unexpected_error_alert('2 All items were not likely renewed',E);
265                                 }
266                         }
267                         list.on_all_fleshed = flesh_callback;
268                         list.full_retrieve();
269                 } catch(E) {
270                         this.error.standard_unexpected_error_alert('All items were not likely renewed',E);
271                 }
272         },
273
274         'items_renew' : function(which,skip_prompt) {
275                 var obj = this;
276                 try{
277                         JSAN.use('circ.util');
278                         var retrieve_ids = ( which == 2 ? obj.retrieve_ids2 : obj.retrieve_ids );
279                         if (!retrieve_ids || retrieve_ids.length == 0) return;
280                         JSAN.use('util.functional');
281                         if (!skip_prompt) {
282                                 var msg = 'Are you sure you would like to renew item' + ( retrieve_ids.length > 1 ? 's ' : ' ') + util.functional.map_list( retrieve_ids, function(o){return o.barcode;}).join(', ') + '?';
283                                 var r = window.confirm(msg);
284                                 if (!r) { return; }
285                         }
286
287                         var count = 0;
288
289                         function gen_renew(bc) {
290                                 var x = document.getElementById('renew_msgs');
291                                 if (x) {
292                                         var l = document.createElement('label');
293                                         l.setAttribute('value','Renewing ' + bc);
294                                         x.appendChild(l);
295                                 }
296                                 var renew = circ.util.renew_via_barcode( barcode, obj.patron_id, 
297                                         function(r) {
298                                                 if ( instanceOf( r[0], 'circ' ) || (typeof r[0].ilsevent != 'undefined' && r[0].ilsevent == 0) ) {
299                                                         l.setAttribute('value', bc + ' renewed.');
300                                                 } else {
301                                                         l.setAttribute('value', bc + ' not renewed.  ' + r[0].desc);
302                                                 }
303                                                 count--;
304                                                 if (count == 0) {
305                                                         if (window.confirm('Action completed. Refresh list?')) obj.retrieve();
306                                                         JSAN.use('util.widgets'); util.widgets.remove_children(x);
307                                                 }
308                                         } 
309                                 );
310                         }
311
312                         for (var i = 0; i < retrieve_ids.length; i++) {
313                                 try {
314                                         count++;
315                                         var barcode = retrieve_ids[i].barcode;
316                                         gen_renew(barcode);
317
318                                 } catch(E) {
319                                         obj.error.standard_unexpected_error_alert('Renew probably did not happen for barcode ' + barcode,E);
320                                 }
321                         }
322                 } catch(E) {
323                         obj.error.standard_unexpected_error_alert('Renew probably did not happen.',E);
324                 }
325         },
326
327         'items_edit' : function(which) {
328                         var obj = this;
329                         try {
330                                 var retrieve_ids = ( which == 2 ? obj.retrieve_ids2 : obj.retrieve_ids );
331                                 if (!retrieve_ids || retrieve_ids.length == 0) return;
332                                 function check_date(value) {
333                                         JSAN.use('util.date');
334                                         try {
335                                                 if (! util.date.check('YYYY-MM-DD',value) ) { 
336                                                         throw('Invalid Date'); 
337                                                 }
338                                                 if (util.date.check_past('YYYY-MM-DD',value) ) { 
339                                                         throw('Due date needs to be after today.'); 
340                                                 }
341                                                 /*
342                                                 if ( util.date.formatted_date(new Date(),'%F') == value) { 
343                                                         throw('Due date needs to be after today.'); 
344                                                 }
345                                                 */
346                                                 return true;
347                                         } catch(E) {
348                                                 alert(E);
349                                                 return false;
350                                         }
351                                 }
352
353                                 JSAN.use('util.functional');
354                                 var title = 'Edit Due Date' + (retrieve_ids.length > 1 ? 's' : '');
355                                 var value = 'YYYY-MM-DD';
356                                 var text = 'Enter a new due date for these items: ' + 
357                                         util.functional.map_list(retrieve_ids,function(o){return o.barcode;}).join(', ');
358                                 var due_date; var invalid = true;
359                                 while(invalid) {
360                                         due_date = window.prompt(text,value,title);
361                                         if (due_date) {
362                                                 invalid = ! check_date(due_date);
363                                         } else {
364                                                 invalid = false;
365                                         }
366                                 }
367                                 if (due_date) {
368                                         var circs = util.functional.map_list(retrieve_ids,function(o){return o.circ_id;});
369                                         for (var i = 0; i < circs.length; i++) {
370                                                 var robj = obj.network.simple_request('FM_CIRC_EDIT_DUE_DATE',[ses(),circs[i],due_date]);
371                                                 if (typeof robj.ilsevent != 'undefined') { if (robj.ilsevent != 0) throw(robj); }
372                                         }
373                                 }
374                         } catch(E) {
375                                 obj.error.standard_unexpected_error_alert('The due dates were not likely modified.',E);
376                         }
377         },
378
379         'items_mark_lost' : function(which) {
380                 var obj = this;
381                 try {
382                         var retrieve_ids = ( which == 2 ? obj.retrieve_ids2 : obj.retrieve_ids );
383                         if (!retrieve_ids || retrieve_ids.length == 0) return;
384                         for (var i = 0; i < retrieve_ids.length; i++) {
385                                 var barcode = retrieve_ids[i].barcode;
386                                 dump('Mark barcode lost = ' + barcode);
387                                 var robj = obj.network.simple_request( 'MARK_ITEM_LOST', [ ses(), { barcode: barcode } ]);
388                                 if (typeof robj.ilsevent != 'undefined') { if (robj.ilsevent != 0) throw(robj); }
389                         }
390                 } catch(E) {
391                         obj.error.standard_unexpected_error_alert('The items were not likely marked lost.',E);
392                 }
393         },
394
395         'items_claimed_returned' : function(which) {
396                 var obj = this;
397                 try {
398                         JSAN.use('util.date');
399                         var retrieve_ids = ( which == 2 ? obj.retrieve_ids2 : obj.retrieve_ids );
400                         if (!retrieve_ids || retrieve_ids.length == 0) return;
401                         function check_date(value) {
402                                 try {
403                                         if (! util.date.check('YYYY-MM-DD',value) ) { 
404                                                 throw('Invalid Date'); 
405                                         }
406                                         if ( util.date.formatted_date(new Date(),'%F') == value) { 
407                                                 return true;
408                                         }
409                                         if (! util.date.check_past('YYYY-MM-DD',value) ) { 
410                                                 throw('Claims Returned Date cannot be in the future.'); 
411                                         }
412                                         return true;
413                                 } catch(E) {
414                                         alert(E);
415                                         return false;
416                                 }
417                         }
418
419                         JSAN.use('util.functional');
420                         var title = 'Claimed Returned';
421                         var value = 'YYYY-MM-DD';
422                         var text = 'Enter a claimed returned date for these items: ' + 
423                                 util.functional.map_list(retrieve_ids,function(o){return o.barcode;}).join(', ');
424                         var backdate; var invalid = true;
425                         while(invalid) {
426                                 backdate = window.prompt(text,value,title);
427                                 if (backdate) {
428                                         invalid = ! check_date(backdate);
429                                 } else {
430                                         invalid = false;
431                                 }
432                         }
433                         //alert('backdate = ' + backdate);
434                         if (backdate) {
435                                 backdate = util.date.formatted_date(backdate + ' 00:00:00','%{iso8601}');
436                                 var barcodes = util.functional.map_list(retrieve_ids,function(o){return o.barcode;});
437                                 for (var i = 0; i < barcodes.length; i++) {
438                                         var robj = obj.network.simple_request(
439                                                 'MARK_ITEM_CLAIM_RETURNED', 
440                                                 [ ses(), { barcode: barcodes[i], backdate: backdate } ]
441                                         );
442                                         if (typeof robj.ilsevent != 'undefined') { if (robj.ilsevent != 0) throw(robj); }
443                                 }
444                         }
445                 } catch(E) {
446                         obj.error.standard_unexpected_error_alert('The items were not likely marked Claimed Returned.',E);
447                 }
448         },
449
450         'items_checkin' : function(which) {
451                 var obj = this;
452                 try {
453                         var retrieve_ids = ( which == 2 ? obj.retrieve_ids2 : obj.retrieve_ids );
454                         if (!retrieve_ids || retrieve_ids.length == 0) return;
455                         JSAN.use('util.functional');
456                         var msg = 'Are you sure you would like to check in item' + ( retrieve_ids.length > 1 ? 's ' : ' ') + util.functional.map_list( retrieve_ids, function(o){return o.barcode;}).join(', ') + '?';
457                         var r = window.confirm(msg);
458                         if (!r) { return; }
459                         JSAN.use('circ.util');
460                         for (var i = 0; i < retrieve_ids.length; i++) {
461                                 var copy_id = retrieve_ids[i].copy_id;
462                                 dump('Check in copy_id = ' + copy_id + ' barcode = ' + retrieve_ids[i].barcode + '\n');
463                                 var robj = circ.util.checkin_via_barcode(
464                                         ses(), { 'copy_id' : copy_id }
465                                 );
466                                 /* circ.util.checkin_via_barcode handles errors currently */
467                         }
468                 } catch(E) {
469                         obj.error.standard_unexpected_error_alert('Checkin probably did not happen.',E);
470                 }
471         },
472
473         'show_catalog' : function(which) {
474                 var obj = this;
475                 try {
476                         var retrieve_ids = ( which == 2 ? obj.retrieve_ids2 : obj.retrieve_ids );
477                         if (!retrieve_ids || retrieve_ids.length == 0) return;
478                         for (var i = 0; i < retrieve_ids.length; i++) {
479                                 var doc_id = retrieve_ids[i].doc_id;
480                                 if (!doc_id) {
481                                         alert(retrieve_ids[i].barcode + ' is not cataloged');
482                                         continue;
483                                 }
484                                 var opac_url = xulG.url_prefix( urls.opac_rdetail ) + '?r=' + doc_id;
485                                 var content_params = { 
486                                         'session' : ses(),
487                                         'authtime' : ses('authtime'),
488                                         'opac_url' : opac_url,
489                                 };
490                                 xulG.new_tab(
491                                         xulG.url_prefix(urls.XUL_OPAC_WRAPPER), 
492                                         {'tab_name':'Retrieving title...'}, 
493                                         content_params
494                                 );
495                         }
496                 } catch(E) {
497                         obj.error.standard_unexpected_error_alert('',E);
498                 }
499         },
500
501         'add_billing' : function(which) {
502                 var obj = this;
503                 try {
504                         var retrieve_ids = ( which == 2 ? obj.retrieve_ids2 : obj.retrieve_ids );
505                         if (!retrieve_ids || retrieve_ids.length == 0) return;
506                         JSAN.use('util.window'); var win = new util.window();
507                         for (var i = 0; i < retrieve_ids.length; i++) {
508                                 var circ_id = retrieve_ids[i].circ_id;
509                                 var my_xulG = win.open(
510                                         urls.XUL_PATRON_BILL_WIZARD,
511                                                 //+ '?patron_id=' + window.escape(obj.patron_id)
512                                                 //+ '&xact_id=' + window.escape( circ_id ),
513                                         'billwizard',
514                                         'chrome,resizable,modal',
515                                         { 'patron_id' : obj.patron_id, 'xact_id' : circ_id }
516                                 );
517                         }
518                 } catch(E) {
519                         obj.error.standard_unexpected_error_alert('',E);
520                 }
521         },
522
523         'init_lists' : function() {
524                 var obj = this;
525
526                 JSAN.use('circ.util');
527                 var columns = circ.util.columns( 
528                         { 
529                                 'barcode' : { 'hidden' : false },
530                                 'checkout_lib' : { 'hidden' : false },
531                                 'circ_lib' : { 'hidden' : false },
532                                 'title' : { 'hidden' : false, 'flex' : '3' },
533                                 'due_date' : { 'hidden' : false },
534                                 'renewal_remaining' : { 'hidden' : false },
535                                 'stop_fines' : { 'hidden' : false },
536                         } 
537                 );
538                 var columns2 = circ.util.columns( 
539                         { 
540                                 'barcode' : { 'hidden' : false },
541                                 'checkout_lib' : { 'hidden' : false },
542                                 'circ_lib' : { 'hidden' : false },
543                                 'title' : { 'hidden' : false, 'flex' : '3' },
544                                 'checkin_time' : { 'hidden' : false },
545                                 'stop_fines' : { 'hidden' : false },
546                         } 
547                 );
548
549                 function retrieve_row(params) {
550                         var row = params.row;
551
552                         if (!row.my.circ_id) {
553                                 if (typeof params.on_retrieve == 'function') { params.on_retrieve(row); }
554                                 return row;
555                         }
556
557                         obj.network.simple_request(
558                                 'FM_CIRC_DETAILS',
559                                 [ row.my.circ_id ],
560                                 function(req) {
561                                         try { 
562                                                 var robj = req.getResultObject();
563                                                 if (typeof robj.ilsevent != 'undefined') throw(robj);
564                                                 if (typeof robj.ilsevent == 'null') throw('null result');
565                                                 row.my.circ = robj.circ;
566                                                 row.my.acp = robj.copy;
567                                                 row.my.mvr = robj.mvr;
568                                                 row.my.acn = robj.volume;
569
570                                                 var copy_id = row.my.circ.target_copy();
571                                                 if (typeof copy_id == 'object') {
572                                                         if (copy_id != null) {
573                                                                 copy_id = copy_id.id();
574                                                         } else {
575                                                                 if (typeof robj.copy == 'object' && robj.copy != null) copy_id = robj.copy.id();
576                                                         }
577                                                 } else {
578                                                                 if (typeof robj.copy == 'object' && robj.copy != null) copy_id = robj.copy.id();
579                                                 }
580                                                 
581                                                 params.row_node.setAttribute( 'retrieve_id', js2JSON({'copy_id':copy_id,'circ_id':row.my.circ.id(),'barcode':row.my.acp.barcode(),'doc_id': (robj.record ? robj.record.id() : null) }) );
582         
583                                                 if (typeof params.on_retrieve == 'function') {
584                                                         params.on_retrieve(row);
585                                                 }
586                                         } catch(E) {
587                                                 obj.error.standard_unexpected_error_alert('Error in callback for FM_CIRC_DETAILS in patron/items.js',E);
588                                         }
589                                 }
590                         );
591
592                         return row;
593                 }
594
595                 JSAN.use('util.list'); obj.list = new util.list('items_list');
596                 obj.list.init(
597                         {
598                                 'columns' : columns,
599                                 'map_row_to_columns' : circ.util.std_map_row_to_columns(),
600                                 'retrieve_row' : retrieve_row,
601                                 'on_select' : function(ev) {
602                                         JSAN.use('util.functional');
603                                         var sel = obj.list.retrieve_selection();
604                                         obj.controller.view.sel_clip.setAttribute('disabled',sel.length < 1);
605                                         var list = util.functional.map_list(
606                                                 sel,
607                                                 function(o) { return JSON2js( o.getAttribute('retrieve_id') ); }
608                                         );
609                                         if (typeof obj.on_select == 'function') {
610                                                 obj.on_select(list);
611                                         }
612                                         if (typeof window.xulG == 'object' && typeof window.xulG.on_select == 'function') {
613                                                 obj.error.sdump('D_PATRON','patron.items: Calling external .on_select()\n');
614                                                 window.xulG.on_select(list);
615                                         } else {
616                                                 obj.error.sdump('D_PATRON','patron.items: No external .on_select()\n');
617                                         }
618                                 },
619                         }
620                 );
621                 
622                 obj.list2 = new util.list('items_list2');
623                 obj.list2.init(
624                         {
625                                 'columns' : columns2,
626                                 'map_row_to_columns' : circ.util.std_map_row_to_columns(),
627                                 'retrieve_row' : retrieve_row,
628                                 'on_select' : function(ev) {
629                                         JSAN.use('util.functional');
630                                         var sel = obj.list2.retrieve_selection();
631                                         obj.controller.view.sel_clip2.setAttribute('disabled',sel.length < 1);
632                                         var list = util.functional.map_list(
633                                                 sel,
634                                                 function(o) { return JSON2js( o.getAttribute('retrieve_id') ); }
635                                         );
636                                         if (typeof obj.on_select2 == 'function') {
637                                                 obj.on_select2(list);
638                                         }
639                                 },
640                         }
641                 );
642         },
643
644         'retrieve' : function(dont_show_me_the_list_change) {
645                 var obj = this;
646                 if (window.xulG && window.xulG.checkouts) {
647                         obj.checkouts = window.xulG.checkouts;
648                 } else {
649                         obj.checkouts = [];
650                         obj.checkouts2 = [];
651                         var robj = obj.network.simple_request(
652                                 'FM_CIRC_RETRIEVE_VIA_USER',
653                                 [ ses(), obj.patron_id ]
654                         );
655                         if (typeof robj.ilsevent!='undefined') {
656                                 obj.error.standard_unexpected_error_alert('Error retrieving circulations.',E);
657                         } else {
658                                 obj.checkouts = obj.checkouts.concat( robj.overdue );
659                                 obj.checkouts = obj.checkouts.concat( robj.out );
660                                 obj.checkouts2 = obj.checkouts2.concat( robj.lost );
661                                 obj.checkouts2 = obj.checkouts2.concat( robj.claims_returned );
662                                 obj.checkouts2 = obj.checkouts2.concat( robj.long_overdue );
663                         }
664                         var robj = obj.network.simple_request(
665                                 'FM_CIRC_IN_WITH_FINES_VIA_USER',
666                                 [ ses(), obj.patron_id ]
667                         );
668                         if (typeof robj.ilsevent!='undefined') {
669                                 obj.error.standard_unexpected_error_alert('Error retrieving circulations.',E);
670                         } else {
671                                 obj.checkouts2 = obj.checkouts2.concat( robj.lost );
672                                 obj.checkouts2 = obj.checkouts2.concat( robj.claims_returned );
673                                 obj.checkouts2 = obj.checkouts2.concat( robj.long_overdue );
674                         }
675                 }
676
677                 function gen_list_append(circ_id,which_list) {
678                         return function() {
679                                 try {
680                                         switch(which_list) {
681                                                 case 1:
682                                                         obj.list2.append( { 'row' : { 'my' : { 'circ_id' : circ_id } },  'to_bottom' : true } );
683                                                 break;
684                                                 default:
685                                                         obj.list.append( { 'row' : { 'my' : { 'circ_id' : circ_id } }, 'to_bottom' : true } );
686                                                 break;
687                                         }
688                                 } catch(E) {
689                                         alert(E);
690                                 }
691                         };
692                 }
693
694                 obj.list.clear(); obj.list2.clear();
695
696                 JSAN.use('util.exec'); var exec = new util.exec();
697                 var rows = [];
698                 for (var i in obj.checkouts) {
699                         rows.push( gen_list_append(obj.checkouts[i],0) );
700                 }
701                 for (var i in obj.checkouts2) {
702                         rows.push( gen_list_append(obj.checkouts2[i],1) );
703                 }
704                 exec.chain( rows );
705                 if (!dont_show_me_the_list_change) {
706                         if (window.xulG && typeof window.xulG.on_list_change == 'function') {
707                                 try { window.xulG.on_list_change(obj.checkouts); } catch(E) { this.error.sdump('D_ERROR',E); }
708                         }
709                 }
710         },
711
712         'on_select' : function(list) {
713
714                 dump('patron.items.on_select list = ' + js2JSON(list) + '\n');
715
716                 var obj = this;
717
718                 obj.controller.view.cmd_items_claimed_returned.setAttribute('disabled','false');
719                 obj.controller.view.cmd_items_renew.setAttribute('disabled','false');
720                 obj.controller.view.cmd_items_checkin.setAttribute('disabled','false');
721                 obj.controller.view.cmd_items_edit.setAttribute('disabled','false');
722                 obj.controller.view.cmd_items_mark_lost.setAttribute('disabled','false');
723                 obj.controller.view.cmd_show_catalog.setAttribute('disabled','false');
724                 obj.controller.view.sel_copy_details.setAttribute('disabled','false');
725                 obj.controller.view.sel_bucket.setAttribute('disabled','false');
726                 obj.controller.view.sel_patron.setAttribute('disabled','false');
727                 obj.controller.view.sel_mark_items_damaged.setAttribute('disabled','false');
728                 obj.controller.view.sel_mark_items_missing.setAttribute('disabled','false');
729
730                 obj.retrieve_ids = list;
731         },
732
733         'on_select2' : function(list) {
734         
735                 dump('patron.items.on_select2 list = ' + js2JSON(list) + '\n');
736
737                 var obj = this;
738
739                 obj.controller.view.cmd_items_claimed_returned2.setAttribute('disabled','false');
740                 obj.controller.view.cmd_items_renew2.setAttribute('disabled','false');
741                 obj.controller.view.cmd_items_checkin2.setAttribute('disabled','false');
742                 obj.controller.view.cmd_items_edit2.setAttribute('disabled','false');
743                 obj.controller.view.cmd_items_mark_lost2.setAttribute('disabled','false');
744                 obj.controller.view.cmd_show_catalog2.setAttribute('disabled','false');
745                 obj.controller.view.sel_copy_details2.setAttribute('disabled','false');
746                 obj.controller.view.sel_bucket2.setAttribute('disabled','false');
747                 obj.controller.view.sel_patron2.setAttribute('disabled','false');
748                 obj.controller.view.sel_mark_items_damaged2.setAttribute('disabled','false');
749                 obj.controller.view.sel_mark_items_missing2.setAttribute('disabled','false');
750
751                 this.retrieve_ids2 = list;
752         },
753
754 }
755
756 dump('exiting patron.items.js\n');