463f15e0358dffa2a686c80aefb6b4a2705180c1
[working/Evergreen.git] / Open-ILS / xul / staff_client / server / patron / items.js
1 dump('entering patron.items.js\n');
2
3 function $(id) { return document.getElementById(id); }
4
5 if (typeof patron == 'undefined') patron = {};
6 patron.items = function (params) {
7
8     JSAN.use('util.error'); this.error = new util.error();
9     JSAN.use('util.network'); this.network = new util.network();
10     JSAN.use('OpenILS.data'); this.data = new OpenILS.data(); this.data.init({'via':'stash'});
11     JSAN.use('util.sound'); this.sound = new util.sound();
12 }
13
14 patron.items.prototype = {
15
16     'list_circ_map' : {},
17     'list_circ_map_by_copy' : {},
18
19     'init' : function( params ) {
20
21         var obj = this;
22
23         obj.patron_id = params['patron_id'];
24
25         obj.init_lists();
26
27         JSAN.use('util.controller'); obj.controller = new util.controller();
28         obj.controller.init(
29             {
30                 'control_map' : {
31                     'save_columns' : [ [ 'command' ], function() { obj.list.save_columns(); } ],
32                     'save_columns2' : [ [ 'command' ], function() { obj.list2.save_columns(); } ],
33                     'cmd_broken' : [ ['command'], function() { alert('Not Yet Implemented'); } ],
34                     'sel_clip' : [ ['command'], function() { obj.list.clipboard(); } ],
35                     'sel_clip2' : [ ['command'], function() { obj.list2.clipboard(); } ],
36                     'sel_edit' : [ ['command'], function() { obj.spawn_copy_editor(1); } ],
37                     'sel_edit2' : [ ['command'], function() { obj.spawn_copy_editor(2); } ],
38                     'sel_patron' : [ ['command'], function() { JSAN.use('circ.util'); circ.util.show_last_few_circs(obj.retrieve_ids); } ],
39                     'cmd_triggered_events' : [
40                         ['command'],
41                         function() {
42                             try {
43                                 var copy_ids = util.functional.map_list( obj.retrieve_ids, function(o) { return o.copy_id; } ); 
44                                 var barcodes = util.functional.map_list( obj.retrieve_ids, function(o) { return o.barcode; } ); 
45                                 for (var i = 0; i < copy_ids.length; i++) {
46                                     xulG.new_tab(
47                                         xulG.url_prefix(urls.XUL_REMOTE_BROWSER),
48                                         {
49                                             'tab_name' : document.getElementById('commonStrings').getFormattedString('tab.label.triggered_events_for_copy',[ barcodes[i] ])
50                                         },
51                                         {
52                                             'url': urls.EG_TRIGGER_EVENTS + "?copy_id=" + copy_ids[i],
53                                             'show_nav_buttons': false,
54                                             'show_print_button': false
55                                         }
56                                     );
57                                 }
58                             } catch(E) {
59                                 alert('Error in items.js, cmd_triggered_events: ' + E);
60                             }
61                         }
62                     ],
63                     'cmd_triggered_events2' : [
64                         ['command'],
65                         function() {
66                             try {
67                                 var copy_ids = util.functional.map_list( obj.retrieve_ids2, function(o) { return o.copy_id; } ); 
68                                 for (var i = 0; i < copy_ids.length; i++) {
69                                     xulG.new_tab(
70                                         xulG.url_prefix(urls.XUL_REMOTE_BROWSER),
71                                         {},
72                                         {
73                                             'url': urls.EG_TRIGGER_EVENTS + "?copy_id=" + copy_ids[i],
74                                             'show_nav_buttons': false,
75                                             'show_print_button': false
76                                         }
77                                     );
78                                 }
79                             } catch(E) {
80                                 alert('Error in copy_status.js, cmd_triggered_events: ' + E);
81                             }
82                         }
83                     ],
84
85                     'sel_bucket' : [
86                         ['command'],
87                         function() {
88                             JSAN.use('cat.util');
89                             cat.util.add_copies_to_bucket(util.functional.map_list( obj.retrieve_ids, function(o) { return o.copy_id; } ) );
90                         }
91                     ],
92                     'sel_bucket2' : [
93                         ['command'],
94                         function() {
95                             JSAN.use('cat.util');
96                             cat.util.add_copies_to_bucket(util.functional.map_list( obj.retrieve_ids2, function(o) { return o.copy_id; } ) );
97                         }
98                     ],
99                     'sel_mark_items_damaged' : [
100                         ['command'],
101                         function() {
102                             JSAN.use('cat.util'); JSAN.use('util.functional');
103                             cat.util.mark_item_damaged( util.functional.map_list( obj.retrieve_ids, function(o) { return o.copy_id; } ) );
104                         }
105                     ],
106                     'sel_mark_items_missing' : [
107                         ['command'],
108                         function() {
109                             JSAN.use('cat.util'); JSAN.use('util.functional');
110                             cat.util.mark_item_missing( util.functional.map_list( obj.retrieve_ids, function(o) { return o.copy_id; } ) );
111                         }
112                     ],
113                     'sel_mark_items_damaged2' : [
114                         ['command'],
115                         function() {
116                             JSAN.use('cat.util'); JSAN.use('util.functional');
117                             cat.util.mark_item_damaged( util.functional.map_list( obj.retrieve_ids2, function(o) { return o.copy_id; } ) );
118                         }
119                     ],
120                     'sel_mark_items_missing2' : [
121                         ['command'],
122                         function() {
123                             JSAN.use('cat.util'); JSAN.use('util.functional');
124                             cat.util.mark_item_missing( util.functional.map_list( obj.retrieve_ids2, function(o) { return o.copy_id; } ) );
125                         }
126                     ],
127                     'sel_copy_details' : [ ['command'],
128                         function() {
129                             JSAN.use('circ.util');
130                             circ.util.item_details_new(
131                                 util.functional.map_list(
132                                     obj.retrieve_ids,
133                                     function(o) { return o.barcode; }
134                                 )
135                             );
136                         }
137                     ],
138                     'sel_patron2' : [ ['command'], function() { JSAN.use('circ.util'); circ.util.show_last_few_circs(obj.retrieve_ids2); } ],
139                     'sel_copy_details2' : [ ['command'],
140                         function() {
141                             JSAN.use('circ.util');
142                             circ.util.item_details_new(
143                                 util.functional.map_list(
144                                     obj.retrieve_ids2,
145                                     function(o) { return o.barcode; }
146                                 )
147                             );
148                         }
149                     ],
150                     'cmd_items_print' : [ ['command'], function() { obj.items_print(1); } ],
151                     'cmd_items_print2' : [ ['command'], function() { obj.items_print(2); } ],
152                     'cmd_items_print_selected' : [ ['command'], function() { obj.items_print_selected(1); } ],
153                     'cmd_items_print_selected2' : [ ['command'], function() { obj.items_print_selected(2); } ],
154                     'cmd_items_export' : [ ['command'], function() { obj.items_export(1); } ],
155                     'cmd_items_export2' : [ ['command'], function() { obj.items_export(2); } ],
156                     'cmd_items_renew' : [ ['command'], function() { obj.items_renew({which_list:1}); } ],
157                     'cmd_items_renew_with_date' : [ ['command'], function() { obj.items_renew({which_list:1,skip_prompt:true,get_date:true}); } ],
158                     'cmd_items_renew_all' : [ ['command'], function() { obj.items_renew_all({which_list:1}); } ],
159                     'cmd_items_renew2' : [ ['command'], function() { obj.items_renew({which_list:2}); } ],
160                     'cmd_items_renew_with_date2' : [ ['command'], function() { obj.items_renew({which_list:2,skip_prompt:true,get_date:true}); } ],
161                     'cmd_items_edit' : [ ['command'], function() { obj.items_edit(1);  obj.refresh_outer_interfaces(); } ],
162                     'cmd_items_edit2' : [ ['command'], function() { obj.items_edit(2);  obj.refresh_outer_interfaces(); } ],
163                     'cmd_items_mark_lost' : [ ['command'], function() { obj.items_mark_lost(1);  obj.refresh_outer_interfaces(); } ],
164                     'cmd_items_mark_lost2' : [ ['command'], function() { obj.items_mark_lost(2);  obj.refresh_outer_interfaces(); } ],
165                     'cmd_items_claimed_returned' : [ ['command'], function() { obj.items_claimed_returned(1);  obj.refresh_outer_interfaces(); } ],
166                     'cmd_items_claimed_returned2' : [ ['command'], function() { obj.items_claimed_returned(2);  obj.refresh_outer_interfaces(); } ],
167                     'cmd_items_claimed_never_checked_out' : [
168                         ['command'],
169                         function() {
170                             obj.items_checkin(
171                                 1,{'claims_never_checked_out':true}
172                             );
173                         }
174                     ],
175                     'cmd_items_claimed_never_checked_out2' : [
176                         ['command'],
177                         function() {
178                             obj.items_checkin(
179                                 2,{'claims_never_checked_out':true}
180                             );
181                         }
182                     ],
183                     'cmd_items_checkin' : [ ['command'], function() { obj.items_checkin(1);  obj.refresh_outer_interfaces(); } ],
184                     'cmd_items_checkin2' : [ ['command'], function() { obj.items_checkin(2);  obj.refresh_outer_interfaces(); } ],
185                     'cmd_show_catalog' : [ ['command'], function() { obj.show_catalog(1); } ],
186                     'cmd_show_catalog2' : [ ['command'], function() { obj.show_catalog(2); } ],
187                     'cmd_add_billing' : [ ['command'], function() { obj.add_billing(1);  obj.refresh_outer_interfaces(); } ],
188                     'cmd_add_billing2' : [ ['command'], function() { obj.add_billing(2);  obj.refresh_outer_interfaces(); } ],
189                     'cmd_show_noncats' : [ ['command'], function() { obj.show_noncats(); } ]
190                 }
191             }
192         );
193
194         obj.retrieve();
195
196         obj.controller.view.sel_mark_items_damaged.setAttribute('disabled','true');
197         obj.controller.view.sel_mark_items_missing.setAttribute('disabled','true');
198         obj.controller.view.sel_mark_items_damaged2.setAttribute('disabled','true');
199         obj.controller.view.sel_mark_items_missing2.setAttribute('disabled','true');
200         obj.controller.view.sel_clip.setAttribute('disabled','true');
201         obj.controller.view.sel_clip2.setAttribute('disabled','true');
202         obj.controller.view.sel_edit.setAttribute('disabled','true');
203         obj.controller.view.sel_edit2.setAttribute('disabled','true');
204         obj.controller.view.sel_bucket.setAttribute('disabled','true');
205         obj.controller.view.sel_bucket2.setAttribute('disabled','true');
206         obj.controller.view.sel_copy_details.setAttribute('disabled','true');
207         obj.controller.view.sel_patron.setAttribute('disabled','true');
208         obj.controller.view.cmd_triggered_events.setAttribute('disabled','true');
209         obj.controller.view.sel_copy_details2.setAttribute('disabled','true');
210         obj.controller.view.sel_patron2.setAttribute('disabled','true');
211         obj.controller.view.cmd_triggered_events2.setAttribute('disabled','true');
212         obj.controller.view.cmd_items_claimed_returned.setAttribute('disabled','true');
213         obj.controller.view.cmd_items_claimed_never_checked_out.setAttribute('disabled','true');
214         obj.controller.view.cmd_items_renew.setAttribute('disabled','true');
215         obj.controller.view.cmd_items_renew_with_date.setAttribute('disabled','true');
216         obj.controller.view.cmd_items_checkin.setAttribute('disabled','true');
217         obj.controller.view.cmd_items_edit.setAttribute('disabled','true');
218         obj.controller.view.cmd_items_mark_lost.setAttribute('disabled','true');
219         obj.controller.view.cmd_show_catalog.setAttribute('disabled','true');
220         obj.controller.view.cmd_items_claimed_returned2.setAttribute('disabled','true');
221         obj.controller.view.cmd_items_claimed_never_checked_out2.setAttribute('disabled','true');
222         obj.controller.view.cmd_items_renew2.setAttribute('disabled','true');
223         obj.controller.view.cmd_items_renew_with_date2.setAttribute('disabled','true');
224         obj.controller.view.cmd_items_checkin2.setAttribute('disabled','true');
225         obj.controller.view.cmd_items_edit2.setAttribute('disabled','true');
226         obj.controller.view.cmd_items_mark_lost2.setAttribute('disabled','true');
227         obj.controller.view.cmd_show_catalog2.setAttribute('disabled','true');
228     },
229
230     'cleanup' : function() {
231         var obj = this;
232         obj.list.cleanup();
233         obj.list.clear();
234         obj.list2.cleanup();
235         obj.list2.clear();
236     },
237
238     'show_noncats' : function() {
239         var obj = this; var checkout = {};
240         try {
241             var robj = obj.network.simple_request('FM_ANCC_RETRIEVE_VIA_USER.authoritative',[ ses(), obj.patron_id ]);
242             if (typeof robj.ilsevent != 'undefined') throw(robj);
243
244             for (var ii = 0; ii < robj.length; ii++) {
245                 try {
246                     var nc_circ = obj.network.simple_request('FM_ANCC_RETRIEVE_VIA_ID',[ ses(), robj[ii] ]);
247                     if (typeof nc_circ.ilsevent != 'undefined') throw(nc_circ);
248                     var fake_circ = new aoc();
249                     fake_circ.circ_lib( nc_circ.circ_lib() );
250                     fake_circ.circ_staff( nc_circ.staff() );
251                     fake_circ.usr( nc_circ.patron() );
252                     fake_circ.xact_start( nc_circ.circ_time() );
253                     fake_circ.renewal_remaining(0);
254                     fake_circ.stop_fines('Non-Cataloged');
255                     fake_circ.due_date( nc_circ.duedate() );
256                         
257                     if (!obj.data.hash.cnct[ nc_circ.item_type() ]) {
258                         var robj2 = obj.network.simple_request('FM_CNCT_RETRIEVE',[ nc_circ.circ_lib() ]);
259                         if (typeof robj2.ilsevent != 'undefined') throw(robj);
260                         obj.data.stash_retrieve();
261                         for (var j = 0; j < robj2.length; j++) {
262                             if (! obj.data.hash.cnct[ robj2[j].id() ] ) {
263                                 obj.data.hash.cnct[ robj2[j].id() ] = robj2[j];
264                                 obj.data.list.cnct.push( robj2[j] );
265                             }
266                         }
267                         obj.data.stash('hash','list');
268                     }
269     
270                     var fake_record = new mvr();
271                     fake_record.title( obj.data.hash.cnct[ nc_circ.item_type() ].name());
272     
273                     var fake_copy = new acp();
274                     fake_copy.barcode( '' );
275                     fake_copy.circ_lib( nc_circ.circ_lib() );
276
277                     obj.list.append( { 'row' : { 'my' : { 'circ' : fake_circ, 'mvr' : fake_record, 'acp' : fake_copy } }, 'to_bottom' : true, 'no_auto_select' : true } );
278
279                 } catch(F) {
280                     obj.error.standard_unexpected_error_alert($("patronStrings").getFormattedString('staff.patron.items.show_noncats.err_showing_noncat', [robj[ii].id()]),F);
281                 }
282             }
283
284         } catch(E) {
285             obj.error.standard_unexpected_error_alert($("patronStrings").getString('staff.patron.items.show_noncats.err_showing_circulations'),E);
286         }
287     },
288
289     'items_print' : function(which) {
290         var obj = this;
291         try {
292             var list = (which==2 ? obj.list2 : obj.list);
293             JSAN.use('patron.util');
294             var params = { 
295                 'patron' : patron.util.retrieve_fleshed_au_via_id(ses(),obj.patron_id), 
296                 'printer_context' : 'receipt', 
297                 'template' : 'items_out'
298             };
299             list.print( params );
300         } catch(E) {
301             obj.error.standard_unexpected_error_alert('printing 1',E);
302         }
303     },
304     'items_print_selected': function(which) {
305         var obj = this;
306         try {
307             JSAN.use('patron.util');
308             // JSAN.use('util.functional');
309             var list = ( which == 2 ? obj.list2 : obj.list);
310             // Selected Rows
311             var list_dump = list.dump_with_keys();
312             var pick_list = ( which == 2 ? obj.retrieve_ids2 : obj.retrieve_ids );
313             if (!pick_list || pick_list.length == 0) return;
314
315             // I don't know a better way to just get all the data from one row
316             for (var i=0; i<pick_list.length; i++) {
317                 var bc = pick_list[i].barcode;
318                 for (var j=0; j<list_dump.length; j++) {
319                     if (pick_list[i].barcode == list_dump[j].barcode) {
320                         pick_list[i] = list_dump[j];
321                     }
322                 }
323             }
324
325             var params = {
326                 'list': pick_list,
327                 'patron' : patron.util.retrieve_fleshed_au_via_id(ses(),obj.patron_id),
328                 'printer_context' : 'receipt',
329                 'template' : 'items_out'
330             };
331             list.print( params );
332         } catch(E) {
333             obj.error.standard_unexpected_error_alert('items_print_selected has failed',E);
334         }
335     },
336     'items_export' : function(which) {
337         var obj = this;
338         try {
339             var list = (which==2 ? obj.list2 : obj.list);
340             list.dump_csv_to_clipboard();
341         } catch(E) {
342             obj.error.standard_unexpected_error_alert('export 1',E);
343         }
344     },
345
346     'items_renew_all' : function(params) {
347         try {
348             if (!params) params = {};
349             var obj = this; var list = obj.list;
350             if (list.on_all_fleshed != null) {
351                 var r = window.confirm($("patronStrings").getString('staff.patron.items.items_renew_all.list_is_busy'));
352                 if (!r) return;
353             }
354             var r = window.confirm($("patronStrings").getString('staff.patron.items.items_renew_all.renew_items_in_list'));
355             if (!r) return;
356             obj.list.select_all();
357             function flesh_callback() {
358                 try {
359                     setTimeout(function(){
360                             list.on_all_fleshed = null;
361                             params.skip_prompt = true;
362                             if (!params.which_list) params.which_list = 1;
363                             obj.items_renew(params);    
364                         },0);
365                 } catch(E) {
366                     obj.error.standard_unexpected_error_alert($("patronStrings").getFormattedString('staff.patron.items.items_renew_all.items_not_renewed', ['2']),E);
367                 }
368             }
369             list.on_all_fleshed = flesh_callback;
370             list.full_retrieve();
371         } catch(E) {
372             this.error.standard_unexpected_error_alert($("patronStrings").getFormattedString('staff.patron.items.items_renew_all.items_not_renewed', ['1']),E);
373         }
374     },
375
376     'items_renew' : function(params) {
377         var obj = this;
378         try{
379             if (!params) { params = {}; }
380             JSAN.use('circ.util');
381             var retrieve_ids = ( params.which_list == 2 ? obj.retrieve_ids2 : obj.retrieve_ids );
382             if (!retrieve_ids || retrieve_ids.length == 0) return;
383             JSAN.use('util.functional');
384             if (!params.skip_prompt) {
385                 var msg = '';
386                 if(retrieve_ids.length > 1) {
387                     msg += $("patronStrings").getFormattedString('staff.patron.items.items_renew.renew_item_plural',[util.functional.map_list( retrieve_ids, function(o){return o.barcode;}).join(', ')]);
388                 } else {
389                     msg += $("patronStrings").getFormattedString('staff.patron.items.items_renew.renew_item_singular', [util.functional.map_list( retrieve_ids, function(o){return o.barcode;}).join(', ')]);
390                 }
391                 var r = window.confirm(msg);
392                 if (!r) { return; }
393             }
394
395             var count = 0;
396
397             if (params.get_date) {
398                 JSAN.use('util.functional');
399                 var title = $("patronStrings").getString('staff.patron.items.items_edit.renew_with_date.title');
400                 var msg = $("patronStrings").getFormattedString('staff.patron.items.items_edit.renew_with_date.prompt', [util.functional.map_list(retrieve_ids,function(o){return o.barcode;}).join(', ')]);
401                 var desc = $("patronStrings").getString('staff.patron.items.items_edit.renew_with_date.description');
402
403                 JSAN.use('util.window'); var win = new util.window();
404                 var my_xulG = win.open( 
405                     urls.XUL_TIMESTAMP_DIALOG, 'edit_renew_due_date', 'chrome,resizable,modal', 
406                     { 
407                         'title' : title, 
408                         'description' : desc, 
409                         'msg' : msg, 
410                         'allow_unset' : false,
411                         'disallow_future_dates' : false,
412                         'disallow_past_dates' : false,
413                         'disallow_today' : false,
414                         'time_readonly' : false
415                     }
416                 );
417
418                 if (my_xulG.complete) {
419                     params.due_date = my_xulG.timestamp;
420                 }
421             }
422
423             function gen_renew(bc,circ_id) {
424                 var x = document.getElementById('renew_msgs');
425                 if (x) {
426                     var l = document.createElement('label');
427                     l.setAttribute('value', $("patronStrings").getFormattedString('staff.patron.items.items_renew.renewing',[bc]));
428                     x.appendChild(l);
429                 }
430                 var p = { 'barcode' : bc, 'patron' : obj.patron_id };
431                 if (params.due_date) p.due_date = params.due_date;
432                 var r = circ.util.renew_via_barcode( p );
433                 try {
434                     if ( (typeof r[0].ilsevent != 'undefined' && r[0].ilsevent == 0) ) {
435                         l.setAttribute('value', $("patronStrings").getFormattedString('staff.patron.items.items_renew.renewed',[bc]));
436                         obj.list_circ_map[ circ_id ].row.my.circ = r[0].payload.circ;
437                         obj.list_circ_map[ circ_id ].row.my.acp = r[0].payload.copy;
438                         obj.list_circ_map[ circ_id ].row.my.mvr = r[0].payload.record;
439                         // A renewed circ is a new circ, and has a new circ_id.
440                         obj.list_circ_map[ r[0].payload.circ.id() ] = obj.list_circ_map[ circ_id ];
441                         obj.list_circ_map_by_copy[ r[0].payload.copy.id() ] = r[0].payload.circ.id();
442                     } else {
443                         var msg = $("patronStrings").getFormattedString('staff.patron.items.items_renew.not_renewed',[bc, r[0].textcode + r[0].desc]);
444                         l.setAttribute('value', msg);
445                         alert(msg);
446                     }
447                     count--;
448                     if (count == 0) {
449                         //if (window.confirm('Action completed. Refresh list?')) obj.retrieve();
450                         JSAN.use('util.widgets'); util.widgets.remove_children(x);
451                     }
452                     obj.refresh(circ_id);
453                 } catch(E) {
454                       obj.error.standard_unexpected_error_alert($("patronStrings").getFormattedString('staff.patron.items.items_renew.err_in_renew_via_barcode',[bc]), E);
455                 }
456             }
457
458             for (var i = 0; i < retrieve_ids.length; i++) {
459                 try {
460                     count++;
461                     var barcode = retrieve_ids[i].barcode;
462                     var circ_id = retrieve_ids[i].circ_id;
463                     gen_renew(barcode,circ_id);
464                 } catch(E) {
465                     obj.error.standard_unexpected_error_alert($("patronStrings").getFormattedString('staff.patron.items.items_renew.no_renew_for_barcode',[barcode]), E);
466                 }
467             }
468         } catch(E) {
469             obj.error.standard_unexpected_error_alert($("patronStrings").getString('staff.patron.items.items_renew.no_renew'),E);
470         }
471     },
472
473     'items_edit' : 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
479                 JSAN.use('util.functional');
480                 var title = '';
481                 if (retrieve_ids.length > 1) {
482                     title += $("patronStrings").getString('staff.patron.items.items_edit.edit_due_date.plural');
483                 } else {
484                     title += $("patronStrings").getString('staff.patron.items.items_edit.edit_due_date.singular');
485                 }
486                 var value = 'YYYY-MM-DD';
487                 var msg = $("patronStrings").getFormattedString('staff.patron.items.items_edit.new_due_date', [util.functional.map_list(retrieve_ids,function(o){return o.barcode;}).join(', ')]);
488                 var desc = $("patronStrings").getString('staff.patron.items.items_edit.edit_due_date.description');
489
490                 JSAN.use('util.window'); var win = new util.window();
491                 var my_xulG = win.open( 
492                     urls.XUL_TIMESTAMP_DIALOG, 'edit_due_date', 'chrome,resizable,modal', 
493                     { 
494                         'title' : title, 
495                         'description' : desc, 
496                         'msg' : msg, 
497                         'allow_unset' : false,
498                         'disallow_future_dates' : false,
499                         'disallow_past_dates' : false,
500                         'disallow_today' : false,
501                         'time_readonly' : false
502                     }
503                 );
504
505                 if (my_xulG.complete) {
506                     // XXX We need to append the time component from the original due date to the entered
507                     // date here, if (circ interval % 1 day == 0)
508                     // XXX I think the middle layer is doing this now
509                     var circs = util.functional.map_list(retrieve_ids,function(o){return o.circ_id;});
510                     for (var i = 0; i < circs.length; i++) {
511                         var robj = obj.network.simple_request('FM_CIRC_EDIT_DUE_DATE',[ses(),circs[i],my_xulG.timestamp]);
512                         if (typeof robj.ilsevent != 'undefined') { if (robj.ilsevent != 0) throw(robj); }
513                         obj.list_circ_map[ circs[i] ].row.my.circ = robj;
514                         obj.list_circ_map_by_copy[ robj.target_copy() ] = circs[i];
515                         obj.refresh(circs[i]);
516                     }
517                 }
518             } catch(E) {
519                 obj.error.standard_unexpected_error_alert($("patronStrings").getString('staff.patron.items.items_edit.dates_not_modified'),E);
520             }
521     },
522
523     'items_mark_lost' : function(which) {
524         var obj = this;
525         try {
526             var retrieve_ids = ( which == 2 ? obj.retrieve_ids2 : obj.retrieve_ids );
527             if (!retrieve_ids || retrieve_ids.length == 0) return;
528             for (var i = 0; i < retrieve_ids.length; i++) {
529                 var barcode = retrieve_ids[i].barcode;
530                 dump($("patronStrings").getFormattedString('staff.patron.items.items_edit.mark_barcode_lost', [barcode]));
531                 var robj = obj.network.simple_request( 'MARK_ITEM_LOST', [ ses(), { barcode: barcode } ]);
532                 if (typeof robj.ilsevent != 'undefined') { 
533                     switch(Number(robj.ilsevent)) {
534                         case 7018 /* COPY_MARKED_LOST */ :
535                             alert( $("patronStrings").getFormattedString('staff.patron.items.items_edit.item_barcode', [barcode, robj.desc]) );
536                         break;
537                         default: throw(robj);
538                     }
539                 } else {
540                     var c = obj.item_out_display.lost;
541                     if (1 & c) {
542                         // stay in top list, force reload
543                         obj.refresh(retrieve_ids[i].circ_id, false, true);
544                     } else {
545                         // move to bottom list (reload is automatic)
546                         obj.refresh(retrieve_ids[i].circ_id, true);
547                     }
548                 }
549             }
550         } catch(E) {
551             obj.error.standard_unexpected_error_alert($("patronStrings").getString('staff.patron.items.items_edit.items_not_marked_lost'),E);
552         }
553     },
554
555     'items_claimed_returned' : function(which) {
556         var obj = this;
557         try {
558             JSAN.use('util.date');
559             var retrieve_ids = ( which == 2 ? obj.retrieve_ids2 : obj.retrieve_ids );
560
561             JSAN.use('util.functional');
562             var title = $("patronStrings").getString('staff.patron.items.items_claimed_returned.claimed_returned');
563             var value = 'YYYY-MM-DD';
564             var msg = $("patronStrings").getFormattedString('staff.patron.items.items_claimed_returned.enter_returned_date',
565                 [util.functional.map_list(retrieve_ids,function(o){return o.barcode;}).join(', ')]);
566             var desc = $("patronStrings").getString('staff.patron.items.items_claimed_returned.claimed_returned.description');
567
568             JSAN.use('util.window'); var win = new util.window();
569             var my_xulG = win.open( 
570                 urls.XUL_TIMESTAMP_DIALOG, 'edit_claimed_returned', 'chrome,resizable,modal', 
571                 { 
572                     'title' : title, 
573                     'description' : desc, 
574                     'msg' : msg, 
575                     'allow_unset' : false,
576                     'disallow_future_dates' : true,
577                     'disallow_past_dates' : false,
578                     'disallow_today' : false,
579                     'time_readonly' : false
580                 }
581             );
582
583
584             if (my_xulG.complete) {
585                 var barcodes = util.functional.map_list(retrieve_ids,function(o){return o.barcode;});
586                 var do_not_move_these = {};
587                 var force_reload = {};
588                 for (var i = 0; i < barcodes.length; i++) {
589                     var robj = obj.network.simple_request(
590                         'MARK_ITEM_CLAIM_RETURNED', 
591                         [ ses(), { barcode: barcodes[i], backdate: my_xulG.timestamp } ],
592                         null,
593                         {
594                             'title' : $("patronStrings").getString('staff.patron.items.set_claim_returned_failure'),
595                             'overridable_events' : [
596                                 'PATRON_EXCEEDS_CLAIMS_RETURN_COUNT'                                
597                             ]
598                         }
599                     );
600                     if (typeof robj.ilsevent != 'undefined') { 
601                         if (robj.ilsevent != 0 && robj.textcode != 'PATRON_EXCEEDS_CLAIMS_RETURN_COUNT' ) {
602                             do_not_move_these[ barcodes[i] ] = true;
603                             obj.error.standard_unexpected_error_alert($("patronStrings").getString('staff.patron.items.items_claimed_returned.not_marked_claimed_returned'),robj);
604                         }
605                         if (robj.textcode == 'PATRON_EXCEEDS_CLAIMS_RETURN_COUNT') {
606                             do_not_move_these[ barcodes[i] ] = true;
607                         }
608                     } else if (robj == '1') { // success
609                         // if claimsreturned items should display in the
610                         // top list, tell refresh() to keep them there
611                         var c = obj.item_out_display.claimsreturned;
612                         if (1 & c) {
613                             do_not_move_these[ barcodes[i] ] = true;
614                             force_reload[barcodes[i]] = true;
615                         }
616                     }
617                 }
618                 for (var i = 0; i < retrieve_ids.length; i++) {
619                     obj.refresh(
620                         retrieve_ids[i].circ_id, 
621                         !do_not_move_these[ retrieve_ids[i].barcode ], 
622                         force_reload[ retrieve_ids[i].barcode ]
623                     );
624                 }
625             }
626         } catch(E) {
627             obj.error.standard_unexpected_error_alert($("patronStrings").getString('staff.patron.items.items_claimed_returned.not_marked_claimed_returned'),E);
628         }
629     },
630
631     'items_checkin' : function(which,options) {
632         var obj = this;
633         try {
634             if (!options) { options = {}; }
635             var retrieve_ids = ( which == 2 ? obj.retrieve_ids2 : obj.retrieve_ids );
636             if (!retrieve_ids || retrieve_ids.length == 0) return;
637             JSAN.use('util.functional');
638             var msg = '';
639             if (options.claims_never_checked_out) {
640                 if (retrieve_ids.length > 1) {
641                     msg += $("patronStrings").getFormattedString(
642                         'staff.patron.items.items_checkin.confirm_item_claimed_never_checked_out.plural',
643                         [
644                             util.functional.map_list(
645                                 retrieve_ids,
646                                 function(o){return o.barcode;}
647                             ).join(', ')
648                         ]
649                     );
650                 } else {
651                     msg += $("patronStrings").getFormattedString(
652                         'staff.patron.items.items_checkin.confirm_item_claimed_never_checked_out.singular',
653                         [
654                             retrieve_ids[0].barcode,
655                         ]
656                     );
657                 }
658             } else {
659                 if (retrieve_ids.length > 1) {
660                     msg += $("patronStrings").getFormattedString(
661                         'staff.patron.items.items_checkin.confirm_item_check_in.plural',
662                         [
663                             util.functional.map_list(
664                                 retrieve_ids,
665                                 function(o){return o.barcode;}
666                             ).join(', ')
667                         ]
668                     );
669                 } else {
670                     msg += $("patronStrings").getFormattedString(
671                         'staff.patron.items.items_checkin.confirm_item_check_in.singular',
672                         [
673                             retrieve_ids[0].barcode,
674                         ]
675                     );
676                 }
677
678             }
679             var r = window.confirm(msg);
680             if (!r) { return; }
681             var auto_print = document.getElementById('checkin_auto_print_slips');
682             if (auto_print) auto_print = auto_print.getAttribute('checked') == 'true';
683             JSAN.use('circ.util');
684             for (var i = 0; i < retrieve_ids.length; i++) {
685                 var copy_id = retrieve_ids[i].copy_id;
686                 dump('Check in copy_id = ' + copy_id + ' barcode = ' + retrieve_ids[i].barcode + '\n');
687                 var opt = JSON2js( js2JSON( options || {} ) ); // clone options
688                 opt.copy_id = copy_id;
689                 var robj = circ.util.checkin_via_barcode(
690                     ses(),
691                     opt,
692                     false /* backdate */,
693                     auto_print
694                 );
695                 /* circ.util.checkin_via_barcode handles errors currently */
696             }
697             obj.retrieve();
698         } catch(E) {
699             obj.error.standard_unexpected_error_alert($("patronStrings").getString('staff.patron.items.items_checkin.no_checkin'),E);
700         }
701     },
702
703     'show_catalog' : function(which) {
704         var obj = this;
705         try {
706             var retrieve_ids = ( which == 2 ? obj.retrieve_ids2 : obj.retrieve_ids );
707             if (!retrieve_ids || retrieve_ids.length == 0) return;
708             for (var i = 0; i < retrieve_ids.length; i++) {
709                 var doc_id = retrieve_ids[i].doc_id;
710                 if (!doc_id) {
711                     alert($("patronStrings").getFormattedString('staff.patron.items.show_catalog.barcode_not_cataloged', [retrieve_ids[i].barcode]));
712                     continue;
713                 }
714                 var opac_url = xulG.url_prefix('opac_rdetail') + doc_id;
715                 var content_params = { 
716                     'session' : ses(),
717                     'authtime' : ses('authtime'),
718                     'opac_url' : opac_url
719                 };
720                 xulG.new_tab(
721                     xulG.url_prefix('XUL_OPAC_WRAPPER'), 
722                     {'tab_name': $("patronStrings").getString('staff.patron.items.show_catalog.retrieving_title')}, 
723                     content_params
724                 );
725             }
726         } catch(E) {
727             obj.error.standard_unexpected_error_alert('',E);
728         }
729     },
730
731     'add_billing' : function(which) {
732         var obj = this;
733         try {
734             var retrieve_ids = ( which == 2 ? obj.retrieve_ids2 : obj.retrieve_ids );
735             if (!retrieve_ids || retrieve_ids.length == 0) return;
736             JSAN.use('util.window'); var win = new util.window();
737             for (var i = 0; i < retrieve_ids.length; i++) {
738                 var circ_id = retrieve_ids[i].circ_id;
739                 var my_xulG = win.open(
740                     urls.XUL_PATRON_BILL_WIZARD,
741                     'billwizard',
742                     'chrome,resizable,modal',
743                     { 'patron_id' : obj.patron_id, 'xact_id' : circ_id }
744                 );
745             }
746         } catch(E) {
747             obj.error.standard_unexpected_error_alert('',E);
748         }
749     },
750
751     'init_lists' : function() {
752         var obj = this;
753
754         JSAN.use('circ.util');
755         var columns = circ.util.columns( 
756             { 
757                 'barcode' : { 'hidden' : false },
758                 'checkout_lib' : { 'hidden' : false },
759                 'circ_lib' : { 'hidden' : false },
760                 'title' : { 'hidden' : false, 'flex' : '3' },
761                 'due_date' : { 'hidden' : false },
762                 'renewal_remaining' : { 'hidden' : false },
763                 'stop_fines' : { 'hidden' : false }
764             } 
765         );
766         var columns2 = circ.util.columns( 
767             { 
768                 'barcode' : { 'hidden' : false },
769                 'checkout_lib' : { 'hidden' : false },
770                 'circ_lib' : { 'hidden' : false },
771                 'title' : { 'hidden' : false, 'flex' : '3' },
772                 'checkin_time' : { 'hidden' : false },
773                 'stop_fines' : { 'hidden' : false }
774             } 
775         );
776
777         function retrieve_row(params) {
778             try { 
779                 var row = params.row;
780
781                 if (!row.my.circ_id) {
782                     if (typeof params.on_retrieve == 'function') { 
783                         params.on_retrieve(row); 
784                     }
785                     return row;
786                 }
787     
788                 if (!row.my.circ) {
789                     obj.network.simple_request(
790                         'FM_CIRC_DETAILS.authoritative',
791                         [ row.my.circ_id ],
792                         function(req) {
793                             try { 
794                                 var robj = req.getResultObject();
795                                 if (typeof robj.ilsevent != 'undefined') throw(robj);
796                                 if (typeof robj.ilsevent == 'null') throw('null result');
797                                 row.my.circ = robj.circ;
798                                 row.my.acp = robj.copy;
799                                 row.my.mvr = robj.mvr;
800                                 row.my.acn = robj.volume;
801                                 row.my.record = robj.record;
802         
803                                 var copy_id = row.my.circ.target_copy();
804                                 if (typeof copy_id == 'object') {
805                                     if (copy_id != null) {
806                                         copy_id = copy_id.id();
807                                     } else {
808                                         if (typeof robj.copy == 'object' && robj.copy != null) copy_id = robj.copy.id();
809                                     }
810                                 } else {
811                                         if (typeof robj.copy == 'object' && robj.copy != null) copy_id = robj.copy.id();
812                                 }
813                                 
814                                 params.treeitem_node.setAttribute( 'retrieve_id', js2JSON({'copy_id':copy_id,'circ_id':row.my.circ.id(),'barcode':row.my.acp.barcode(),'doc_id': ( row.my.record ? row.my.record.id() : null ) }) );
815
816                                 obj.list_circ_map_by_copy[ copy_id ] = row.my.circ.id();
817             
818                                 if (typeof params.on_retrieve == 'function') {
819                                     params.on_retrieve(row);
820                                 }
821                             } catch(E) {
822                                 obj.error.standard_unexpected_error_alert($("patronStrings").getString('staff.patron.items.retrieve_row.callback_error'), E);
823                             }
824                         }
825                     );
826                 } else {
827                     var copy_id = row.my.circ ? row.my.circ.target_copy() : null;
828                     if (typeof copy_id == 'object') {
829                         if (copy_id != null) {
830                             copy_id = copy_id.id();
831                         } else {
832                             if (typeof row.my.acp == 'object' && row.my.acp != null) copy_id = row.my.acp.id();
833                         }
834                     } else {
835                             if (typeof row.my.acp == 'object' && row.my.acp != null) copy_id = row.my.acp.id();
836                     }
837  
838                     params.treeitem_node.setAttribute( 'retrieve_id', js2JSON({'copy_id':row.my.acp.id(),'circ_id':row.my.circ.id(),'barcode':row.my.acp.barcode(),'doc_id': (row.my.record ? row.my.record.id() : null) }) );
839                     if (typeof params.on_retrieve == 'function') {
840                         params.on_retrieve(row);
841                     }
842                 }
843     
844                 return row;
845             } catch(E) {
846                 obj.error.standard_unexpected_error_alert($("patronStrings").getString('staff.patron.items.retrieve_row.error_in_retrieve_row'),E);
847                 return params.row;
848             }
849         }
850
851         JSAN.use('util.list'); obj.list = new util.list('items_list');
852         obj.list.init(
853             {
854                 'columns' : columns,
855                 'retrieve_row' : retrieve_row,
856                 'on_select' : function(ev) {
857                     JSAN.use('util.functional');
858                     var sel = obj.list.retrieve_selection();
859                     obj.controller.view.sel_clip.setAttribute('disabled',sel.length < 1);
860                     obj.controller.view.sel_edit.setAttribute('disabled',sel.length < 1);
861                     var list = util.functional.map_list(
862                         sel,
863                         function(o) { return JSON2js( o.getAttribute('retrieve_id') ); }
864                     );
865                     if (typeof obj.on_select == 'function') {
866                         obj.on_select(list);
867                     }
868                     if (typeof window.xulG == 'object' && typeof window.xulG.on_select == 'function') {
869                         obj.error.sdump('D_PATRON','patron.items: Calling external .on_select()\n');
870                         window.xulG.on_select(list);
871                     } else {
872                         obj.error.sdump('D_PATRON','patron.items: No external .on_select()\n');
873                     }
874                 }
875             }
876         );
877         
878         obj.list2 = new util.list('items_list2');
879         obj.list2.init(
880             {
881                 'columns' : columns2,
882                 'retrieve_row' : retrieve_row,
883                 'on_select' : function(ev) {
884                     JSAN.use('util.functional');
885                     var sel = obj.list2.retrieve_selection();
886                     obj.controller.view.sel_clip2.setAttribute('disabled',sel.length < 1);
887                     obj.controller.view.sel_edit2.setAttribute('disabled',sel.length < 1);
888                     var list = util.functional.map_list(
889                         sel,
890                         function(o) { return JSON2js( o.getAttribute('retrieve_id') ); }
891                     );
892                     if (typeof obj.on_select2 == 'function') {
893                         obj.on_select2(list);
894                     }
895                 }
896             }
897         );
898     },
899
900     'refresh' : function(circ_id,move_to_bottom_list, reload) {
901         var obj = this;
902         try {
903             var nparams = obj.list_circ_map[circ_id];
904             if (move_to_bottom_list) { 
905                 obj.list_circ_map[circ_id].treeitem_node.setAttribute('hidden','true');
906                 var nparams2 = obj.list2.append( { 'row' : { 'my' : { 'circ_id' : circ_id } },  'to_bottom' : true, 'which_list' : 1 } );
907                 obj.list_circ_map[circ_id] = nparams2; 
908             } else {
909                 if (reload) {
910                     // circ is not changing lists, but we need to re-fetch 
911                     // it from the server.  removing the circ forces a refresh
912                     nparams.row.my.circ = null; 
913                 }
914                 var which_list = nparams.which_list;
915                 switch(which_list) {
916                     case 1:
917                     case '1':
918                         setTimeout(function(){try{obj.list2.refresh_row(nparams);}catch(E){
919                                                     obj.error.standard_unexpected_error_alert($("patronStrings").getFormattedString('staff.patron.items.refresh.error_refreshing_row2', [circ_id, nparams]),E);}},1000);
920                         break;
921                     default:
922                         setTimeout(function(){try{obj.list.refresh_row(nparams);}catch(E){
923                                                     obj.error.standard_unexpected_error_alert($("patronStrings").getFormattedString('staff.patron.items.refresh.error_refreshing_row2', [circ_id, nparams]),E);}},1000);
924                         break;
925                 }
926             }
927         } catch(E) {
928             obj.error.standard_unexpected_error_alert($("patronStrings").getFormattedString('staff.patron.items.refresh.error_refreshing_row', [circ_id, nparams]),E);
929         }
930     },
931
932     'retrieve' : function(dont_show_me_the_list_change) {
933         var obj = this;
934         if (window.xulG && window.xulG.checkouts) {
935             obj.checkouts = window.xulG.checkouts;
936         } else {
937             obj.checkouts = [];
938             obj.checkouts2 = [];
939
940             obj.item_out_display = {
941                 lost : Number(obj.data.hash.aous[
942                     'ui.circ.items_out.lost']) || 2,
943                 longoverdue : Number(obj.data.hash.aous[
944                     'ui.circ.items_out.longoverdue']) || 2,
945                 claimsreturned : Number(obj.data.hash.aous[
946                     'ui.circ.items_out.claimsreturned']) || 2
947             };
948
949             // items still circulating
950             var robj = obj.network.simple_request(
951                 'FM_CIRC_RETRIEVE_VIA_USER.authoritative',
952                 [ ses(), obj.patron_id ]
953             );
954
955             if (typeof robj.ilsevent!='undefined') {
956                 obj.error.standard_unexpected_error_alert($("patronStrings").getString(
957                     'staff.patron.items.retrieve.err_retrieving_circulations'),E);
958                 return;
959             }
960
961             obj.checkouts = obj.checkouts.concat(robj.out);
962             obj.checkouts = obj.checkouts.concat(robj.overdue);
963
964             // open circs are added to list one or two based on config.
965             // closed circs added to list 2 only if configured, otherwise
966             // they are added to no list
967             function promote_circs(list, stop_fines, open) {
968                 var code = obj.item_out_display[stop_fines];
969                 if (open) {
970                     if (1 & code) { // bitflag 1 == top list
971                         obj.checkouts = obj.checkouts.concat(list);
972                     } else {
973                         obj.checkouts2 = obj.checkouts2.concat(list);
974                     }
975                 } else {
976                     if (4 & code) return;  // bitflag 4 == hide on checkin
977                     obj.checkouts2 = obj.checkouts2.concat(list);
978                 }
979             }
980
981             promote_circs(robj.lost, 'lost', true);
982             promote_circs(robj.long_overdue, 'longoverdue', true);
983             promote_circs(robj.claims_returned, 'claimsreturned', true);
984             
985             if (obj.item_out_display.lost & 4 &&
986                 obj.item_out_display.longoverdue & 4 &&
987                 obj.item_out_display.claimsreturned & 4) {
988                 // all types are configured to be hidden once checked in, 
989                 // so there is no need to fetch the checked in circs.
990
991                 if (obj.item_out_display.lost & 1 &&
992                     obj.item_out_display.longoverdue & 1 &&
993                     obj.item_out_display.claimsreturned & 1) {
994                     // additionally, if all types are configured to display
995                     // in the top list while checked out, nothing will
996                     // ever appear in the bottom list, so we can hide
997                     // the bottom list from the UI.
998
999                     $('splitter').setAttribute('hidden', true);
1000                     $('after_splitter').setAttribute('hidden', true);
1001                 }
1002
1003             } else {
1004                 var robj = obj.network.simple_request(
1005                     'FM_CIRC_IN_WITH_FINES_VIA_USER.authoritative',
1006                     [ ses(), obj.patron_id ]
1007                 );
1008
1009                 if (typeof robj.ilsevent!='undefined') {
1010                     obj.error.standard_unexpected_error_alert($("patronStrings").getString(
1011                         'staff.patron.items.retrieve.err_retrieving_circulations'),E);
1012                     return;
1013                 }
1014
1015                 promote_circs(robj.lost, 'lost');
1016                 promote_circs(robj.long_overdue, 'longoverdue');
1017                 promote_circs(robj.claims_returned, 'claimsreturned');
1018             }
1019         }
1020
1021         function gen_list_append(circ_id,which_list) {
1022             return function() {
1023                 try {
1024                     var nparams;
1025                     switch(which_list) {
1026                         case 1:
1027                             nparams = obj.list2.append( { 'row' : { 'my' : { 'circ_id' : circ_id } },  'to_bottom' : true, 'which_list' : which_list } );
1028                         break;
1029                         default:
1030                             nparams = obj.list.append( { 'row' : { 'my' : { 'circ_id' : circ_id } }, 'to_bottom' : true, 'which_list' : which_list } );
1031                         break;
1032                     }
1033                     if (nparams) {
1034                         obj.list_circ_map[circ_id] = nparams; // unlike item status interface, each circ should be in this list only once
1035                     } else {
1036                         throw('typeof nparams = ' + typeof nparams);
1037                     }
1038                 } catch(E) {
1039                     obj.error.standard_unexpected_error_alert($("patronStrings").getString('staff.patron.items.gen_list_append.error'),E);
1040                 }
1041             };
1042         }
1043
1044         obj.list.clear(); obj.list2.clear();
1045
1046         JSAN.use('util.exec'); var exec = new util.exec();
1047         var rows = [];
1048         for (var i in obj.checkouts) {
1049             rows.push( gen_list_append(obj.checkouts[i],0) );
1050         }
1051         for (var i in obj.checkouts2) {
1052             rows.push( gen_list_append(obj.checkouts2[i],1) );
1053         }
1054         exec.chain( rows );
1055         if (!dont_show_me_the_list_change) {
1056             obj.refresh_outer_interfaces();
1057         }
1058     },
1059
1060     'refresh_outer_interfaces' : function() {
1061         var obj = this;
1062         if (window.xulG && typeof window.xulG.on_list_change == 'function') {
1063             try { window.xulG.on_list_change(obj.checkouts); } catch(E) { this.error.sdump('D_ERROR',E); }
1064         }
1065     },
1066
1067     'on_select' : function(list) {
1068
1069         dump('patron.items.on_select list = ' + js2JSON(list) + '\n');
1070
1071         var obj = this;
1072
1073         obj.controller.view.cmd_items_claimed_returned.setAttribute('disabled','false');
1074         obj.controller.view.cmd_items_claimed_never_checked_out.setAttribute('disabled','false');
1075         obj.controller.view.cmd_items_renew.setAttribute('disabled','false');
1076         obj.controller.view.cmd_items_renew_with_date.setAttribute('disabled','false');
1077         obj.controller.view.cmd_items_checkin.setAttribute('disabled','false');
1078         obj.controller.view.cmd_items_edit.setAttribute('disabled','false');
1079         obj.controller.view.cmd_items_mark_lost.setAttribute('disabled','false');
1080         obj.controller.view.cmd_show_catalog.setAttribute('disabled','false');
1081         obj.controller.view.sel_copy_details.setAttribute('disabled','false');
1082         obj.controller.view.sel_bucket.setAttribute('disabled','false');
1083         obj.controller.view.sel_patron.setAttribute('disabled','false');
1084         obj.controller.view.cmd_triggered_events.setAttribute('disabled','false');
1085         obj.controller.view.sel_mark_items_damaged.setAttribute('disabled','false');
1086         obj.controller.view.sel_mark_items_missing.setAttribute('disabled','false');
1087
1088         obj.retrieve_ids = list;
1089     },
1090
1091     'on_select2' : function(list) {
1092     
1093         dump('patron.items.on_select2 list = ' + js2JSON(list) + '\n');
1094
1095         var obj = this;
1096
1097         obj.controller.view.cmd_items_claimed_returned2.setAttribute('disabled','false');
1098         obj.controller.view.cmd_items_claimed_never_checked_out2.setAttribute('disabled','false');
1099         obj.controller.view.cmd_items_renew2.setAttribute('disabled','false');
1100         obj.controller.view.cmd_items_renew_with_date2.setAttribute('disabled','false');
1101         obj.controller.view.cmd_items_checkin2.setAttribute('disabled','false');
1102         obj.controller.view.cmd_items_edit2.setAttribute('disabled','false');
1103         obj.controller.view.cmd_items_mark_lost2.setAttribute('disabled','false');
1104         obj.controller.view.cmd_show_catalog2.setAttribute('disabled','false');
1105         obj.controller.view.sel_copy_details2.setAttribute('disabled','false');
1106         obj.controller.view.sel_bucket2.setAttribute('disabled','false');
1107         obj.controller.view.sel_patron2.setAttribute('disabled','false');
1108         obj.controller.view.cmd_triggered_events2.setAttribute('disabled','false');
1109         obj.controller.view.sel_mark_items_damaged2.setAttribute('disabled','false');
1110         obj.controller.view.sel_mark_items_missing2.setAttribute('disabled','false');
1111
1112         this.retrieve_ids2 = list;
1113     },
1114
1115     'spawn_copy_editor' : function(which) {
1116
1117         var obj = this;
1118
1119         JSAN.use('util.functional');
1120
1121         var copy_ids = util.functional.map_list( which == 1 ? obj.retrieve_ids : obj.retrieve_ids2, function(o) { return o.copy_id; } ); 
1122
1123         JSAN.use('cat.util'); cat.util.spawn_copy_editor( { 'copy_ids' : copy_ids, 'edit' : 1 } );
1124
1125     },
1126
1127
1128
1129 }
1130
1131 dump('exiting patron.items.js\n');