74b7ae3d14b140da6cb36b1624baeeab337b0569
[working/Evergreen.git] / Open-ILS / xul / staff_client / server / circ / alternate_copy_summary.js
1 var error; 
2 var network;
3 var data;
4 var transit_list;
5 var hold_list;
6
7 function my_init() {
8     try {
9         if (typeof JSAN == 'undefined') { throw( "The JSAN library object is missing."); }
10         JSAN.errorLevel = "die"; // none, warn, or die
11         JSAN.addRepository('/xul/server/');
12         JSAN.use('util.error'); error = new util.error();
13         error.sdump('D_TRACE','my_init() for alternate_copy_summary.xul');
14
15         JSAN.use('util.network'); network = new util.network();
16         JSAN.use('OpenILS.data'); data = new OpenILS.data(); data.stash_retrieve();
17         JSAN.use('util.date');
18         JSAN.use('cat.util');
19
20         var x = document.getElementById('patron_name');
21         if (x) {
22             x.addEventListener(
23                 'command',
24                 function(ev) {
25                     var usr = ev.target.getAttribute('data');
26                     if (usr) { window.xulG.new_patron_tab( {}, { 'id' : usr } ); }
27                 },
28                 false
29             );
30         }
31         var y = document.getElementById('prev_patron_name');
32         if (y) {
33             y.addEventListener(
34                 'command',
35                 function(ev) {
36                     var usr = ev.target.getAttribute('data');
37                     if (usr) { window.xulG.new_patron_tab( {}, { 'id' : usr } ); }
38                 },
39                 false
40             );
41         }
42
43         JSAN.use('circ.util'); 
44         JSAN.use('util.list'); 
45
46         var columns = circ.util.transit_columns({});
47         transit_list = new util.list('transit');
48         transit_list.init( { 'columns' : columns });
49         
50         var columns = circ.util.hold_columns(
51         
52                 { 
53                     'request_time' : { 'hidden' : true },
54                     'pickup_lib_shortname' : { 'hidden' : false },
55                     'hold_type' : { 'hidden' : false },
56                     'current_copy' : { 'hidden' : true },
57                     'capture_time' : { 'hidden' : true },
58                     'email_notify' : { 'hidden' : false },
59                     'phone_notify' : { 'hidden' : false },
60                 } 
61             );
62
63         hold_list = new util.list('hold');
64         hold_list.init( { 'columns' : columns });
65
66         // timeout so xulG gets a chance to get pushed in
67         setTimeout(
68             function () { xulG.from_item_details_new = false; load_item(); },
69             1000
70         );
71
72     } catch(E) {
73         try { error.standard_unexpected_error_alert('main/test.xul',E); } catch(F) { alert(E); }
74     }
75 }
76
77 function set(name,value,data) { 
78     if (typeof value == 'undefined' || typeof value == 'null') { return; }
79     var nodes = document.getElementsByAttribute('name',name); 
80     for (var i = 0; i < nodes.length; i++) {
81         if (nodes[i].nodeName == 'button') {
82             nodes[i].setAttribute('label',value);
83             if (data) {
84                 nodes[i].setAttribute('data',data); 
85             } else {
86                 nodes[i].setAttribute('data',''); 
87             }
88         } else {
89             nodes[i].setAttribute('value',value);
90         }
91         nodes[i].value = value; 
92     }
93 }
94
95 function set_tooltip(name,value) { 
96     if (typeof value == 'undefined' || typeof value == 'null') { return; }
97     var nodes = document.getElementsByAttribute('name',name); 
98     for (var i = 0; i < nodes.length; i++) {
99         nodes[i].setAttribute('tooltiptext',value);
100     }
101 }
102
103 function renewal_composite_kludge(circ) {
104     // Only a corrupt database could give us a situation where more
105     // than one of these were true at a time, right?
106     if (circ.desk_renewal() == "t")
107         return document.getElementById('circStrings').getString(
108             'staff.circ.copy_details.desk_renewal'
109         );
110     else if (circ.opac_renewal() == "t")
111         return document.getElementById('circStrings').getString(
112             'staff.circ.copy_details.opac_renewal'
113         );
114     else if (circ.phone_renewal() == "t")
115         return document.getElementById('circStrings').getString(
116             'staff.circ.copy_details.phone_renewal'
117         );
118     else return "";
119 }
120
121 function load_item() {
122     try {
123         if (! xulG.barcode) return;
124
125         if (xulG.fetched_copy_details && xulG.fetched_copy_details[xulG.barcode]) {
126             var details = xulG.fetched_copy_details[xulG.barcode];
127             // We don't want to use these details more than once (i.e., we
128             // don't want cached data after things have potentially changed).
129             delete xulG.fetched_copy_details[xulG.barcode];
130         } else {
131             var details = network.simple_request('FM_ACP_DETAILS_VIA_BARCODE.authoritative', [ ses(), xulG.barcode ]);
132             // Should get back .mvr, .copy, .volume, .transit, .circ, .hold
133         }
134
135         if (typeof dynamic_grid_replacement == 'function') {
136             dynamic_grid_replacement('alternate_copy_summary');
137         }
138         if (typeof bib_brief_overlay == 'function') {
139             bib_brief_overlay({
140                 'mvr' : details.mvr,
141                 'acp' : details.copy
142             });
143         }
144
145         set("stat_cat_entries", '');
146         set("age_protect", '');
147         set("alert_message", '');
148         set("barcode", '');
149         set("call_number", '');
150         set("circ_as_type", '');
151         set("copy_circ_lib" , '');
152         set_tooltip("copy_circ_lib" , '');
153         set("circ_modifier", '');
154         set("circulate", '');
155         set("floating", '');
156         set("copy_number", '');
157         set("copy_create_date", '');
158         set("copy_active_date", '');
159         set("status_changed_time", '');
160         set("copy_creator", '');
161         set("deleted", '');
162         set("deposit", '');
163         set("deposit_amount", '');
164         set("dummy_author", '');
165         set("dummy_title", '');
166         set("copy_edit_date", '');
167         set("copy_editor", '');
168         set("fine_level", '');
169         set("holdable", '');
170         set("copy_id", '');
171         set("loan_duration", '');
172         set("location", '');
173         set_tooltip("location", '');
174         set("renewal_type", '');
175         set("opac_visible", '');
176         set("price", '');
177         set_tooltip("price", '');
178         set("cost", '');
179         set_tooltip("cost", '');
180         set("ref", '');
181         set("copy_status", '');
182         set_tooltip("copy_status", '');
183         set("notes", '');
184         set("stat_cat_entry_copy_maps", '');
185         set("circulations", '');
186         set("total_circ_count", '');
187         set_tooltip("total_circ_count", '');
188         set("total_circ_count_prev_year", '');
189         set("total_circ_count_curr_year", '');
190         set("holds", '');
191
192         if (details.copy) {
193             set("stat_cat_entries", details.copy.stat_cat_entries()); 
194             set("age_protect", details.copy.age_protect()); 
195             set("alert_message", details.copy.alert_message()); 
196             set("barcode", details.copy.barcode()); 
197             if (typeof details.copy.call_number() == 'object') {
198                 set("call_number", details.copy.call_number().label()); 
199             } else {
200                 network.simple_request('FM_ACN_RETRIEVE.authoritative',[details.copy.call_number()], function(req) {
201                     var acn_obj = req.getResultObject();
202                     set("call_number", acn_obj.label());
203                 });
204             }
205             set("circ_as_type", details.copy.circ_as_type() != null && details.copy.circ_as_type() == 'object'
206                 ? details.copy.circ_as_type()
207                 : ( typeof data.hash.citm[ details.copy.circ_as_type() ] != 'undefined'
208                     ? data.hash.citm[ details.copy.circ_as_type() ].value
209                     : ''
210                 )
211             ); 
212             set("copy_circ_lib" , typeof details.copy.circ_lib() == 'object' ? details.copy.circ_lib().shortname() : data.hash.aou[ details.copy.circ_lib() ].shortname()); 
213             set_tooltip("copy_circ_lib" , typeof details.copy.circ_lib() == 'object' ? details.copy.circ_lib().name() : data.hash.aou[ details.copy.circ_lib() ].name()); 
214             var cm = details.copy.circ_modifier();
215             if (typeof data.hash.ccm[cm] != 'undefined') {
216                 set("circ_modifier", document.getElementById('commonStrings').getFormattedString('staff.circ_modifier.display',[cm,data.hash.ccm[cm].name(),data.hash.ccm[cm].description()])); 
217             } else {
218                 set("circ_modifier","");
219             }
220             set("circulate", get_localized_bool( details.copy.circulate() )); 
221             set("floating", (details.copy.floating() && typeof details.copy.floating() == 'object' ? details.copy.floating().name() : get_localized_bool( details.copy.floating() ))); 
222             set("copy_number", details.copy.copy_number()); 
223             set("copy_create_date", util.date.formatted_date( details.copy.create_date(), '%{localized}' )); 
224             set("copy_active_date", util.date.formatted_date( details.copy.active_date(), '%{localized}' ));
225             set("status_changed_time", util.date.formatted_date( details.copy.status_changed_time(), '%{localized}' )); 
226             set("copy_creator", details.copy.creator()); 
227             set("deleted", details.copy.deleted()); 
228             set("deposit", details.copy.deposit()); 
229             set("deposit_amount", details.copy.deposit_amount()); 
230             set("dummy_author", details.copy.dummy_author()); 
231             set("dummy_title", details.copy.dummy_title()); 
232             set("copy_edit_date", util.date.formatted_date( details.copy.edit_date(), '%{localized}' )); 
233             set("copy_editor", details.copy.editor()); 
234             set("fine_level", cat.util.render_fine_level( details.copy.fine_level() )); 
235             set("holdable", get_localized_bool( details.copy.holdable() )); 
236             set("copy_id", details.copy.id()); 
237             set("loan_duration", cat.util.render_loan_duration( details.copy.loan_duration() )); 
238             var copy_location = typeof details.copy.location() == 'object' ? details.copy.location() : data.lookup('acpl',details.copy.location());
239                 set("location", copy_location.name());
240                 set_tooltip("location", document.getElementById('circStrings').getFormattedString( 
241                     'staff.circ.copy_details.location_tooltip',
242                     [
243                         get_localized_bool( copy_location.circulate() ), 
244                         get_localized_bool( copy_location.holdable() ), 
245                         get_localized_bool( copy_location.hold_verify() ), 
246                         get_localized_bool( copy_location.opac_visible() )
247                     ]
248                 ));
249             set("opac_visible", get_localized_bool( details.copy.opac_visible() )); 
250             set("price", details.copy.price()); 
251             set_tooltip("price" , "Replacement Amount charged to Patron");
252             set("cost", details.copy.cost());
253             set_tooltip("cost" , "Acquisition Amount paid by Library");
254             set("ref", get_localized_bool( details.copy.ref() )); 
255             var copy_status = typeof details.copy.status() == 'object' ? details.copy.status() : data.hash.ccs[ details.copy.status() ];
256                 set("copy_status", copy_status.name() );
257                 set_tooltip("copy_status", document.getElementById('circStrings').getFormattedString(
258                     'staff.circ.copy_details.copy_status_tooltip',
259                     [
260                         get_localized_bool( copy_status.opac_visible() ), 
261                         get_localized_bool( copy_status.holdable() ) 
262                     ]
263                 ));
264             set("notes", details.copy.notes()); 
265             set("stat_cat_entry_copy_maps", details.copy.stat_cat_entry_copy_maps()); 
266             set("circulations", details.copy.circulations()); 
267             set("holds", details.copy.holds()); 
268
269             network.simple_request('FM_CIRC_IMPROVED_COUNT_VIA_COPY', [ses(), { 'copy' : details.copy.id() } ], function(req) {
270                 var r = req.getResultObject();
271                 var total = 0; var tooltip = ''; var year = {};
272                 for (var i = 0; i < r.length; i++) {
273                     total += Number( r[i].count() );
274                     if (typeof year[ r[i].year() ] == 'undefined') year[ r[i].year() ] = 0;
275                     year[ r[i].year() ] += Number( r[i].count() ); // Add original circs and renewals together
276                 }
277                 set( 'total_circ_count', total );
278                 var curr_year = (new Date()).getFullYear();
279                 var prev_year = curr_year - 1;
280                 set( 'total_circ_count_curr_year', year[ curr_year ] || 0 );
281                 set( 'total_circ_count_prev_year', year[ prev_year ] || 0 );
282                 var keys = []; for (var i in year) { keys.push( i ); }; keys.sort();
283                 for (var i = 0; i < keys.length; i++) {
284                     tooltip += document.getElementById('circStrings').getFormattedString( 
285                         'staff.circ.copy_details.circ_count_by_year', [ 
286                             keys[i] == -1 ? document.getElementById('circStrings').getString('staff.circ.copy_details.circ_count_by_year.legacy_label') : keys[i], 
287                             year[keys[i]]
288                         ] 
289                     ) + '\n';
290                 }
291                 set_tooltip( 'total_circ_count', tooltip );
292             } );
293         }
294
295         set("copies", '');
296         set("volume_create_date", '');
297         set("volume_creator", '');
298         set("deleted", '');
299         set("volume_edit_date", '');
300         set("volume_editor", '');
301         set("volume_id", '');
302         set("label", '');
303         set("owning_lib" , '');
304         set_tooltip("owning_lib" , '');
305         set("record", '');
306         set("notes", '');
307         set("uri_maps", '');
308         set("uris", '');
309
310         if (details.volume) {
311             set("copies", details.volume.copies()); 
312             set("volume_create_date", util.date.formatted_date( details.volume.create_date(), '%{localized}' )); 
313             set("volume_creator", details.volume.creator()); 
314             set("deleted", details.volume.deleted()); 
315             set("volume_edit_date", util.date.formatted_date( details.volume.edit_date(), '%{localized}' )); 
316             set("volume_editor", details.volume.editor()); 
317             set("volume_id", details.volume.id()); 
318             set("label", details.volume.label()); 
319             set("owning_lib" , typeof details.volume.owning_lib() == 'object' ? details.volume.owning_lib().shortname() : data.hash.aou[ details.volume.owning_lib() ].shortname()); 
320             set_tooltip("owning_lib" , typeof details.volume.owning_lib() == 'object' ? details.volume.owning_lib().name() : data.hash.aou[ details.volume.owning_lib() ].name()); 
321             set("record", details.volume.record()); 
322             set("notes", details.volume.notes()); 
323             set("uri_maps", details.volume.uri_maps()); 
324             set("uris", details.volume.uris()); 
325         }
326
327         set("transit_copy_status", '');
328         set_tooltip("transit_copy_status", '');
329         set("dest", '');
330         set("dest_recv_time", '');
331         set("transit_id", '');
332         set("persistant_transfer", '');
333         set("prev_hop", '');
334         set("source", '');
335         set("source_send_time", '');
336         set("target_copy", '');
337         set("hold_transit_copy", '');
338
339         if (details.transit) {
340
341             transit_list.clear();
342             transit_list.append( { 'row' : { 'my' : { 'atc' : details.transit, } } });
343
344             var transit_copy_status = typeof details.transit.copy_status() == 'object' ? details.transit.copy_status() : data.hash.ccs[ details.transit.copy_status() ];
345                 set("transit_copy_status", transit_copy_status.name() );
346                 set_tooltip("transit_copy_status", document.getElementById('circStrings').getFormattedString(
347                     'staff.circ.copy_details.copy_status_tooltip',
348                     [
349                         get_localized_bool( transit_copy_status.opac_visible() ), 
350                         get_localized_bool( transit_copy_status.holdable() ) 
351                     ]
352                 ));
353             set("dest", details.transit.dest()); 
354             set("dest_recv_time", util.date.formatted_date( details.transit.dest_recv_time(), '%{localized}' )); 
355             set("transit_id", details.transit.id()); 
356             set("persistant_transfer", details.transit.persistant_transfer()); 
357             set("prev_hop", details.transit.prev_hop()); 
358             set("source", details.transit.source()); 
359             set("source_send_time", util.date.formatted_date( details.transit.source_send_time(), '%{localized}' )); 
360             set("target_copy", details.transit.target_copy()); 
361             set("hold_transit_copy", details.transit.hold_transit_copy()); 
362         } else {
363             $('transit_caption').setAttribute('label', $('circStrings').getString('staff.circ.copy_details.not_transit'));
364         }
365
366         set("checkin_lib", '');
367         set_tooltip("checkin_lib", '');
368         set("checkin_workstation",""); 
369         set("checkin_staff", '');
370         set("checkin_time", '');
371         set("checkin_scan_time", '');
372         set("circ_circ_lib" , '');
373         set_tooltip("circ_circ_lib" , '');
374         set("circ_staff", '');
375         set("desk_renewal", '');
376         set("due_date", '');
377         set("duration", '');
378         set("duration_rule", '');
379         set("fine_interval", '');
380         set("circ_id", '');
381         set("max_fine", '');
382         set("max_fine_rule", '');
383         set("opac_renewal", '');
384         set("phone_renewal", '');
385         set("recurring_fine", '');
386         set("recurring_fine_rule", '');
387         set("renewal_remaining", '');
388         set("stop_fines", '');
389         set("stop_fines_time", '');
390         set("target_copy", '');
391         set("circ_usr", '');
392         set("xact_finish", '');
393         set("xact_start", '');
394         set("create_time", '');
395         set("workstation", '');
396         set("renewal_workstation", '');
397         set("checkout_workstation", '');
398         set("billings", '');
399         set("payments", '');
400         set("billable_transaction", '');
401         set("circ_type", '');
402         set("billing_total", '');
403         set("payment_total", '');
404         set("patron_name", '');
405         set("prev_patron_name", '');
406         set("prev_num_circs", '');
407         set("prev_num_renewals", '');
408         set("prev_xact_start", '');
409         set("prev_checkout_workstation", '');
410         set("prev_renewal_time", '');
411         set("prev_stop_fines", '');
412         set("prev_stop_fines_time", '');
413         set("prev_renewal_workstation", '');
414         set("prev_checkin_workstation", '');
415         set("prev_last_checkin_time", '');
416         set("prev_last_checkin_scan_time", '');
417
418         if (details.circ) {
419             try { set("checkin_lib", typeof details.circ.checkin_lib() == 'object' ? details.circ.checkin_lib().shortname() : data.hash.aou[ details.circ.checkin_lib() ].shortname() );  } catch(E) {};
420             try { set_tooltip("checkin_lib", typeof details.circ.checkin_lib() == 'object' ? details.circ.checkin_lib().name() : data.hash.aou[ details.circ.checkin_lib() ].name() );  } catch(E) {};
421             if (details.circ.checkin_workstation()) {
422                 set("checkin_workstation", details.circ.checkin_workstation().name()); 
423             }
424             set("checkin_staff", details.circ.checkin_staff()); 
425             set("checkin_time", util.date.formatted_date( details.circ.checkin_time(), '%{localized}' )); 
426             set("last_checkin_time", util.date.formatted_date( details.circ.checkin_time(), '%{localized}' )); 
427             set("checkin_scan_time", util.date.formatted_date( details.circ.checkin_scan_time(), '%{localized}' )); 
428             set("last_checkin_scan_time", util.date.formatted_date( details.circ.checkin_scan_time(), '%{localized}' )); 
429             try { set("circ_circ_lib" , typeof details.circ.circ_lib() == 'object' ? details.circ.circ_lib().shortname() : data.hash.aou[ details.circ.circ_lib() ].shortname() );  } catch(E) {};
430             try { set_tooltip("circ_circ_lib" , typeof details.circ.circ_lib() == 'object' ? details.circ.circ_lib().name() : data.hash.aou[ details.circ.circ_lib() ].name() );  } catch(E) {};
431             set("circ_staff", details.circ.circ_staff()); 
432             set("desk_renewal", details.circ.desk_renewal()); 
433             set("due_date", util.date.formatted_date( details.circ.due_date(), '%{localized}' )); 
434             set("duration", details.circ.duration()); 
435             set("fine_interval", details.circ.fine_interval()); 
436             set("circ_id", details.circ.id()); 
437             set("max_fine", details.circ.max_fine()); 
438             set("opac_renewal", details.circ.opac_renewal()); 
439             set("phone_renewal", details.circ.phone_renewal()); 
440             set("renewal_type", renewal_composite_kludge(details.circ));
441             set("recurring_fine", details.circ.recurring_fine()); 
442             set("renewal_remaining", details.circ.renewal_remaining()); 
443             set("stop_fines", details.circ.stop_fines()); 
444             set("stop_fines_time", util.date.formatted_date( details.circ.stop_fines_time(), '%{localized}' )); 
445             set("target_copy", details.circ.target_copy()); 
446             set("circ_usr", details.circ.usr()); 
447             network.simple_request('FM_AU_FLESHED_RETRIEVE_VIA_ID',[ ses(), details.circ.usr() ], function(preq) {
448                 var r_au = preq.getResultObject();
449                 JSAN.use('patron.util');
450                 set(
451                     'patron_name', 
452                     patron.util.format_name( r_au ) + ' : ' + r_au.card().barcode(),
453                     details.circ.usr()
454                 );
455                 set_tooltip('patron_name','circ id ' + details.circ.id());
456             });
457             set("xact_finish", util.date.formatted_date( details.circ.xact_finish(), '%{localized}' )); 
458             set("xact_start", util.date.formatted_date( details.circ.xact_start(), '%{localized}' )); 
459             set("create_time", util.date.formatted_date( details.circ.create_time(), '%{localized}' )); 
460             set("workstation", details.circ.workstation()); 
461             if (get_bool(details.circ.opac_renewal())||get_bool(details.circ.phone_renewal())||get_bool(details.circ.desk_renewal())) {
462                 set("renewal_workstation", (typeof details.circ.workstation() == 'object' && details.circ.workstation() != null) ? details.circ.workstation().name() : details.circ.workstation() ); 
463                 network.simple_request('FM_CIRC_CHAIN_SUMMARY', [ses(), details.circ.id() ], function(req) {
464                     try {
465                         var summary = req.getResultObject();
466                         set("num_circs", summary.num_circs());
467                         set("num_renewals", Number(summary.num_circs()) - 1);
468                         set("xact_start", util.date.formatted_date( summary.start_time(), '%{localized}' )); 
469                         set("checkout_workstation", summary.checkout_workstation());
470                         set("renewal_time", util.date.formatted_date( summary.last_renewal_time(), '%{localized}' )); 
471                         set("stop_fines", summary.last_stop_fines());
472                         set("stop_fines_time", util.date.formatted_date( summary.last_stop_fines_time(), '%{localized}' )); 
473                         set("renewal_workstation", summary.last_renewal_workstation());
474                         set("checkin_workstation", summary.last_checkin_workstation());
475                         set("last_checkin_time", util.date.formatted_date( summary.last_checkin_time(), '%{localized}' )); 
476                         set("last_checkin_scan_time", util.date.formatted_date( summary.last_checkin_scan_time(), '%{localized}' )); 
477                     } catch(E) {
478                         alert('Error in alternate_copy_summary.js, FM_CIRC_CHAIN: ' + E);
479                     }
480                 } );
481             } else {
482                 set("checkout_workstation", (typeof details.circ.workstation() == 'object' && details.circ.workstation() != null) ? details.circ.workstation().name() : details.circ.workstation() );
483             }
484             network.simple_request('FM_CIRC_PREV_CHAIN_SUMMARY', [ses(), details.circ.id() ], function(req) {
485                 try {
486                     var robj = req.getResultObject();
487                     if (!robj || typeof robj == 'null') { return; }
488                     var summary = robj['summary'];
489                     network.simple_request('FM_AU_FLESHED_RETRIEVE_VIA_ID',[ ses(), robj['usr'] ], function(preq) {
490                         var r_au = preq.getResultObject();
491                         JSAN.use('patron.util');
492                         set(
493                             'prev_patron_name', 
494                             patron.util.format_name( r_au ) + ' : ' + r_au.card().barcode(),
495                             robj['usr']
496                         );
497                         set_tooltip('prev_patron_name','circ chain prior to circ id ' + details.circ.id());
498                     });
499                     set("prev_num_circs", summary.num_circs());
500                     set("prev_num_renewals", Number(summary.num_circs()) - 1);
501                     set("prev_xact_start", util.date.formatted_date( summary.start_time(), '%{localized}' )); 
502                     set("prev_checkout_workstation", summary.checkout_workstation());
503                     set("prev_renewal_time", util.date.formatted_date( summary.last_renewal_time(), '%{localized}' )); 
504                     set("prev_stop_fines", summary.last_stop_fines());
505                     set("prev_stop_fines_time", util.date.formatted_date( summary.last_stop_fines_time(), '%{localized}' )); 
506                     set("prev_renewal_workstation", summary.last_renewal_workstation());
507                     set("prev_checkin_workstation", summary.last_checkin_workstation());
508                     set("prev_last_checkin_time", util.date.formatted_date( summary.last_checkin_time(), '%{localized}' )); 
509                     set("prev_last_checkin_scan_time", util.date.formatted_date( summary.last_checkin_scan_time(), '%{localized}' )); 
510                 } catch(E) {
511                     alert('Error in alternate_copy_summary.js, FM_CIRC_PREV_CHAIN: ' + E);
512                 }
513             });
514             set("billings", details.circ.billings()); 
515             set("payments", details.circ.payments()); 
516             set("billable_transaction", details.circ.billable_transaction()); 
517             set("circ_type", details.circ.circ_type()); 
518             set("billing_total", details.circ.billing_total()); 
519             set("payment_total", details.circ.payment_total()); 
520             if (! details.circ.checkin_time() ) {
521                 set("recurring_fine_rule", document.getElementById('circStrings').getFormattedString(
522                     'staff.circ.copy_details.recurring_fine_rule_format',
523                     [
524                         details.circ.recurring_fine_rule().name(),
525                         details.circ.recurring_fine_rule().id(),
526                         details.circ.recurring_fine_rule().low(),
527                         details.circ.recurring_fine_rule().normal(),
528                         details.circ.recurring_fine_rule().high(),
529                         details.circ.recurring_fine_rule().recurrence_interval()
530                     ]
531                 )); 
532                 set_tooltip("recurring_fine_rule", document.getElementById('circStrings').getFormattedString(
533                     'staff.circ.copy_details.recurring_fine_rule_tooltip_format',
534                     [
535                         details.circ.recurring_fine_rule().name(),
536                         details.circ.recurring_fine_rule().id(),
537                         details.circ.recurring_fine_rule().low(),
538                         details.circ.recurring_fine_rule().normal(),
539                         details.circ.recurring_fine_rule().high(),
540                         details.circ.recurring_fine_rule().recurrence_interval()
541                     ]
542                 )); 
543                 set("duration_rule", document.getElementById('circStrings').getFormattedString(
544                     'staff.circ.copy_details.duration_rule_format',
545                     [
546                         details.circ.duration_rule().name(),
547                         details.circ.duration_rule().id(),
548                         details.circ.duration_rule().shrt(),
549                         details.circ.duration_rule().normal(),
550                         details.circ.duration_rule().extended(),
551                         details.circ.duration_rule().max_renewals()
552                     ]
553                 )); 
554                 set_tooltip("duration_rule", document.getElementById('circStrings').getFormattedString(
555                     'staff.circ.copy_details.duration_rule_tooltip_format',
556                     [
557                         details.circ.duration_rule().name(),
558                         details.circ.duration_rule().id(),
559                         details.circ.duration_rule().shrt(),
560                         details.circ.duration_rule().normal(),
561                         details.circ.duration_rule().extended(),
562                         details.circ.duration_rule().max_renewals()
563                     ]
564                 )); 
565                 set("max_fine_rule", document.getElementById('circStrings').getFormattedString(
566                     'staff.circ.copy_details.max_fine_rule_format',
567                     [
568                         details.circ.max_fine_rule().name(),
569                         details.circ.max_fine_rule().id(),
570                         details.circ.max_fine_rule().amount(),
571                         details.circ.max_fine_rule().is_percent()
572                     ]
573                 ));
574                 set_tooltip("max_fine_rule", document.getElementById('circStrings').getFormattedString(
575                     'staff.circ.copy_details.max_fine_rule_tooltip_format',
576                     [
577                         details.circ.max_fine_rule().name(),
578                         details.circ.max_fine_rule().id(),
579                         details.circ.max_fine_rule().amount(),
580                         details.circ.max_fine_rule().is_percent()
581                     ]
582                 ));
583             }
584         }
585
586         set("hold_status", '');
587         set("transit", '');
588         set("capture_time", '');
589         set("current_copy", '');
590         set("email_notify", '');
591         set("expire_time", '');
592         set("fulfillment_lib", '');
593         set_tooltip("fulfillment_lib", '');
594         set("fulfillment_staff", '');
595         set("fulfillment_time", '');
596         set("hold_type", '');
597         set("holdable_formats", '');
598         set("hold_id", '');
599         set("phone_notify", '');
600         set("pickup_lib", '');
601         set_tooltip("pickup_lib", '');
602         set("prev_check_time", '');
603         set("request_lib", '');
604         set_tooltip("request_lib", '');
605         set("request_time", '');
606         set("requestor", '');
607         set("selection_depth", '');
608         set("selection_ou", '');
609         set_tooltip("selection_ou", '');
610         set("target", '');
611         set("hold_usr", '');
612         set("hold_patron_name", '');
613         set("cancel_time", '');
614         set("notify_time", '');
615         set("notify_count", '');
616         set("notifications", '');
617         set("bib_rec", '');
618         set("eligible_copies", '');
619         set("frozen", '');
620         set("thaw_date", '');
621         set("shelf_time", '');
622         set("cancel_cause", '');
623         set("cancel_note", '');
624         set("notes", '');
625
626         if (details.hold) {
627             var better_fleshed_hold_blob = network.simple_request('FM_AHR_BLOB_RETRIEVE.authoritative',[ ses(), details.hold.id() ]);
628             var status_robj = better_fleshed_hold_blob.status;
629             JSAN.use('circ.util');
630
631             hold_list.clear();
632             hold_list.append( { 'row' : { 'my' : { 'ahr' : better_fleshed_hold_blob.hold, 'acp' : details.copy, 'status' : status_robj, } } });
633
634             JSAN.use('patron.util'); 
635             var au_obj = patron.util.retrieve_fleshed_au_via_id( ses(), details.hold.usr() );
636             $('hold_patron_name').setAttribute('value', $('circStrings').getFormattedString('staff.circ.copy_details.user_details', [au_obj.family_name(), au_obj.first_given_name(), au_obj.card().barcode()]) );
637             $('hold_patron_name').onclick = function(e) {
638                 if (e.ctrlKey) {
639                    window.xulG.new_patron_tab( {}, { 'id' : au_obj.id() } );
640                    return;
641                 }
642                 copy_to_clipboard(au_obj.card().barcode());
643             };
644
645             set("hold_status", details.hold.status()); 
646             set("transit", details.hold.transit()); 
647             set("capture_time", util.date.formatted_date( details.hold.capture_time(), '%{localized}' )); 
648             set("current_copy", details.hold.current_copy()); 
649             set("email_notify", details.hold.email_notify()); 
650             set("expire_time", util.date.formatted_date( details.hold.expire_time(), '%{localized}' )); 
651             try { set("fulfillment_lib" , typeof details.hold.fulfillment_lib() == 'object' ? details.hold.fulfillment_lib().shortname() : data.hash.aou[ details.hold.fulfillment_lib() ].shortname() );  } catch(E) {}
652             try { set_tooltip("fulfillment_lib" , typeof details.hold.fulfillment_lib() == 'object' ? details.hold.fulfillment_lib().name() : data.hash.aou[ details.hold.fulfillment_lib() ].name() );  } catch(E) {}
653             set("fulfillment_staff", details.hold.fulfillment_staff()); 
654             set("fulfillment_time", util.date.formatted_date( details.hold.fulfillment_time(), '%{localized}' )); 
655             set("hold_type", details.hold.hold_type()); 
656             set("holdable_formats", details.hold.holdable_formats()); 
657             set("hold_id", details.hold.id()); 
658             set("phone_notify", details.hold.phone_notify()); 
659             try { set("pickup_lib" , typeof details.hold.pickup_lib() == 'object' ? details.hold.pickup_lib().shortname() : data.hash.aou[ details.hold.pickup_lib() ].shortname() );  } catch(E) {}
660             try { set_tooltip("pickup_lib" , typeof details.hold.pickup_lib() == 'object' ? details.hold.pickup_lib().name() : data.hash.aou[ details.hold.pickup_lib() ].name() );  } catch(E) {}
661             set("prev_check_time", util.date.formatted_date( details.hold.prev_check_time(), '%{localized}' )); 
662             try { set("request_lib" , typeof details.hold.request_lib() == 'object' ? details.hold.request_lib().shortname() : data.hash.aou[ details.hold.request_lib() ].shortname() ); } catch(E) {}
663             try { set_tooltip("request_lib" , typeof details.hold.request_lib() == 'object' ? details.hold.request_lib().name() : data.hash.aou[ details.hold.request_lib() ].name() ); } catch(E) {}
664             set("request_time", util.date.formatted_date( details.hold.request_time(), '%{localized}' )); 
665             set("requestor", details.hold.requestor()); 
666             set("selection_depth", details.hold.selection_depth()); 
667             set("selection_ou" , typeof details.hold.selection_ou() == 'object' ? details.hold.selection_ou().shortname() : data.hash.aou[ details.hold.selection_ou() ].shortname() ); 
668             set_tooltip("selection_ou" , typeof details.hold.selection_ou() == 'object' ? details.hold.selection_ou().name() : data.hash.aou[ details.hold.selection_ou() ].name() ); 
669             set("target", details.hold.target()); 
670             set("hold_usr", details.hold.usr()); 
671             set("cancel_time", util.date.formatted_date( details.hold.cancel_time(), '%{localized}' )); 
672             set("notify_time", util.date.formatted_date( details.hold.notify_time(), '%{localized}' )); 
673             set("notify_count", details.hold.notify_count()); 
674             set("notifications", details.hold.notifications()); 
675             set("bib_rec", details.hold.bib_rec()); 
676             set("eligible_copies", details.hold.eligible_copies()); 
677             set("frozen", details.hold.frozen()); 
678             set("thaw_date", util.date.formatted_date( details.hold.thaw_date(), '%{localized}' )); 
679             set("shelf_time", util.date.formatted_date( details.hold.shelf_time(), '%{localized}' )); 
680             set("cancel_cause", details.hold.cancel_cause()); 
681             set("cancel_note", details.hold.cancel_note()); 
682             set("notes", details.hold.notes()); 
683         } else {
684             if (details.copy.status() == 8 /* ON HOLDS SHELF */) {
685                 $('hold_caption').setAttribute('label', $('circStrings').getString('staff.circ.copy_details.bad_hold_status'));
686             } else {
687                 $('hold_caption').setAttribute('label', $('circStrings').getString('staff.circ.copy_details.no_hold'));
688             }
689         }
690
691         var x = document.getElementById('cat_deck');
692         if (x) {
693             JSAN.use('util.deck');
694             var d = new util.deck('cat_deck');
695             d.reset_iframe( urls.XUL_MARC_VIEW, {}, { 'docid' : details.mvr ? details.mvr.doc_id() : -1 } );
696         }
697
698     } catch(E) {
699         alert(E);
700     }
701 }