3 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
4 if (typeof JSAN == 'undefined') { throw( "The JSAN library object is missing."); }
5 JSAN.errorLevel = "die"; // none, warn, or die
6 JSAN.addRepository('..');
7 JSAN.use('util.error'); g.error = new util.error();
8 g.error.sdump('D_TRACE','my_init() for offline_renew.xul');
10 if (typeof window.xulG == 'object' && typeof window.xulG.set_tab_name == 'function') {
11 try { window.xulG.set_tab_name('Standalone'); } catch(E) { alert(E); }
14 JSAN.use('OpenILS.data'); g.data = new OpenILS.data(); g.data.init({'via':'stash'});
16 JSAN.use('util.list'); g.list = new util.list('checkout_list');
17 JSAN.use('circ.util');
19 'columns' : circ.util.offline_renew_columns(),
20 'map_row_to_column' : circ.util.std_map_row_to_column(),
23 JSAN.use('util.date');
24 var today = new Date();
25 var todayPlus = new Date(); todayPlus.setTime( today.getTime() + 24*60*60*1000*14 );
26 todayPlus = util.date.formatted_date(todayPlus,"%F");
28 $('duedate').setAttribute('value',todayPlus);
29 $('duedate').addEventListener('change',check_date,false);
31 $('p_barcode').addEventListener('change',test_patron,false);
33 $('p_barcode').addEventListener('keypress',handle_keypress,false);
34 $('p_barcode').focus();
36 $('i_barcode').addEventListener('keypress',handle_keypress,false);
37 $('enter').addEventListener('command',handle_enter,false);
39 $('duedate_menu').addEventListener('command',handle_duedate_menu,false);
41 $('submit').addEventListener('command',next_patron,false);
43 JSAN.use('util.file');
44 var file = new util.file('offline_delta');
45 if (file._file.exists()) { g.delta = file.get_object()[0]; file.close(); } else { g.delta = 0; }
48 var err_msg = "!! This software has encountered an error. Please tell your friendly " +
49 "system administrator or software developer the following:\ncirc/offline_renew.xul\n" + E + '\n';
50 try { g.error.sdump('D_ERROR',err_msg); } catch(E) { dump(err_msg); }
55 function $(id) { return document.getElementById(id); }
57 function test_patron(ev) {
59 var barcode = ev.target.value;
60 JSAN.use('util.barcode');
61 if ( ($('strict_p_barcode').checked) && (! util.barcode.check(barcode)) ) {
62 var r = g.error.yns_alert('This barcode has a bad checkdigit.','Barcode Warning','Ok','Clear',null,'Check here to confirm this message');
74 if (g.data.bad_patrons[barcode]) {
75 var msg = 'Warning: As of ' + g.data.bad_patrons_date.substr(0,15) + ', this barcode (' + barcode + ') was flagged ';
76 switch(g.data.bad_patrons[barcode]) {
77 case 'L' : msg += 'Lost'; break;
78 case 'E' : msg += 'Expired'; break;
79 case 'B' : msg += 'Barred'; break;
80 case 'D' : msg += 'Blocked'; break;
81 default : msg += ' with an unknown code: ' + g.data.bad_patrons[barcode]; break;
83 var r = g.error.yns_alert(msg,'Barcode Warning','Ok','Clear',null,'Check here to confirm this message');
98 function handle_keypress(ev) {
99 if ( (! ev.keyCode) || (ev.keyCode != 13) ) return;
101 case $('p_barcode') : setTimeout( function() { $('i_barcode').focus(); },0 ); break;
102 case $('i_barcode') : handle_enter(); break;
107 function handle_enter(ev) {
108 JSAN.use('util.barcode');
109 if ( ($('strict_i_barcode').checked) && (! util.barcode.check($('i_barcode').value)) ) {
110 var r = g.error.yns_alert('This barcode has a bad checkdigit.','Barcode Warning','Ok','Clear',null,'Check here to confirm this message');
114 ev.target.value = '';
119 append_to_list('barcode');
122 append_to_list('barcode');
126 function handle_duedate_menu(ev) {
127 if (ev.target.value=='0') return;
128 JSAN.use('util.date');
129 var today = new Date();
130 var todayPlus = new Date();
131 todayPlus.setTime( today.getTime() + 24*60*60*1000*ev.target.value );
132 todayPlus = util.date.formatted_date(todayPlus,'%F');
133 $('duedate').setAttribute('value',todayPlus);
134 $('duedate').value = todayPlus;
137 function check_date(ev) {
138 JSAN.use('util.date');
140 if (! util.date.check('YYYY-MM-DD',ev.target.value) ) { throw('Invalid Date'); }
141 if (util.date.check_past('YYYY-MM-DD',ev.target.value) ) { throw('Due date needs to be after today.'); }
142 if ( util.date.formatted_date(new Date(),'%F') == ev.target.value) { throw('Due date needs to be after today.'); }
145 var today = new Date();
146 var todayPlus = new Date(); todayPlus.setTime( today.getTime() + 24*60*60*1000*14 );
147 todayPlus = util.date.formatted_date(todayPlus,"%F");
148 ev.target.value = todayPlus;
152 function append_to_list(checkout_type,count) {
159 my.timestamp = parseInt( new Date().getTime() / 1000) + g.delta;
160 my.checkout_time = util.date.formatted_date(new Date(),"%F %H:%M:%s");
162 var p_barcode = $('p_barcode').value;
164 /* Not strictly necessary for a renewal
165 alert('Please enter a patron barcode first.');
170 // Need to validate patron barcode against bad patron list
171 my.patron_barcode = p_barcode;
174 var due_date = $('duedate').value; // Need to validate this
175 my.due_date = due_date;
177 var i_barcode = $('i_barcode').value;
178 switch(checkout_type) {
180 if (! i_barcode) return;
182 var rows = g.list.dump_with_keys();
183 for (var i = 0; i < rows.length; i++) {
184 if (rows[i].barcode == i_barcode) {
185 g.error.yns_alert('This barcode has already been scanned.','Duplicate Scan','Ok',null,null,'Check here to confirm this message');
190 my.barcode = i_barcode;
192 default: alert("Please report that this happened."); break;
195 g.list.append( { 'row' : { 'my' : my } } );
197 var x = $('i_barcode'); x.value = ''; x.focus();
201 dump(E+'\n'); alert(E);
206 function next_patron() {
208 JSAN.use('util.file'); var file = new util.file('pending_xacts');
209 var rows = g.list.dump_with_keys();
210 for (var i = 0; i < rows.length; i++) {
211 var row = rows[i]; row.delta = g.delta;
212 if (row.patron_barcode == '') {
213 delete(row.patron_barcode);
215 file.append_object(row);
219 if ($('print_receipt').checked) {
222 'patron_barcode' : $('p_barcode').value,
223 'header' : g.data.print_list_templates.offline_renew.header,
224 'line_item' : g.data.print_list_templates.offline_renew.line_item,
225 'footer' : g.data.print_list_templates.offline_renew.footer,
226 'type' : g.data.print_list_templates.offline_renew.type,
227 'list' : g.list.dump(),
229 JSAN.use('util.print'); var print = new util.print();
230 print.tree_list( params );
232 g.error.sdump('D_ERROR','print: ' + E);
233 alert('print: ' + E);
240 x = $('i_barcode'); x.value = '';
241 x = $('p_barcode'); x.value = ''; x.focus();
244 dump(E+'\n'); alert(E);