]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/xul/staff_client/server/circ/alternate_copy_summary.js
show circ rules in Item Details given an active circulation
[Evergreen.git] / Open-ILS / xul / staff_client / server / circ / alternate_copy_summary.js
1 var error; 
2 var network;
3 var data;
4
5 function my_init() {
6     try {
7         netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
8         if (typeof JSAN == 'undefined') { throw( "The JSAN library object is missing."); }
9         JSAN.errorLevel = "die"; // none, warn, or die
10         JSAN.addRepository('/xul/server/');
11         JSAN.use('util.error'); error = new util.error();
12         error.sdump('D_TRACE','my_init() for alternate_copy_summary.xul');
13
14         JSAN.use('util.network'); network = new util.network();
15         JSAN.use('OpenILS.data'); data = new OpenILS.data(); data.stash_retrieve();
16
17         // timeout so xulG gets a chance to get pushed in
18         setTimeout(
19             function () { xulG.from_item_details_new = false; load_item(); },
20             1000
21         );
22
23     } catch(E) {
24         try { error.standard_unexpected_error_alert('main/test.xul',E); } catch(F) { alert(E); }
25     }
26 }
27
28 function set(name,value) { 
29     var nodes = document.getElementsByAttribute('name',name); 
30     for (var i = 0; i < nodes.length; i++) {
31         nodes[i].setAttribute('value',value); nodes[i].value = value; 
32     }
33 }
34
35 function set_tooltip(name,value) { 
36     var nodes = document.getElementsByAttribute('name',name); 
37     for (var i = 0; i < nodes.length; i++) {
38         nodes[i].setAttribute('tooltiptext',value);
39     }
40 }
41
42 function renewal_composite_kludge(circ) {
43     // Only a corrupt database could give us a situation where more
44     // than one of these were true at a time, right?
45     if (circ.desk_renewal() == "t")
46         return document.getElementById('circStrings').getString(
47             'staff.circ.copy_details.desk_renewal'
48         );
49     else if (circ.opac_renewal() == "t")
50         return document.getElementById('circStrings').getString(
51             'staff.circ.copy_details.opac_renewal'
52         );
53     else if (circ.phone_renewal() == "t")
54         return document.getElementById('circStrings').getString(
55             'staff.circ.copy_details.phone_renewal'
56         );
57     else return "";
58 }
59
60 function load_item() {
61     try {
62         if (! xulG.barcode) return;
63
64         if (xulG.fetched_copy_details && xulG.fetched_copy_details[xulG.barcode]) {
65             var details = xulG.fetched_copy_details[xulG.barcode];
66             // We don't want to use these details more than once (i.e., we
67             // don't want cached data after things have potentially changed).
68             delete xulG.fetched_copy_details[xulG.barcode];
69         } else {
70             var details = network.simple_request('FM_ACP_DETAILS_VIA_BARCODE.authoritative', [ ses(), xulG.barcode ]);
71             // Should get back .mvr, .copy, .volume, .transit, .circ, .hold
72         }
73
74         if (typeof bib_brief_overlay == 'function') bib_brief_overlay( { 'mvr' : details.mvr, 'acp' : details.copy } );
75 /*
76         set('title', '');
77         set('author', '');
78         set('doc_id', '');
79         set('doc_type', '');
80         set('pubdate', '');
81         set('isbn', '');
82         set('publisher', '');
83         set('tcn', '');
84         set('subject', '');
85         set('types_of_resource', '');
86         set('call_numbers', '');
87         set('edition', '');
88         set('online_loc', '');
89         set('synopsis', '');
90         set('physical_description', '');
91         set('toc', '');
92         set('copy_count', '');
93         set('series', '');
94         set('serials', '');
95
96         if (details.mvr) {
97             set('title',details.mvr.title()); 
98             set('author',details.mvr.author());
99             set('doc_id', details.mvr.doc_id());
100             set('doc_type', details.mvr.doc_type());
101             set('pubdate', details.mvr.pubdate());
102             set('isbn',details.mvr.isbn());
103             set('publisher', details.mvr.publisher());
104             set('tcn', details.mvr.tcn());
105             set('subject', details.mvr.subject());
106             set('types_of_resource', details.mvr.types_of_resource());
107             set('call_numbers', details.mvr.call_numbers());
108             set('edition', details.mvr.edition());
109             set('online_loc', details.mvr.online_loc());
110             set('synopsis', details.mvr.synopsis());
111             set('physical_description', details.mvr.physical_description());
112             set('toc', details.mvr.toc());
113             set('copy_count', details.mvr.copy_count());
114             set('series', details.mvr.series());
115             set('serials', details.mvr.serials());
116         } else {
117             set('title',details.copy.dummy_title());
118             set('author',details.copy.dummy_author()); 
119             set('isbn',details.copy.dummy_isbn());
120         }
121 */
122         set("stat_cat_entries", '');
123         set("age_protect", '');
124         set("alert_message", '');
125         set("barcode", '');
126         set("call_number", '');
127         set("circ_as_type", '');
128         set("copy_circ_lib" , '');
129         set("circ_modifier", '');
130         set("circulate", '');
131         set("copy_number", '');
132         set("copy_create_date", '');
133         set("status_changed_time", '');
134         set("copy_creator", '');
135         set("deleted", '');
136         set("deposit", '');
137         set("deposit_amount", '');
138         set("dummy_author", '');
139         set("dummy_title", '');
140         set("copy_edit_date", '');
141         set("copy_editor", '');
142         set("fine_level", '');
143         set("holdable", '');
144         set("copy_id", '');
145         set("loan_duration", '');
146         set("location", '');
147         set("renewal_type", '');
148         set("opac_visible", '');
149         set("price", '');
150         set("ref", '');
151         set("status", '');
152         set("notes", '');
153         set("stat_cat_entry_copy_maps", '');
154         set("circulations", '');
155         set("total_circ_count", '');
156         set_tooltip("total_circ_count", '');
157         set("total_circ_count_prev_year", '');
158         set("total_circ_count_curr_year", '');
159         set("holds", '');
160
161         if (details.copy) {
162             set("stat_cat_entries", details.copy.stat_cat_entries()); 
163             set("age_protect", details.copy.age_protect()); 
164             set("alert_message", details.copy.alert_message()); 
165             set("barcode", details.copy.barcode()); 
166             set("call_number", details.copy.call_number()); 
167             set("circ_as_type", details.copy.circ_as_type()); 
168             set("copy_circ_lib" , details.copy.circ_lib()); 
169             set("circ_modifier", details.copy.circ_modifier()); 
170             set("circulate", details.copy.circulate()); 
171             set("copy_number", details.copy.copy_number()); 
172             set("copy_create_date", details.copy.create_date()); 
173             set("status_changed_time", details.copy.status_changed_time()); 
174             set("copy_creator", details.copy.creator()); 
175             set("deleted", details.copy.deleted()); 
176             set("deposit", details.copy.deposit()); 
177             set("deposit_amount", details.copy.deposit_amount()); 
178             set("dummy_author", details.copy.dummy_author()); 
179             set("dummy_title", details.copy.dummy_title()); 
180             set("copy_edit_date", details.copy.edit_date()); 
181             set("copy_editor", details.copy.editor()); 
182             set("fine_level", details.copy.fine_level()); 
183             set("holdable", details.copy.holdable()); 
184             set("copy_id", details.copy.id()); 
185             set("loan_duration", details.copy.loan_duration()); 
186             set("location", details.copy.location()); 
187             set("opac_visible", details.copy.opac_visible()); 
188             set("price", details.copy.price()); 
189             set("ref", details.copy.ref()); 
190             set("status", details.copy.status()); 
191             set("notes", details.copy.notes()); 
192             set("stat_cat_entry_copy_maps", details.copy.stat_cat_entry_copy_maps()); 
193             set("circulations", details.copy.circulations()); 
194             set("holds", details.copy.holds()); 
195
196             network.simple_request('FM_CIRC_IMPROVED_COUNT_VIA_COPY', [ses(), { 'copy' : details.copy.id() } ], function(req) {
197                 var r = req.getResultObject();
198                 var total = 0; var tooltip = ''; var year = {};
199                 for (var i = 0; i < r.length; i++) {
200                     total += Number( r[i].count() );
201                     if (typeof year[ r[i].year() ] == 'undefined') year[ r[i].year() ] = 0;
202                     year[ r[i].year() ] += Number( r[i].count() ); // Add original circs and renewals together
203                 }
204                 set( 'total_circ_count', total );
205                 var curr_year = (new Date()).getFullYear();
206                 var prev_year = curr_year - 1;
207                 set( 'total_circ_count_curr_year', year[ curr_year ] || 0 );
208                 set( 'total_circ_count_prev_year', year[ prev_year ] || 0 );
209                 var keys = []; for (var i in year) { keys.push( i ); }; keys.sort();
210                 for (var i = 0; i < keys.length; i++) {
211                     tooltip += document.getElementById('circStrings').getFormattedString( 
212                         'staff.circ.copy_details.circ_count_by_year', [ 
213                             keys[i] == -1 ? document.getElementById('circStrings').getString('staff.circ.copy_details.circ_count_by_year.legacy_label') : keys[i], 
214                             year[keys[i]]
215                         ] 
216                     ) + '\n';
217                 }
218                 set_tooltip( 'total_circ_count', tooltip );
219             } );
220         }
221
222         set("copies", '');
223         set("volume_create_date", '');
224         set("volume_creator", '');
225         set("deleted", '');
226         set("volume_edit_date", '');
227         set("volume_editor", '');
228         set("volume_id", '');
229         set("label", '');
230         set("owning_lib" , '');
231         set("record", '');
232         set("notes", '');
233         set("uri_maps", '');
234         set("uris", '');
235
236         if (details.volume) {
237             set("copies", details.volume.copies()); 
238             set("volume_create_date", details.volume.create_date()); 
239             set("volume_creator", details.volume.creator()); 
240             set("deleted", details.volume.deleted()); 
241             set("volume_edit_date", details.volume.edit_date()); 
242             set("volume_editor", details.volume.editor()); 
243             set("volume_id", details.volume.id()); 
244             set("label", details.volume.label()); 
245             set("owning_lib" , details.volume.owning_lib()); 
246             set("record", details.volume.record()); 
247             set("notes", details.volume.notes()); 
248             set("uri_maps", details.volume.uri_maps()); 
249             set("uris", details.volume.uris()); 
250         }
251
252         set("copy_status", '');
253         set("dest", '');
254         set("dest_recv_time", '');
255         set("transit_id", '');
256         set("persistant_transfer", '');
257         set("prev_hop", '');
258         set("source", '');
259         set("source_send_time", '');
260         set("target_copy", '');
261         set("hold_transit_copy", '');
262
263         if (details.transit) {
264             set("copy_status", details.transit.copy_status()); 
265             set("dest", details.transit.dest()); 
266             set("dest_recv_time", details.transit.dest_recv_time()); 
267             set("transit_id", details.transit.id()); 
268             set("persistant_transfer", details.transit.persistant_transfer()); 
269             set("prev_hop", details.transit.prev_hop()); 
270             set("source", details.transit.source()); 
271             set("source_send_time", details.transit.source_send_time()); 
272             set("target_copy", details.transit.target_copy()); 
273             set("hold_transit_copy", details.transit.hold_transit_copy()); 
274         }
275
276         set("checkin_lib", '');
277         set("checkin_workstation",""); 
278         set("checkin_staff", '');
279         set("checkin_time", '');
280         set("checkin_scan_time", '');
281         set("circ_circ_lib" , '');
282         set("circ_staff", '');
283         set("desk_renewal", '');
284         set("due_date", '');
285         set("duration", '');
286         set("duration_rule", '');
287         set("fine_interval", '');
288         set("circ_id", '');
289         set("max_fine", '');
290         set("max_fine_rule", '');
291         set("opac_renewal", '');
292         set("phone_renewal", '');
293         set("recurring_fine", '');
294         set("recurring_fine_rule", '');
295         set("renewal_remaining", '');
296         set("stop_fines", '');
297         set("stop_fines_time", '');
298         set("target_copy", '');
299         set("usr", '');
300         set("xact_finish", '');
301         set("xact_start", '');
302         set("create_time", '');
303         set("workstation", '');
304         set("renewal_workstation", '');
305         set("checkout_workstation", '');
306         set("billings", '');
307         set("payments", '');
308         set("billable_transaction", '');
309         set("circ_type", '');
310         set("billing_total", '');
311         set("payment_total", '');
312
313         if (details.circ) {
314             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) {};
315             if (details.circ.checkin_workstation()) {
316                 set("checkin_workstation", details.circ.checkin_workstation().name()); 
317             }
318             set("checkin_staff", details.circ.checkin_staff()); 
319             set("checkin_time", details.circ.checkin_time()); 
320             set("checkin_scan_time", details.circ.checkin_scan_time()); 
321             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) {};
322             set("circ_staff", details.circ.circ_staff()); 
323             set("desk_renewal", details.circ.desk_renewal()); 
324             set("due_date", details.circ.due_date()); 
325             set("duration", details.circ.duration()); 
326             set("fine_interval", details.circ.fine_interval()); 
327             set("circ_id", details.circ.id()); 
328             set("max_fine", details.circ.max_fine()); 
329             set("opac_renewal", details.circ.opac_renewal()); 
330             set("phone_renewal", details.circ.phone_renewal()); 
331             set("renewal_type", renewal_composite_kludge(details.circ));
332             set("recurring_fine", details.circ.recurring_fine()); 
333             set("renewal_remaining", details.circ.renewal_remaining()); 
334             set("stop_fines", details.circ.stop_fines()); 
335             set("stop_fines_time", details.circ.stop_fines_time()); 
336             set("target_copy", details.circ.target_copy()); 
337             set("usr", details.circ.usr()); 
338             set("xact_finish", details.circ.xact_finish()); 
339             set("xact_start", details.circ.xact_start()); 
340             set("create_time", details.circ.create_time()); 
341             set("workstation", details.circ.workstation()); 
342             if (get_bool(details.circ.opac_renewal())||get_bool(details.circ.phone_renewal())||get_bool(details.circ.desk_renewal())) {
343                 set("renewal_workstation", (typeof details.circ.workstation() == 'object' && details.circ.workstation() != null) ? details.circ.workstation().name() : details.circ.workstation() ); 
344                 network.simple_request('FM_CIRC_CHAIN', [ses(), details.circ.id() ], function(req) { // Tiny race condition between details.circ and circs[circs.length-1] here, but meh :)
345                     try {
346                         var circs = req.getResultObject();
347                         set("checkout_workstation", (typeof circs[0].workstation() == 'object' && circs[0].workstation() != null) ? circs[0].workstation().name() : circs[0].workstation() );
348                     } catch(E) {
349                         alert('Error in alternate_copy_summary.js, FM_CIRC_CHAIN: ' + E);
350                     }
351                 } );
352             } else {
353                 set("checkout_workstation", (typeof details.circ.workstation() == 'object' && details.circ.workstation() != null) ? details.circ.workstation().name() : details.circ.workstation() );
354             }
355             set("billings", details.circ.billings()); 
356             set("payments", details.circ.payments()); 
357             set("billable_transaction", details.circ.billable_transaction()); 
358             set("circ_type", details.circ.circ_type()); 
359             set("billing_total", details.circ.billing_total()); 
360             set("payment_total", details.circ.payment_total()); 
361             if (! details.circ.checkin_time() ) {
362                 set("recurring_fine_rule", document.getElementById('circStrings').getFormattedString(
363                     'staff.circ.copy_details.recurring_fine_rule_format',
364                     [
365                         details.circ.recurring_fine_rule().name(),
366                         details.circ.recurring_fine_rule().id(),
367                         details.circ.recurring_fine_rule().low(),
368                         details.circ.recurring_fine_rule().normal(),
369                         details.circ.recurring_fine_rule().high(),
370                         details.circ.recurring_fine_rule().recurrence_interval()
371                     ]
372                 )); 
373                 set_tooltip("recurring_fine_rule", document.getElementById('circStrings').getFormattedString(
374                     'staff.circ.copy_details.recurring_fine_rule_tooltip_format',
375                     [
376                         details.circ.recurring_fine_rule().name(),
377                         details.circ.recurring_fine_rule().id(),
378                         details.circ.recurring_fine_rule().low(),
379                         details.circ.recurring_fine_rule().normal(),
380                         details.circ.recurring_fine_rule().high(),
381                         details.circ.recurring_fine_rule().recurrence_interval()
382                     ]
383                 )); 
384                 set("duration_rule", document.getElementById('circStrings').getFormattedString(
385                     'staff.circ.copy_details.duration_rule_format',
386                     [
387                         details.circ.duration_rule().name(),
388                         details.circ.duration_rule().id(),
389                         details.circ.duration_rule().shrt(),
390                         details.circ.duration_rule().normal(),
391                         details.circ.duration_rule().extended(),
392                         details.circ.duration_rule().max_renewals()
393                     ]
394                 )); 
395                 set_tooltip("duration_rule", document.getElementById('circStrings').getFormattedString(
396                     'staff.circ.copy_details.duration_rule_tooltip_format',
397                     [
398                         details.circ.duration_rule().name(),
399                         details.circ.duration_rule().id(),
400                         details.circ.duration_rule().shrt(),
401                         details.circ.duration_rule().normal(),
402                         details.circ.duration_rule().extended(),
403                         details.circ.duration_rule().max_renewals()
404                     ]
405                 )); 
406                 set("max_fine_rule", document.getElementById('circStrings').getFormattedString(
407                     'staff.circ.copy_details.max_fine_rule_format',
408                     [
409                         details.circ.max_fine_rule().name(),
410                         details.circ.max_fine_rule().id(),
411                         details.circ.max_fine_rule().amount(),
412                         details.circ.max_fine_rule().is_percent()
413                     ]
414                 ));
415                 set_tooltip("max_fine_rule", document.getElementById('circStrings').getFormattedString(
416                     'staff.circ.copy_details.max_fine_rule_tooltip_format',
417                     [
418                         details.circ.max_fine_rule().name(),
419                         details.circ.max_fine_rule().id(),
420                         details.circ.max_fine_rule().amount(),
421                         details.circ.max_fine_rule().is_percent()
422                     ]
423                 ));
424             }
425         }
426
427         set("status", '');
428         set("transit", '');
429         set("capture_time", '');
430         set("current_copy", '');
431         set("email_notify", '');
432         set("expire_time", '');
433         set("fulfillment_lib", '');
434         set("fulfillment_staff", '');
435         set("fulfillment_time", '');
436         set("hold_type", '');
437         set("holdable_formats", '');
438         set("hold_id", '');
439         set("phone_notify", '');
440         set("pickup_lib", '');
441         set("prev_check_time", '');
442         set("request_lib", '');
443         set("request_time", '');
444         set("requestor", '');
445         set("selection_depth", '');
446         set("selection_ou", '');
447         set("target", '');
448         set("usr", '');
449         set("cancel_time", '');
450         set("notify_time", '');
451         set("notify_count", '');
452         set("notifications", '');
453         set("bib_rec", '');
454         set("eligible_copies", '');
455         set("frozen", '');
456         set("thaw_date", '');
457         set("shelf_time", '');
458         set("cancel_cause", '');
459         set("cancel_note", '');
460         set("notes", '');
461
462         if (details.hold) {
463             set("status", details.hold.status()); 
464             set("transit", details.hold.transit()); 
465             set("capture_time", details.hold.capture_time()); 
466             set("current_copy", details.hold.current_copy()); 
467             set("email_notify", details.hold.email_notify()); 
468             set("expire_time", details.hold.expire_time()); 
469             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) {}
470             set("fulfillment_staff", details.hold.fulfillment_staff()); 
471             set("fulfillment_time", details.hold.fulfillment_time()); 
472             set("hold_type", details.hold.hold_type()); 
473             set("holdable_formats", details.hold.holdable_formats()); 
474             set("hold_id", details.hold.id()); 
475             set("phone_notify", details.hold.phone_notify()); 
476             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) {}
477             set("prev_check_time", details.hold.prev_check_time()); 
478             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) {}
479             set("request_time", details.hold.request_time()); 
480             set("requestor", details.hold.requestor()); 
481             set("selection_depth", details.hold.selection_depth()); 
482             set("selection_ou" , typeof details.hold.selection_ou() == 'object' ? details.hold.selection_ou().shortname() : data.hash.aou[ details.hold.selection_ou() ].shortname() ); 
483             set("target", details.hold.target()); 
484             set("usr", details.hold.usr()); 
485             set("cancel_time", details.hold.cancel_time()); 
486             set("notify_time", details.hold.notify_time()); 
487             set("notify_count", details.hold.notify_count()); 
488             set("notifications", details.hold.notifications()); 
489             set("bib_rec", details.hold.bib_rec()); 
490             set("eligible_copies", details.hold.eligible_copies()); 
491             set("frozen", details.hold.frozen()); 
492             set("thaw_date", details.hold.thaw_date()); 
493             set("shelf_time", details.hold.shelf_time()); 
494             set("cancel_cause", details.hold.cancel_cause()); 
495             set("cancel_note", details.hold.cancel_note()); 
496             set("notes", details.hold.notes()); 
497         } 
498
499         var x = document.getElementById('cat_deck');
500         if (x) {
501             JSAN.use('util.deck');
502             var d = new util.deck('cat_deck');
503             d.reset_iframe( urls.XUL_MARC_VIEW, {}, { 'docid' : details.mvr ? details.mvr.doc_id() : -1 } );
504         }
505
506     } catch(E) {
507         alert(E);
508     }
509 }