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