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_register.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 $('barcode').addEventListener('keypress',handle_keypress,false);
15 $('submit').addEventListener('command',next_patron,false);
17 JSAN.use('util.file');
18 JSAN.use('util.widgets');
20 var file; var list_data; var ml; var errors = '';
22 file = new util.file('offline_ou_list');
23 if (file._file.exists()) {
24 list_data = file.get_object(); file.close();
25 ml = util.widgets.make_menulist( list_data[0], list_data[1] );
26 ml.setAttribute('id','home_ou'); $('x_home_ou').appendChild(ml);
28 errors += 'Missing library list.\n';
31 file = new util.file('offline_pgt_list');
32 if (file._file.exists()) {
33 list_data = file.get_object(); file.close();
34 ml = util.widgets.make_menulist( list_data[0], list_data[1] );
35 ml.setAttribute('id','profile'); $('x_profile').appendChild(ml);
37 errors += 'Missing profile list.\n';
40 file = new util.file('offline_cit_list');
41 if (file._file.exists()) {
42 list_data = file.get_object(); file.close();
43 ml = util.widgets.make_menulist( list_data[0], list_data[1] );
44 ml.setAttribute('id','ident_type'); $('x_ident_type').appendChild(ml);
46 errors += 'Missing identification type list.\n';
49 file = new util.file('offline_asv_list');
50 if (file._file.exists()) {
51 list_data = file.get_object(); file.close();
52 render_surveys('x_surveys', list_data);
54 errors += 'Missing required surveys.\n';
58 alert('ERROR: Offline patron registration requires some server-generated files. Please login periodically to retrieve these files.\n' + errors);
59 location.href = 'about:blank';
62 $('passwd').value = parseInt(Math.random()*8999+1000);
64 $('dob').addEventListener('change',handle_check_date,false);
67 var file = new util.file('offline_delta');
68 if (file._file.exists()) { g.delta = file.get_object(); file.close(); } else { g.delta = 0; }
71 var err_msg = "!! This software has encountered an error. Please tell your friendly " +
72 "system administrator or software developer the following:\ncirc/offline_register.xul\n" + E + '\n';
73 try { g.error.sdump('D_ERROR',err_msg); } catch(E) { dump(err_msg); }
78 function $(id) { return document.getElementById(id); }
80 function handle_check_date(ev) {
81 ev.target.value = check_date(ev.target.value);
84 function check_date(value) {
85 JSAN.use('util.date');
87 if (! util.date.check('YYYY-MM-DD',value) ) { throw('Invalid Date'); }
88 if (! util.date.check_past('YYYY-MM-DD',value) ) { throw('Patron needs to be born yesterday.'); }
89 if ( util.date.formatted_date(new Date(),'%F') == value) { throw('Happy birthday! You need to be more than 0 days old.'); }
97 function render_surveys(node,obj) {
98 node = util.widgets.get(node);
99 util.widgets.remove_children(node);
103 var x_gb = document.createElement('groupbox'); node.appendChild(x_gb);
104 var x_cp = document.createElement('caption');
105 x_cp.setAttribute('label',i); x_gb.appendChild(x_cp);
106 var x_d = document.createElement('description');
107 x_d.appendChild( document.createTextNode( survey.description ) ); x_gb.appendChild(x_d);
108 for (var j = 0; j < survey.questions.length; j++) {
109 var question = survey.questions[j];
110 var x_d = document.createElement('description');
111 x_d.appendChild( document.createTextNode( (j+1) + ') ' + question.question ) );
112 x_gb.appendChild( x_d );
113 var x_hb = document.createElement('hbox'); x_hb.setAttribute('flex','1');
114 x_gb.appendChild(x_hb);
115 var x_spacer = document.createElement('spacer'); x_spacer.setAttribute('flex','1');
116 x_hb.appendChild(x_spacer);
117 var x_ml = util.widgets.make_menulist( [ ['Choose a response...',''] ].concat(question.answers) );
118 x_ml.setAttribute('name','survey'); x_hb.appendChild(x_ml);
123 function handle_keypress(ev) {
124 if ( (! ev.keyCode) || (ev.keyCode != 13) ) return;
126 case $('barcode') : $('family_name').focus(); break;
131 function check_patron(obj) {
133 if (! obj.user.billing_address.post_code ) {
134 errors += 'Missing Address : Postal Code\n';
135 $('post_code').focus();
136 $('post_code').parentNode.setAttribute('style','background-color: red');
138 $('post_code').parentNode.setAttribute('style','');
140 if (! obj.user.billing_address.state ) {
141 errors += 'Missing Address : State\n';
143 $('state').parentNode.setAttribute('style','background-color: red');
145 $('state').parentNode.setAttribute('style','');
147 if (! obj.user.billing_address.city ) {
148 errors += 'Missing Address : City\n';
150 $('city').parentNode.setAttribute('style','background-color: red');
152 $('city').parentNode.setAttribute('style','');
154 if (! obj.user.billing_address.street1 ) {
155 errors += 'Missing Address : Line 1\n';
156 $('street1').focus();
157 $('street1').parentNode.setAttribute('style','background-color: red');
159 $('street1').parentNode.setAttribute('style','');
161 if (! obj.user.ident_value ) {
162 errors += 'Missing Identification Value\n';
163 $('ident_value').focus();
164 $('ident_value').parentNode.setAttribute('style','background-color: red');
166 $('ident_value').parentNode.setAttribute('style','');
168 if (! obj.user.ident_type ) {
169 errors += 'Missing Identification Type\n';
170 $('ident_type').focus();
171 $('ident_type').parentNode.setAttribute('style','background-color: red');
173 $('ident_type').parentNode.setAttribute('style','');
175 if (! obj.user.dob ) {
176 errors += 'Missing Date of Birth\n';
178 $('dob').parentNode.parentNode.setAttribute('style','background-color: red');
180 $('dob').parentNode.parentNode.setAttribute('style','');
182 if (! obj.user.first_given_name ) {
183 errors += 'Missing First Name\n';
184 $('first_given_name').focus();
185 $('first_given_name').parentNode.setAttribute('style','background-color: red');
187 $('first_given_name').parentNode.setAttribute('style','');
189 if (! obj.user.family_name ) {
190 errors += 'Missing Last Name\n';
191 $('family_name').focus();
192 $('family_name').parentNode.setAttribute('style','background-color: red');
194 $('family_name').parentNode.setAttribute('style','');
196 if (! obj.user.passwd ) {
197 errors += 'Missing Password\n';
199 $('passwd').parentNode.setAttribute('style','background-color: red');
201 $('passwd').parentNode.setAttribute('style','');
203 if (! obj.user.card.barcode ) {
204 errors += 'Missing Barcode\n';
205 $('barcode').focus();
206 $('barcode').parentNode.setAttribute('style','background-color: red');
208 $('barcode').parentNode.setAttribute('style','');
210 if (! obj.user.profile ) {
211 errors += 'Missing Profile\n';
212 $('profile').focus();
213 $('profile').parentNode.setAttribute('style','background-color: red');
215 $('profile').parentNode.setAttribute('style','');
217 if (! obj.user.home_ou ) {
218 errors += 'Missing Home Library\n';
219 $('home_ou').focus();
220 $('home_ou').parentNode.setAttribute('style','background-color: red');
222 $('home_ou').parentNode.setAttribute('style','');
224 if (errors != '') throw(errors);
227 function next_patron() {
230 obj.timestamp = parseInt( new Date().getTime() / 1000);
231 obj.type = 'register';
233 obj.user.card = { 'barcode' : $('barcode').value };
234 obj.user.profile = $('profile').value;
235 obj.user.passwd = $('passwd').value;
236 obj.user.ident_type = $('ident_type').value;
237 obj.user.ident_value = $('ident_value').value;
238 obj.user.first_given_name = $('first_given_name').value;
239 obj.user.family_name = $('family_name').value;
240 obj.user.home_ou = $('home_ou').value;
241 obj.user.dob = $('dob').value;
242 obj.user.billing_address = {};
243 obj.user.billing_address.street1 = $('street1').value;
244 obj.user.billing_address.street2 = $('street2').value;
245 obj.user.billing_address.city = $('city').value;
246 obj.user.billing_address.state = $('state').value;
247 obj.user.billing_address.country = $('country').value;
248 obj.user.billing_address.post_code = $('post_code').value;
249 obj.user.survey_responses = [];
251 var nl = document.getElementsByAttribute('name','survey');
252 for (var i = 0; i < nl.length; i++) {
253 var value = nl[i].value; if (value == '') continue;
254 var values = JSON2js( value );
255 var response = { 'survey' : values[2], 'question' : values[1], 'answer' : values[0] };
256 obj.user.survey_responses.push( response );
262 alert('Please fix the following:\n' + E);
266 JSAN.use('util.file'); var file = new util.file('pending_xacts');
268 file.append_object(obj);
271 alert('Patron Registration Saved');
273 $('passwd').value = parseInt(Math.random()*8999+1000);
274 $('barcode').value = ''; $('ident_value').value = ''; $('first_given_name').value = '';
275 $('family_name').value = ''; $('dob').value = ''; $('street1').value = '';
276 $('street2').value = '';
278 file = new util.file('offline_asv_list'); var list_data = file.get_object(); file.close();
279 render_surveys('x_surveys', list_data);
281 $('barcode').focus();
284 dump(E+'\n'); alert(E);