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('util.list'); g.list = new util.list('checkout_list');
19 'label' : 'Timestamp',
20 'flex' : 1, 'primary' : false, 'hidden' : true,
21 'render' : 'my.timestamp'
24 'id' : 'checkout_time',
25 'label' : 'Check Out Time',
26 'flex' : 1, 'primary' : false, 'hidden' : true,
27 'render' : 'my.checkout_time'
31 'label' : 'Transaction Type',
32 'flex' : 1, 'primary' : false, 'hidden' : true,
36 'id' : 'patron_barcode',
37 'label' : 'Patron Barcode',
38 'flex' : 1, 'primary' : false, 'hidden' : true,
39 'render' : 'my.patron_barcode'
43 'label' : 'Item Barcode',
44 'flex' : 2, 'primary' : true, 'hidden' : false,
45 'render' : 'my.barcode'
50 'flex' : 1, 'primary' : false, 'hidden' : false,
51 'render' : 'my.due_date'
54 'map_row_to_column' : function(row,col) {
55 // row contains { 'my' : { 'barcode' : xxx, 'duedate' : xxx } }
56 // col contains one of the objects listed above in columns
61 value = eval( col.render );
62 if (typeof value == 'undefined') value = '';
65 JSAN.use('util.error'); var error = new util.error();
66 error.sdump('D_WARN','map_row_to_column: ' + E);
73 JSAN.use('util.date');
74 var today = new Date();
75 var todayPlus = new Date(); todayPlus.setTime( today.getTime() + 24*60*60*1000*14 );
76 todayPlus = util.date.formatted_date(todayPlus,"%F");
78 $('duedate').setAttribute('value',todayPlus);
80 $('p_barcode').addEventListener('keypress',handle_keypress,false);
81 $('p_barcode').focus();
83 $('i_barcode').addEventListener('keypress',handle_keypress,false);
85 $('duedate_menu').addEventListener('command',handle_duedate_menu,false);
87 $('submit').addEventListener('command',next_patron,false);
90 var err_msg = "!! This software has encountered an error. Please tell your friendly " +
91 "system administrator or software developer the following:\ncirc/offline_renew.xul\n" + E + '\n';
92 try { g.error.sdump('D_ERROR',err_msg); } catch(E) { dump(err_msg); }
97 function $(id) { return document.getElementById(id); }
99 function handle_keypress(ev) {
100 if ( (! ev.keyCode) || (ev.keyCode != 13) ) return;
102 case $('p_barcode') : $('i_barcode').focus(); break;
103 case $('i_barcode') : append_to_list('barcode'); break;
108 function handle_duedate_menu(ev) {
109 if (ev.target.value=='0') return;
110 JSAN.use('util.date');
111 var today = new Date();
112 var todayPlus = new Date();
113 todayPlus.setTime( today.getTime() + 24*60*60*1000*ev.target.value );
114 todayPlus = util.date.formatted_date(todayPlus,'%F');
115 $('duedate').setAttribute('value',todayPlus);
116 $('duedate').value = todayPlus;
119 function handle_barcode_menu(ev) {
122 function append_to_list(checkout_type,count) {
129 my.timestamp = new Date().getTime();
130 my.checkout_time = util.date.formatted_date(new Date(),"%F %H:%M:%s");
132 var p_barcode = $('p_barcode').value;
134 /* Not strictly necessary for a renewal
135 alert('Please enter a patron barcode first.');
140 // Need to validate patron barcode against bad patron list
141 my.patron_barcode = p_barcode;
144 var due_date = $('duedate').value; // Need to validate this
145 my.due_date = due_date;
147 var i_barcode = $('i_barcode').value;
148 switch(checkout_type) {
150 if (! i_barcode) return;
152 var rows = g.list.dump_with_keys();
153 for (var i = 0; i < rows.length; i++) {
154 if (rows[i].barcode == i_barcode) {
155 alert('This barcode has already been scanned.');
160 my.barcode = i_barcode;
162 default: alert("Please report that this happened."); break;
165 g.list.append( { 'row' : { 'my' : my } } );
167 var x = $('i_barcode'); x.value = ''; x.focus();
171 dump(E+'\n'); alert(E);
176 function next_patron() {
178 JSAN.use('util.file'); var file = new util.file('pending_xacts');
179 var rows = g.list.dump_with_keys();
180 for (var i = 0; i < rows.length; i++) {
182 if (row.patron_barcode == '') {
183 delete(row.patron_barcode);
185 file.append_object(row);
191 x = $('i_barcode'); x.value = '';
192 x = $('p_barcode'); x.value = ''; x.focus();
195 dump(E+'\n'); alert(E);