1 var G = {}; // the master Global variable
3 var debug_ignore_auth_failures = false;
5 G['main_window'] = self;
7 G['appshell_list'] = [];
9 G['window_name_increment'] = 0;
10 G['appshell_name_increment'] = 0;
13 G['main_test_variable'] = 'Hello World';
16 G['my_orgs_hash'] = {};
20 G['ap_list'] = []; // actor::profile
22 G['cit_list'] = []; // config::identification_type
24 G['cst_list'] = []; // config::standing
26 G['acpl_list'] = []; // asset::copy_location
27 G['acpl_hash'] = {}; G['acpl_my_orgs'] = []; G['acpl_my_orgs_hash'] = {};
28 G['aout_list'] = []; // actor::org_unit_type
30 G['ccs_list'] = []; // config::copy_status
32 G['asc_list'] = []; // asset::stat_cat
33 G['actsc_list'] = []; // actor::stat_cat
34 G['actsc_hash']; // actor::stat_cat
36 G['itemsout_header'] = 'Welcome %PATRON_FIRSTNAME%, to %LIBRARY%!\r\nYou have the following items:<hr/><ol>';
37 G['itemsout_line_item'] = '<li>%TITLE: 50%\r\nBarcode: %COPY_BARCODE% Due: %DUE_D%\r\n';
38 G['itemsout_footer'] = '</ol><hr />%PINES_CODE% %TODAY%\r\nYou were helped by %STAFF_FIRSTNAME% %STAFF_LASTNAME%';
40 G['checkout_header'] = 'Welcome %PATRON_FIRSTNAME%, to %LIBRARY%!\r\nYou checked out the following items:<hr/><ol>';
41 G['checkout_line_item'] = '<li>%TITLE%\r\nBarcode: %COPY_BARCODE% Due: %DUE_D%\r\n';
42 G['checkout_footer'] = '</ol><hr />%PINES_CODE% %TODAY%\r\nYou were helped by %STAFF_FIRSTNAME% %STAFF_LASTNAME%';
44 var mw = G['main_window'];
45 var auth_meter_incr = 10;
47 function auth_init() {
48 sdump('D_AUTH','TESTING: auth.js: ' + mw.G['main_test_variable'] + '\n');
49 sdump('D_AUTH',arg_dump(arguments));
51 var np = document.getElementById('name_prompt');
53 np.addEventListener("keypress",handle_keypress,false);
57 var pp = document.getElementById('password_prompt');
59 pp.addEventListener("keypress",handle_keypress,false);
61 self.addEventListener("unload",nice_shutdown,false);
63 G['sound'] = xp_sound_init();
71 function handle_keypress(ev) {
72 if (ev.keyCode && ev.keyCode == 13) {
74 case document.getElementById('name_prompt') :
76 var pp = document.getElementById('password_prompt');
77 pp.focus(); pp.select();
79 case document.getElementById('password_prompt') :
81 var sb = document.getElementById('submit_button');
91 function disable_login_prompts() {
92 sdump('D_AUTH',arg_dump(arguments));
93 disable_widgets(document,'password_prompt','name_prompt','submit_button');
97 function enable_login_prompts() {
98 sdump('D_AUTH',arg_dump(arguments));
99 enable_widgets(document,'password_prompt','name_prompt','submit_button');
100 document.getElementById('password_prompt').value = '';
101 var np = document.getElementById('name_prompt');
102 np.focus(); np.select();
103 document.getElementById('auth_meter').value = 0;
104 document.getElementById('auth_meter').setAttribute('real', '0.0');
108 function authenticate() {
109 sdump('D_AUTH',arg_dump(arguments));
111 var name = document.getElementById('name_prompt').value;
112 if (name.length == 0) { enable_login_prompts(); return; }
113 // Talk to the system and authenticate the user.
116 'open-ils.auth.authenticate.init',
122 function auth_init_callback(request) {
123 sdump('D_AUTH',arg_dump(arguments));
126 auth_init = request.getResultObject();
127 if (!auth_init) { throw('null result'); }
129 alert('Login failed on auth_init: ' + js2JSON(E));
130 if (!debug_ignore_auth_failures) {
131 enable_login_prompts(); return;
135 sdump( 'D_AUTH', 'D_AUTH_INIT: ' + typeof(auth_init) + ' : ' + auth_init + '\n');
136 var name = document.getElementById('name_prompt').value;
137 var pw = document.getElementById('password_prompt').value;
141 'open-ils.auth.authenticate.complete',
142 [ name, hex_md5(auth_init + hex_md5(pw)) ],
145 incr_progressmeter(document,'auth_meter',auth_meter_incr);
148 function auth_ses_callback(request) {
149 sdump('D_AUTH',arg_dump(arguments));
152 auth_ses = request.getResultObject();
153 if (!auth_ses) { throw('null result'); }
154 if (auth_ses == 0) { throw('0 result'); }
156 alert('Login failed on auth_ses: ' + js2JSON(E));
157 if (!debug_ignore_auth_failures) {
158 enable_login_prompts(); return;
161 mw.G.auth_ses = [ auth_ses ];
162 sdump( 'D_AUTH', 'D_AUTH_SES: ' + typeof(mw.G['auth_ses'][0]) + ' : ' + mw.G['auth_ses'][0] + '\n');
164 //'open-ils.actor.user.profiles.retrieve',
167 'open-ils.actor.groups.retrieve',
171 incr_progressmeter(document,'auth_meter',auth_meter_incr);
174 function ap_list_callback(request) {
175 sdump('D_AUTH',arg_dump(arguments));
178 ap_list = request.getResultObject();
179 if (!ap_list) { throw('null result'); }
180 if (ap_list.length == 0) { throw('zero length result'); }
182 alert('Login failed on ap_list: ' + js2JSON(E));
183 if (!debug_ignore_auth_failures) {
184 enable_login_prompts(); return;
187 mw.G.ap_list = ap_list;
188 mw.G.ap_hash = convert_object_list_to_hash( ap_list );
192 'open-ils.actor.user.ident_types.retrieve',
196 incr_progressmeter(document,'auth_meter',auth_meter_incr);
199 function cit_list_callback(request) {
200 sdump('D_AUTH',arg_dump(arguments));
203 cit_list = request.getResultObject();
204 if (!cit_list) { throw('null result'); }
205 if (cit_list.length == 0) { throw('zero length result'); }
207 alert('Login failed on cit_list: ' + js2JSON(E));
208 if (!debug_ignore_auth_failures) {
209 enable_login_prompts(); return;
212 mw.G.cit_list = cit_list;
213 mw.G.cit_hash = convert_object_list_to_hash( cit_list );
217 'open-ils.actor.standings.retrieve',
222 incr_progressmeter(document,'auth_meter',auth_meter_incr);
225 function cst_list_callback(request) {
226 sdump('D_AUTH',arg_dump(arguments));
229 cst_list = request.getResultObject();
230 if (!cst_list) { throw('null result'); }
231 if (cst_list.length == 0) { throw('zero length result'); }
233 alert('Login failed on cst_list: ' + js2JSON(E));
234 if (!debug_ignore_auth_failures) {
235 enable_login_prompts(); return;
238 mw.G.cst_list = cst_list;
239 mw.G.cst_hash = convert_object_list_to_hash( cst_list );
240 sdump('D_AUTH', 'cst_list = ' + js2JSON(cst_list) + '\n');
244 'open-ils.search.config.copy_location.retrieve.all',
248 incr_progressmeter(document,'auth_meter',auth_meter_incr);
252 function acpl_list_callback(request) {
253 sdump('D_AUTH',arg_dump(arguments));
256 acpl_list = request.getResultObject();
257 if (!acpl_list) { throw('null result'); }
258 if (acpl_list.length == 0) { throw('zero length result'); }
260 alert('Login failed on acpl_list: ' + js2JSON(E));
261 if (!debug_ignore_auth_failures) {
262 enable_login_prompts(); return;
265 mw.G.acpl_list = acpl_list;
266 mw.G.acpl_hash = convert_object_list_to_hash( acpl_list );
267 sdump('D_AUTH', 'acpl_list = ' + js2JSON(acpl_list) + '\n');
271 'open-ils.search.config.copy_status.retrieve.all',
275 incr_progressmeter(document,'auth_meter',auth_meter_incr);
278 function ccs_list_callback(request) {
279 sdump('D_AUTH',arg_dump(arguments));
282 ccs_list = request.getResultObject();
283 if (!ccs_list) { throw('null result'); }
284 if (ccs_list.length == 0) { throw('zero length result'); }
286 alert('Login failed on ccs_list: ' + js2JSON(E));
287 if (!debug_ignore_auth_failures) {
288 enable_login_prompts(); return;
291 mw.G.ccs_list = ccs_list;
292 mw.G.ccs_hash = convert_object_list_to_hash( ccs_list );
293 sdump('D_AUTH', 'ccs_list = ' + js2JSON(ccs_list) + '\n');
297 'open-ils.search.actor.user.session',
298 [ mw.G['auth_ses'][0] ],
301 incr_progressmeter(document,'auth_meter',auth_meter_incr);
304 function user_callback(request) {
305 sdump('D_AUTH',arg_dump(arguments));
309 user = request.getResultObject();
310 if (!user) { throw('null result'); }
311 if (typeof(user) != 'object') { throw('result not an object' + user); }
313 alert('Login failed on user: ' + js2JSON(E));
314 if (!debug_ignore_auth_failures) {
315 enable_login_prompts(); return;
319 mw.G.user_ou = user.home_ou();
320 sdump('D_AUTH', "user: " + js2JSON(mw.G['user']) + '\n');
321 sdump('D_AUTH', "user_ou: " + js2JSON(mw.G['user_ou']) + '\n');
322 /*user_async_request(
324 'open-ils.search.actor.org_tree.retrieve',
328 /*user_async_request(
330 'open-ils.actor.org_types.retrieve',
331 [ mw.G.auth_ses[0] ],
335 incr_progressmeter(document,'auth_meter',auth_meter_incr);
338 function org_type_callback(request) {
339 sdump('D_AUTH',arg_dump(arguments));
340 var aout_list = globalOrgTypes;
342 aout_list = request.getResultObject();
343 if (!aout_list) { throw('null result'); }
344 if (typeof(aout_list) != 'object') { throw('result not an object' + aout_list); }
345 if (aout_list.length == 0) { throw('empty aout_list'); }
347 alert('Login failed on aout_list: ' + js2JSON(E)); enable_login_prompts(); return;
349 mw.G.aout_list = aout_list;
351 mw.G.aout_hash = convert_object_list_to_hash( aout_list );
353 mw.G.org_tree = globalOrgTree;
355 mw.G.org_tree_hash = convert_object_list_to_hash( flatten_ou_branch( globalOrgTree ) );
357 mw.G.user_ou = find_ou( mw.G.org_tree, mw.G.user_ou );
362 'open-ils.actor.org_unit.full_path.retrieve',
363 [ mw.G.auth_ses[0] ],
366 incr_progressmeter(document,'auth_meter',auth_meter_incr);
370 function my_orgs_callback(request) {
371 sdump('D_AUTH',arg_dump(arguments));
374 my_orgs = request.getResultObject();
375 if (!my_orgs) { throw('null result'); }
376 if (typeof(my_orgs) != 'object') { throw('result not an object' + my_orgs); }
377 if (my_orgs.length == 0) { throw('empty my_orgs'); }
379 alert('Login failed on my_orgs: ' + js2JSON(E));
380 if (!debug_ignore_auth_failures) {
381 enable_login_prompts(); return;
385 mw.G.my_orgs = my_orgs;
386 mw.G.my_orgs_hash = convert_object_list_to_hash( my_orgs );
387 sdump('D_AUTH','my_orgs = ' + js2JSON(my_orgs) + '\n');
388 mw.G.acpl_my_orgs = filter_list(
391 if ( typeof obj != 'object' ) return null;
392 if ( mw.G.my_orgs_hash[ obj.owning_lib() ] ) return obj;
395 mw.G.acpl_my_orgs_hash = convert_object_list_to_hash( mw.G.acpl_my_orgs );
396 //sdump('D_AUTH', 'my_orgs.length = ' + mw.G.my_orgs.length + ' other_orgs.length = ' + mw.G.other_orgs.length + '\n');
400 'open-ils.circ.stat_cat.actor.retrieve.all',
401 [ mw.G.auth_ses[0], mw.G.user_ou.id() ],
402 my_actsc_list_callback
405 incr_progressmeter(document,'auth_meter',auth_meter_incr);
408 function my_actsc_list_callback(request) {
409 sdump('D_AUTH',arg_dump(arguments));
412 actsc_list = request.getResultObject();
413 if (!actsc_list) { throw('null result'); }
414 //if (actsc_list.length == 0) { throw('zero length result'); }
416 alert('Login failed on actsc_list: ' + js2JSON(E));
417 if (!debug_ignore_auth_failures) {
418 enable_login_prompts(); return;
421 mw.G.actsc_list = actsc_list;
422 mw.G.actsc_hash = convert_object_list_to_hash( actsc_list );
423 sdump('D_AUTH', 'actsc_list = ' + js2JSON(actsc_list) + '\n');
425 incr_progressmeter(document,'auth_meter',auth_meter_incr);
435 sdump('D_AUTH',arg_dump(arguments));
436 mw.G['auth_ses'] = '';
438 enable_login_prompts();
439 incr_progressmeter(document,'auth_meter',-100);
443 function nice_shutdown() {
444 sdump('D_AUTH',arg_dump(arguments));
445 if (ses) { logoff(); ses.disconnect(); }