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_checkout.xul');
10 JSAN.use('util.widgets'); JSAN.use('util.file');
12 if (typeof window.xulG == 'object' && typeof window.xulG.set_tab_name == 'function') {
13 try { window.xulG.set_tab_name('Standalone'); } catch(E) { alert(E); }
16 JSAN.use('util.list'); g.list = new util.list('checkout_list');
21 'label' : 'Timestamp',
22 'flex' : 1, 'primary' : false, 'hidden' : true,
23 'render' : 'my.timestamp'
26 'id' : 'checkout_time',
27 'label' : 'Check Out Time',
28 'flex' : 1, 'primary' : false, 'hidden' : true,
29 'render' : 'my.checkout_time'
33 'label' : 'Transaction Type',
34 'flex' : 1, 'primary' : false, 'hidden' : true,
39 'label' : 'Non-Cataloged?',
40 'flex' : 1, 'primary' : false, 'hidden' : true,
41 'render' : 'my.noncat'
45 'label' : 'Non-Cat Type ID',
46 'flex' : 1, 'primary' : false, 'hidden' : true,
47 'render' : 'my.noncat_type'
50 'id' : 'noncat_count',
52 'flex' : 1, 'primary' : false, 'hidden' : false,
53 'render' : 'my.noncat_count'
56 'id' : 'patron_barcode',
57 'label' : 'Patron Barcode',
58 'flex' : 1, 'primary' : false, 'hidden' : true,
59 'render' : 'my.patron_barcode'
63 'label' : 'Item Barcode',
64 'flex' : 2, 'primary' : true, 'hidden' : false,
65 'render' : 'my.barcode'
70 'flex' : 1, 'primary' : false, 'hidden' : false,
71 'render' : 'my.due_date'
74 'map_row_to_column' : function(row,col) {
75 // row contains { 'my' : { 'barcode' : xxx, 'duedate' : xxx } }
76 // col contains one of the objects listed above in columns
81 value = eval( col.render );
82 if (typeof value == 'undefined') value = '';
85 JSAN.use('util.error'); var error = new util.error();
86 error.sdump('D_WARN','map_row_to_column: ' + E);
93 JSAN.use('util.date');
94 var today = new Date();
95 var todayPlus = new Date(); todayPlus.setTime( today.getTime() + 24*60*60*1000*14 );
96 todayPlus = util.date.formatted_date(todayPlus,"%F");
98 $('duedate').setAttribute('value',todayPlus);
99 $('duedate').addEventListener('change',check_date,false);
101 $('p_barcode').addEventListener('keypress',handle_keypress,false);
102 $('p_barcode').focus();
104 $('i_barcode').addEventListener('keypress',handle_keypress,false);
105 $('enter').addEventListener('command',handle_enter,false);
107 $('duedate_menu').addEventListener('command',handle_duedate_menu,false);
109 $('submit').addEventListener('command',function(ev){
110 save_xacts(); next_patron(); /* kludge */ ev.target.focus(); next_patron();
112 $('cancel').addEventListener('command',function(ev){
113 next_patron(); /* kludge */ ev.target.focus(); next_patron();
116 var file; var list_data; var ml;
118 file = new util.file('offline_cnct_list');
119 if (file._file.exists()) {
120 list_data = file.get_object(); file.close();
121 ml = util.widgets.make_menulist(
122 [ ['or choose a non-barcoded option...', ''] ].concat(list_data[0]),
125 ml.setAttribute('id','noncat_type_menu'); $('x_noncat_type').appendChild(ml);
129 var count = window.prompt('Enter the number of items:',1,ml.getAttribute('label'));
130 append_to_list('noncat',count);
136 alert('WARNING: The non-barcode types have not been downloaded from the server. You should log in to retrieve these.');
139 var file = new util.file('offline_delta');
140 if (file._file.exists()) { g.delta = file.get_object(); file.close(); } else { g.delta = 0; }
143 var err_msg = "!! This software has encountered an error. Please tell your friendly " +
144 "system administrator or software developer the following:\ncirc/offline_checkout.xul\n" + E + '\n';
145 try { g.error.sdump('D_ERROR',err_msg); } catch(E) { dump(err_msg); }
150 function $(id) { return document.getElementById(id); }
152 function check_date(ev) {
153 JSAN.use('util.date');
155 if (! util.date.check('YYYY-MM-DD',ev.target.value) ) { throw('Invalid Date'); }
156 if (util.date.check_past('YYYY-MM-DD',ev.target.value) ) { throw('Due date needs to be after today.'); }
157 if ( util.date.formatted_date(new Date(),'%F') == ev.target.value) { throw('Due date needs to be after today.'); }
160 var today = new Date();
161 var todayPlus = new Date(); todayPlus.setTime( today.getTime() + 24*60*60*1000*14 );
162 todayPlus = util.date.formatted_date(todayPlus,"%F");
163 ev.target.value = todayPlus;
167 function handle_keypress(ev) {
168 if ( (! ev.keyCode) || (ev.keyCode != 13) ) return;
170 case $('p_barcode') : $('p_barcode').disabled = true; $('i_barcode').focus(); break;
171 case $('i_barcode') : append_to_list('barcode'); break;
176 function handle_enter(ev) {
177 append_to_list('barcode');
180 function handle_duedate_menu(ev) {
181 if (ev.target.value=='0') return;
182 JSAN.use('util.date');
183 var today = new Date();
184 var todayPlus = new Date();
185 todayPlus.setTime( today.getTime() + 24*60*60*1000*ev.target.value );
186 todayPlus = util.date.formatted_date(todayPlus,'%F');
187 $('duedate').setAttribute('value',todayPlus);
188 $('duedate').value = todayPlus;
191 function append_to_list(checkout_type,count) {
197 my.type = 'checkout';
198 my.timestamp = parseInt( new Date().getTime() / 1000);
199 my.checkout_time = util.date.formatted_date(new Date(),"%F %H:%M:%s");
201 var p_barcode = $('p_barcode').value;
203 alert('Please enter a patron barcode first.');
207 // Need to validate patron barcode against bad patron list
208 my.patron_barcode = p_barcode;
211 var due_date = $('duedate').value; // Need to validate this
212 my.due_date = due_date;
214 var i_barcode = $('i_barcode').value;
215 switch(checkout_type) {
217 if (! i_barcode) return;
219 var rows = g.list.dump_with_keys();
220 for (var i = 0; i < rows.length; i++) {
221 if (rows[i].barcode == i_barcode) {
222 alert('This barcode has already been scanned.');
227 my.barcode = i_barcode;
230 count = parseInt(count); if (! (count>0) ) {
231 alert("Please try again and enter a valid count.");
234 my.barcode = $('noncat_type_menu').getAttribute('label');
236 my.noncat_type = JSON2js($('noncat_type_menu').value)[0];
237 my.noncat_count = count;
239 default: alert("Please report that this happened."); break;
242 g.list.append( { 'row' : { 'my' : my } } );
244 var x = $('i_barcode'); x.value = ''; x.focus();
248 dump(E+'\n'); alert(E);
254 function save_xacts() {
255 JSAN.use('util.file'); var file = new util.file('pending_xacts');
256 var rows = g.list.dump_with_keys();
257 for (var i = 0; i < rows.length; i++) {
258 var row = rows[i]; row.delta = g.delta;
259 if (row.noncat == 1) {
263 delete(row.noncat_type);
264 delete(row.noncat_count);
266 file.append_object(row);
271 function next_patron() {
276 x = $('i_barcode'); x.value = '';
277 x = $('p_barcode'); x.value = '';
278 x.setAttribute('disabled','false'); x.disabled = false;
282 dump(E+'\n'); alert(E);