]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/xul/staff_client/server/circ/alternate_copy_summary.js
This fetches action::circ_counts_by_year objects, an improvement over open-ils.circ...
[working/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 load_item() {
39     try {
40         if (! xulG.barcode) return;
41
42         var details = network.simple_request('FM_ACP_DETAILS_VIA_BARCODE.authoritative', [ ses(), xulG.barcode ]);
43         // Should get back .mvr, .copy, .volume, .transit, .circ, .hold
44
45         set('title', '');
46         set('author', '');
47         set('doc_id', '');
48         set('doc_type', '');
49         set('pubdate', '');
50         set('isbn', '');
51         set('publisher', '');
52         set('tcn', '');
53         set('subject', '');
54         set('types_of_resource', '');
55         set('call_numbers', '');
56         set('edition', '');
57         set('online_loc', '');
58         set('synopsis', '');
59         set('physical_description', '');
60         set('toc', '');
61         set('copy_count', '');
62         set('series', '');
63         set('serials', '');
64
65         if (details.mvr) {
66             set('title',details.mvr.title()); 
67             set('author',details.mvr.author());
68             set('doc_id', details.mvr.doc_id());
69             set('doc_type', details.mvr.doc_type());
70             set('pubdate', details.mvr.pubdate());
71             set('isbn',details.mvr.isbn());
72             set('publisher', details.mvr.publisher());
73             set('tcn', details.mvr.tcn());
74             set('subject', details.mvr.subject());
75             set('types_of_resource', details.mvr.types_of_resource());
76             set('call_numbers', details.mvr.call_numbers());
77             set('edition', details.mvr.edition());
78             set('online_loc', details.mvr.online_loc());
79             set('synopsis', details.mvr.synopsis());
80             set('physical_description', details.mvr.physical_description());
81             set('toc', details.mvr.toc());
82             set('copy_count', details.mvr.copy_count());
83             set('series', details.mvr.series());
84             set('serials', details.mvr.serials());
85         } else {
86             set('title',details.copy.dummy_title());
87             set('author',details.copy.dummy_author()); 
88             set('isbn',details.copy.dummy_isbn());
89         }
90
91         set("stat_cat_entries", '');
92         set("age_protect", '');
93         set("alert_message", '');
94         set("barcode", '');
95         set("call_number", '');
96         set("circ_as_type", '');
97         set("copy_circ_lib" , '');
98         set("circ_modifier", '');
99         set("circulate", '');
100         set("copy_number", '');
101         set("create_date", '');
102         set("creator", '');
103         set("deleted", '');
104         set("deposit", '');
105         set("deposit_amount", '');
106         set("dummy_author", '');
107         set("dummy_title", '');
108         set("edit_date", '');
109         set("editor", '');
110         set("fine_level", '');
111         set("holdable", '');
112         set("copy_id", '');
113         set("loan_duration", '');
114         set("location", '');
115         set("opac_visible", '');
116         set("price", '');
117         set("ref", '');
118         set("status", '');
119         set("notes", '');
120         set("stat_cat_entry_copy_maps", '');
121         set("circulations", '');
122         set("total_circ_count", '');
123         set_tooltip("total_circ_count", '');
124         set("holds", '');
125
126         if (details.copy) {
127             set("stat_cat_entries", details.copy.stat_cat_entries()); 
128             set("age_protect", details.copy.age_protect()); 
129             set("alert_message", details.copy.alert_message()); 
130             set("barcode", details.copy.barcode()); 
131             set("call_number", details.copy.call_number()); 
132             set("circ_as_type", details.copy.circ_as_type()); 
133             set("copy_circ_lib" , details.copy.circ_lib()); 
134             set("circ_modifier", details.copy.circ_modifier()); 
135             set("circulate", details.copy.circulate()); 
136             set("copy_number", details.copy.copy_number()); 
137             set("create_date", details.copy.create_date()); 
138             set("creator", details.copy.creator()); 
139             set("deleted", details.copy.deleted()); 
140             set("deposit", details.copy.deposit()); 
141             set("deposit_amount", details.copy.deposit_amount()); 
142             set("dummy_author", details.copy.dummy_author()); 
143             set("dummy_title", details.copy.dummy_title()); 
144             set("edit_date", details.copy.edit_date()); 
145             set("editor", details.copy.editor()); 
146             set("fine_level", details.copy.fine_level()); 
147             set("holdable", details.copy.holdable()); 
148             set("copy_id", details.copy.id()); 
149             set("loan_duration", details.copy.loan_duration()); 
150             set("location", details.copy.location()); 
151             set("opac_visible", details.copy.opac_visible()); 
152             set("price", details.copy.price()); 
153             set("ref", details.copy.ref()); 
154             set("status", details.copy.status()); 
155             set("notes", details.copy.notes()); 
156             set("stat_cat_entry_copy_maps", details.copy.stat_cat_entry_copy_maps()); 
157             set("circulations", details.copy.circulations()); 
158             set("holds", details.copy.holds()); 
159
160             network.simple_request('FM_CIRC_IMPROVED_COUNT_VIA_COPY', [ses(), { 'copy' : details.copy.id() } ], function(req) {
161                 var r = req.getResultObject();
162                 var total = 0; var tooltip = ''; var year = {};
163                 for (var i = 0; i < r.length; i++) {
164                     total += Number( r[i].count() );
165                     if (typeof year[ r[i].year() ] == 'undefined') year[ r[i].year() ] = 0;
166                     year[ r[i].year() ] += r[i].count(); // Add original circs and renewals together
167                 }
168                 set( 'total_circ_count', total );
169                 var keys = []; for (var i in year) { keys.push( i ); }; keys.sort();
170                 for (var i = 0; i < keys.length; i++) {
171                     tooltip += document.getElementById('circStrings').getFormattedString( 
172                         'staff.circ.copy_details.circ_count_by_year', [ 
173                             keys[i] == -1 ? document.getElementById('circStrings').getString('staff.circ.copy_details.circ_count_by_year.legacy_label') : keys[i], 
174                             year[keys[i]]
175                         ] 
176                     ) + '\n';
177                 }
178                 set_tooltip( 'total_circ_count', tooltip );
179             } );
180         }
181
182         set("copies", '');
183         set("create_date", '');
184         set("creator", '');
185         set("deleted", '');
186         set("edit_date", '');
187         set("editor", '');
188         set("volume_id", '');
189         set("label", '');
190         set("owning_lib" , '');
191         set("record", '');
192         set("notes", '');
193         set("uri_maps", '');
194         set("uris", '');
195
196         if (details.volume) {
197             set("copies", details.volume.copies()); 
198             set("create_date", details.volume.create_date()); 
199             set("creator", details.volume.creator()); 
200             set("deleted", details.volume.deleted()); 
201             set("edit_date", details.volume.edit_date()); 
202             set("editor", details.volume.editor()); 
203             set("volume_id", details.volume.id()); 
204             set("label", details.volume.label()); 
205             set("owning_lib" , details.volume.owning_lib()); 
206             set("record", details.volume.record()); 
207             set("notes", details.volume.notes()); 
208             set("uri_maps", details.volume.uri_maps()); 
209             set("uris", details.volume.uris()); 
210         }
211
212         set("copy_status", '');
213         set("dest", '');
214         set("dest_recv_time", '');
215         set("transit_id", '');
216         set("persistant_transfer", '');
217         set("prev_hop", '');
218         set("source", '');
219         set("source_send_time", '');
220         set("target_copy", '');
221         set("hold_transit_copy", '');
222
223         if (details.transit) {
224             set("copy_status", details.transit.copy_status()); 
225             set("dest", details.transit.dest()); 
226             set("dest_recv_time", details.transit.dest_recv_time()); 
227             set("transit_id", details.transit.id()); 
228             set("persistant_transfer", details.transit.persistant_transfer()); 
229             set("prev_hop", details.transit.prev_hop()); 
230             set("source", details.transit.source()); 
231             set("source_send_time", details.transit.source_send_time()); 
232             set("target_copy", details.transit.target_copy()); 
233             set("hold_transit_copy", details.transit.hold_transit_copy()); 
234         }
235
236         set("checkin_lib", '');
237         set("checkin_workstation",""); 
238         set("checkin_staff", '');
239         set("checkin_time", '');
240         set("checkin_scan_time", '');
241         set("circ_circ_lib" , '');
242         set("circ_staff", '');
243         set("desk_renewal", '');
244         set("due_date", '');
245         set("duration", '');
246         set("duration_rule", '');
247         set("fine_interval", '');
248         set("circ_id", '');
249         set("max_fine", '');
250         set("max_fine_rule", '');
251         set("opac_renewal", '');
252         set("phone_renewal", '');
253         set("recuring_fine", '');
254         set("recuring_fine_rule", '');
255         set("renewal_remaining", '');
256         set("stop_fines", '');
257         set("stop_fines_time", '');
258         set("target_copy", '');
259         set("usr", '');
260         set("xact_finish", '');
261         set("xact_start", '');
262         set("create_time", '');
263         set("workstation", '');
264         set("billings", '');
265         set("payments", '');
266         set("billable_transaction", '');
267         set("circ_type", '');
268         set("billing_total", '');
269         set("payment_total", '');
270
271         if (details.circ) {
272             set("checkin_lib", typeof details.circ.checkin_lib() == 'object' ? details.circ.checkin_lib().shortname() : data.hash.aou[ details.circ.checkin_lib() ].shortname() ); 
273             if (details.circ.checkin_workstation()) {
274                 set("checkin_workstation", details.circ.checkin_workstation().name()); 
275             }
276             set("checkin_staff", details.circ.checkin_staff()); 
277             set("checkin_time", details.circ.checkin_time()); 
278             set("checkin_scan_time", details.circ.checkin_scan_time()); 
279             set("circ_circ_lib" , typeof details.circ.circ_lib() == 'object' ? details.circ.circ_lib().shortname() : data.hash.aou[ details.circ.circ_lib() ].shortname() ); 
280             set("circ_staff", details.circ.circ_staff()); 
281             set("desk_renewal", details.circ.desk_renewal()); 
282             set("due_date", details.circ.due_date()); 
283             set("duration", details.circ.duration()); 
284             set("duration_rule", details.circ.duration_rule()); 
285             set("fine_interval", details.circ.fine_interval()); 
286             set("circ_id", details.circ.id()); 
287             set("max_fine", details.circ.max_fine()); 
288             set("max_fine_rule", details.circ.max_fine_rule()); 
289             set("opac_renewal", details.circ.opac_renewal()); 
290             set("phone_renewal", details.circ.phone_renewal()); 
291             set("recuring_fine", details.circ.recuring_fine()); 
292             set("recuring_fine_rule", details.circ.recuring_fine_rule()); 
293             set("renewal_remaining", details.circ.renewal_remaining()); 
294             set("stop_fines", details.circ.stop_fines()); 
295             set("stop_fines_time", details.circ.stop_fines_time()); 
296             set("target_copy", details.circ.target_copy()); 
297             set("usr", details.circ.usr()); 
298             set("xact_finish", details.circ.xact_finish()); 
299             set("xact_start", details.circ.xact_start()); 
300             set("create_time", details.circ.create_time()); 
301             set("workstation", details.circ.workstation()); 
302             set("billings", details.circ.billings()); 
303             set("payments", details.circ.payments()); 
304             set("billable_transaction", details.circ.billable_transaction()); 
305             set("circ_type", details.circ.circ_type()); 
306             set("billing_total", details.circ.billing_total()); 
307             set("payment_total", details.circ.payment_total()); 
308         }
309
310         set("status", '');
311         set("transit", '');
312         set("capture_time", '');
313         set("current_copy", '');
314         set("email_notify", '');
315         set("expire_time", '');
316         set("fulfillment_lib", '');
317         set("fulfillment_staff", '');
318         set("fulfillment_time", '');
319         set("hold_type", '');
320         set("holdable_formats", '');
321         set("hold_id", '');
322         set("phone_notify", '');
323         set("pickup_lib", '');
324         set("prev_check_time", '');
325         set("request_lib", '');
326         set("request_time", '');
327         set("requestor", '');
328         set("selection_depth", '');
329         set("selection_ou", '');
330         set("target", '');
331         set("usr", '');
332         set("cancel_time", '');
333         set("notify_time", '');
334         set("notify_count", '');
335         set("notifications", '');
336         set("bib_rec", '');
337         set("eligible_copies", '');
338         set("frozen", '');
339         set("thaw_date", '');
340         set("shelf_time", '');
341         set("cancel_cause", '');
342         set("cancel_note", '');
343         set("notes", '');
344
345         if (details.hold) {
346             set("status", details.hold.status()); 
347             set("transit", details.hold.transit()); 
348             set("capture_time", details.hold.capture_time()); 
349             set("current_copy", details.hold.current_copy()); 
350             set("email_notify", details.hold.email_notify()); 
351             set("expire_time", details.hold.expire_time()); 
352             set("fulfillment_lib" , typeof details.hold.fulfillment_lib() == 'object' ? details.hold.fulfillment_lib().shortname() : data.hash.aou[ details.hold.fulfillment_lib() ].shortname() ); 
353             set("fulfillment_staff", details.hold.fulfillment_staff()); 
354             set("fulfillment_time", details.hold.fulfillment_time()); 
355             set("hold_type", details.hold.hold_type()); 
356             set("holdable_formats", details.hold.holdable_formats()); 
357             set("hold_id", details.hold.id()); 
358             set("phone_notify", details.hold.phone_notify()); 
359             set("pickup_lib" , typeof details.hold.pickup_lib() == 'object' ? details.hold.pickup_lib().shortname() : data.hash.aou[ details.hold.pickup_lib() ].shortname() ); 
360             set("prev_check_time", details.hold.prev_check_time()); 
361             set("request_lib" , typeof details.hold.request_lib() == 'object' ? details.hold.request_lib().shortname() : data.hash.aou[ details.hold.request_lib() ].shortname() ); 
362             set("request_time", details.hold.request_time()); 
363             set("requestor", details.hold.requestor()); 
364             set("selection_depth", details.hold.selection_depth()); 
365             set("selection_ou" , typeof details.hold.selection_ou() == 'object' ? details.hold.selection_ou().shortname() : data.hash.aou[ details.hold.selection_ou() ].shortname() ); 
366             set("target", details.hold.target()); 
367             set("usr", details.hold.usr()); 
368             set("cancel_time", details.hold.cancel_time()); 
369             set("notify_time", details.hold.notify_time()); 
370             set("notify_count", details.hold.notify_count()); 
371             set("notifications", details.hold.notifications()); 
372             set("bib_rec", details.hold.bib_rec()); 
373             set("eligible_copies", details.hold.eligible_copies()); 
374             set("frozen", details.hold.frozen()); 
375             set("thaw_date", details.hold.thaw_date()); 
376             set("shelf_time", details.hold.shelf_time()); 
377             set("cancel_cause", details.hold.cancel_cause()); 
378             set("cancel_note", details.hold.cancel_note()); 
379             set("notes", details.hold.notes()); 
380         } 
381
382         var x = document.getElementById('cat_deck');
383         if (x) {
384             JSAN.use('util.deck');
385             var d = new util.deck('cat_deck');
386             d.reset_iframe( urls.XUL_MARC_VIEW, {}, { 'docid' : details.mvr ? details.mvr.doc_id() : -1 } );
387         }
388
389     } catch(E) {
390         alert(E);
391     }
392 }