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