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