1 var G = {}; // the master Global variable
3 var debug_ignore_auth_failures = false;
6 G['main_window'] = self;
8 G['appshell_list'] = [];
10 G['window_name_increment'] = 0;
11 G['appshell_name_increment'] = 0;
14 G['main_test_variable'] = 'Hello World';
17 G['my_orgs_hash'] = {};
21 G['ap_list'] = []; // actor::profile
23 G['cit_list'] = []; // config::identification_type
25 G['cst_list'] = []; // config::standing
27 G['acpl_list'] = []; // asset::copy_location
28 G['acpl_hash'] = {}; G['acpl_my_orgs'] = []; G['acpl_my_orgs_hash'] = {};
29 G['aout_list'] = []; // actor::org_unit_type
31 G['ccs_list'] = []; // config::copy_status
33 G['asc_list'] = []; // asset::stat_cat
34 G['actsc_list'] = []; // actor::stat_cat
35 G['actsc_hash']; // actor::stat_cat
37 G['itemsout_header'] = 'Welcome %PATRON_FIRSTNAME%, to %LIBRARY%!\r\nYou have the following items:<hr/><ol>';
38 G['itemsout_line_item'] = '<li>%TITLE: 50%\r\nBarcode: %COPY_BARCODE% Due: %DUE_D%\r\n';
39 G['itemsout_footer'] = '</ol><hr />%PINES_CODE% %TODAY%\r\nYou were helped by %STAFF_FIRSTNAME% %STAFF_LASTNAME%';
41 G['checkout_header'] = 'Welcome %PATRON_FIRSTNAME%, to %LIBRARY%!\r\nYou checked out the following items:<hr/><ol>';
42 G['checkout_line_item'] = '<li>%TITLE%\r\nBarcode: %COPY_BARCODE% Due: %DUE_D%\r\n';
43 G['checkout_footer'] = '</ol><hr />%PINES_CODE% %TODAY%\r\nYou were helped by %STAFF_FIRSTNAME% %STAFF_LASTNAME%';
45 var mw = G['main_window'];
46 var auth_meter_incr = 10;
48 function auth_init() {
49 sdump('D_AUTH','TESTING: auth.js: ' + mw.G['main_test_variable'] + '\n');
50 sdump('D_AUTH',arg_dump(arguments));
51 var np = document.getElementById('name_prompt');
52 np.addEventListener("keypress",handle_keypress,false);
54 var pp = document.getElementById('password_prompt');
55 pp.addEventListener("keypress",handle_keypress,false);
56 self.addEventListener("unload",nice_shutdown,false);
57 G['sound'] = xp_sound_init();
62 function handle_keypress(ev) {
63 if (ev.keyCode && ev.keyCode == 13) {
65 case document.getElementById('name_prompt') :
67 var pp = document.getElementById('password_prompt');
68 pp.focus(); pp.select();
70 case document.getElementById('password_prompt') :
72 var sb = document.getElementById('submit_button');
82 function disable_login_prompts() {
83 sdump('D_AUTH',arg_dump(arguments));
84 disable_widgets(document,'password_prompt','name_prompt','submit_button');
88 function enable_login_prompts() {
89 sdump('D_AUTH',arg_dump(arguments));
90 enable_widgets(document,'password_prompt','name_prompt','submit_button');
91 document.getElementById('password_prompt').value = '';
92 var np = document.getElementById('name_prompt');
93 np.focus(); np.select();
94 document.getElementById('auth_meter').value = 0;
95 document.getElementById('auth_meter').setAttribute('real', '0.0');
99 function authenticate() {
100 sdump('D_AUTH',arg_dump(arguments));
102 var name = document.getElementById('name_prompt').value;
103 if (name.length == 0) { enable_login_prompts(); return; }
104 // Talk to the system and authenticate the user.
107 'open-ils.auth.authenticate.init',
113 function auth_init_callback(request) {
114 sdump('D_AUTH',arg_dump(arguments));
117 auth_init = request.getResultObject();
118 if (!auth_init) { throw('null result'); }
121 sdump('D_ERROR','Error trying to communicate with the server. Entering OFFLINE mode.\n');
122 s_alert('Error trying to communicate with the server. Entering OFFLINE mode.\n');
125 sdump( 'D_AUTH', 'D_AUTH_INIT: ' + typeof(auth_init) + ' : ' + auth_init + '\n');
126 var name = document.getElementById('name_prompt').value;
127 var pw = document.getElementById('password_prompt').value;
128 G.name = name; G.pw = pw;
132 'open-ils.auth.authenticate.complete',
133 [ name, hex_md5(auth_init + hex_md5(pw)) ],
136 incr_progressmeter(document,'auth_meter',auth_meter_incr);
139 function auth_ses_callback(request) {
140 sdump('D_AUTH',arg_dump(arguments));
143 auth_ses = request.getResultObject();
144 if (!auth_ses) { if (!G.offline) { throw('null result'); } }
145 if (auth_ses == 0) { throw('0 result'); }
146 if (instanceOf(auth_ses,ex)) {
147 throw(auth_ses.err_msg());
150 alert('Login failed on auth_ses: ' + js2JSON(E));
151 if (!debug_ignore_auth_failures) {
152 enable_login_prompts(); return;
155 mw.G.auth_ses = [ auth_ses ];
156 sdump( 'D_AUTH', 'D_AUTH_SES: ' + typeof(mw.G['auth_ses'][0]) + ' : ' + mw.G['auth_ses'][0] + '\n');
158 //'open-ils.actor.user.profiles.retrieve',
161 'open-ils.actor.groups.retrieve',
165 incr_progressmeter(document,'auth_meter',auth_meter_incr);
168 function ap_list_callback(request) {
169 sdump('D_AUTH',arg_dump(arguments));
172 ap_list = request.getResultObject();
175 throw('null result');
177 var f = create_input_stream('ap_list');
178 ap_list = JSON2js( f.read(-1) ); f.close();
181 if (ap_list.length == 0) { throw('zero length result'); }
183 alert('Login failed on ap_list: ' + js2JSON(E));
184 if (!debug_ignore_auth_failures) {
185 enable_login_prompts(); return;
188 var f = create_output_stream('ap_list');
189 var ap_list_json = js2JSON( ap_list );
190 f.write( ap_list_json, ap_list_json.length ); f.close();
191 mw.G.ap_list = ap_list;
192 mw.G.ap_hash = convert_object_list_to_hash( ap_list );
196 'open-ils.actor.user.ident_types.retrieve',
200 incr_progressmeter(document,'auth_meter',auth_meter_incr);
203 function cit_list_callback(request) {
204 sdump('D_AUTH',arg_dump(arguments));
207 cit_list = request.getResultObject();
208 if (!cit_list) { throw('null result'); }
209 if (cit_list.length == 0) { throw('zero length result'); }
211 alert('Login failed on cit_list: ' + js2JSON(E));
212 if (!debug_ignore_auth_failures) {
213 enable_login_prompts(); return;
216 mw.G.cit_list = cit_list;
217 mw.G.cit_hash = convert_object_list_to_hash( cit_list );
221 'open-ils.actor.standings.retrieve',
226 incr_progressmeter(document,'auth_meter',auth_meter_incr);
229 function cst_list_callback(request) {
230 sdump('D_AUTH',arg_dump(arguments));
233 cst_list = request.getResultObject();
234 if (!cst_list) { throw('null result'); }
235 if (cst_list.length == 0) { throw('zero length result'); }
237 alert('Login failed on cst_list: ' + js2JSON(E));
238 if (!debug_ignore_auth_failures) {
239 enable_login_prompts(); return;
242 mw.G.cst_list = cst_list;
243 mw.G.cst_hash = convert_object_list_to_hash( cst_list );
244 sdump('D_AUTH', 'cst_list = ' + js2JSON(cst_list) + '\n');
248 'open-ils.search.config.copy_location.retrieve.all',
252 incr_progressmeter(document,'auth_meter',auth_meter_incr);
256 function acpl_list_callback(request) {
257 sdump('D_AUTH',arg_dump(arguments));
260 acpl_list = request.getResultObject();
261 if (!acpl_list) { throw('null result'); }
262 if (acpl_list.length == 0) { throw('zero length result'); }
264 alert('Login failed on acpl_list: ' + js2JSON(E));
265 if (!debug_ignore_auth_failures) {
266 enable_login_prompts(); return;
269 mw.G.acpl_list = acpl_list;
270 mw.G.acpl_hash = convert_object_list_to_hash( acpl_list );
271 sdump('D_AUTH', 'acpl_list = ' + js2JSON(acpl_list) + '\n');
275 'open-ils.search.config.copy_status.retrieve.all',
279 incr_progressmeter(document,'auth_meter',auth_meter_incr);
282 function ccs_list_callback(request) {
283 sdump('D_AUTH',arg_dump(arguments));
286 ccs_list = request.getResultObject();
287 if (!ccs_list) { throw('null result'); }
288 if (ccs_list.length == 0) { throw('zero length result'); }
290 alert('Login failed on ccs_list: ' + js2JSON(E));
291 if (!debug_ignore_auth_failures) {
292 enable_login_prompts(); return;
295 mw.G.ccs_list = ccs_list;
296 mw.G.ccs_hash = convert_object_list_to_hash( ccs_list );
297 sdump('D_AUTH', 'ccs_list = ' + js2JSON(ccs_list) + '\n');
301 'open-ils.search.actor.user.session',
302 [ mw.G['auth_ses'][0] ],
305 incr_progressmeter(document,'auth_meter',auth_meter_incr);
308 function user_callback(request) {
309 sdump('D_AUTH',arg_dump(arguments));
313 user = request.getResultObject();
314 if (!user) { throw('null result'); }
315 if (typeof(user) != 'object') { throw('result not an object' + user); }
317 alert('Login failed on user: ' + js2JSON(E));
318 if (!debug_ignore_auth_failures) {
319 enable_login_prompts(); return;
323 mw.G.user_ou = user.home_ou();
324 sdump('D_AUTH', "user: " + js2JSON(mw.G['user']) + '\n');
325 sdump('D_AUTH', "user_ou: " + js2JSON(mw.G['user_ou']) + '\n');
328 'open-ils.actor.org_tree.retrieve',
332 incr_progressmeter(document,'auth_meter',auth_meter_incr);
335 function org_tree_callback(request) {
338 org_tree = request.getResultObject();
339 if (!org_tree) { throw('null result'); }
340 if (typeof(org_tree) != 'object') { throw('result not an object' + org_tree); }
342 alert('Login failed on org_tree: ' + js2JSON(E)); enable_login_prompts(); return;
345 //mw.G.org_tree = globalOrgTree;
346 mw.G.org_tree = org_tree;
347 mw.G.org_tree_hash = convert_object_list_to_hash( flatten_ou_branch( mw.G.org_tree ) );
348 mw.G.user_ou = find_ou( mw.G.org_tree, mw.G.user_ou );
350 /*user_async_request(
352 'open-ils.actor.org_types.retrieve',
353 [ mw.G.auth_ses[0] ],
359 function org_type_callback(request) {
360 sdump('D_AUTH',arg_dump(arguments));
361 var aout_list = globalOrgTypes;
363 aout_list = request.getResultObject();
364 if (!aout_list) { throw('null result'); }
365 if (typeof(aout_list) != 'object') { throw('result not an object' + aout_list); }
366 if (aout_list.length == 0) { throw('empty aout_list'); }
368 alert('Login failed on aout_list: ' + js2JSON(E)); enable_login_prompts(); return;
370 mw.G.aout_list = aout_list;
371 mw.G.aout_hash = convert_object_list_to_hash( aout_list );
375 'open-ils.actor.org_unit.full_path.retrieve',
376 [ mw.G.auth_ses[0] ],
379 incr_progressmeter(document,'auth_meter',auth_meter_incr);
382 function my_orgs_callback(request) {
383 sdump('D_AUTH',arg_dump(arguments));
386 my_orgs = request.getResultObject();
387 if (!my_orgs) { throw('null result'); }
388 if (typeof(my_orgs) != 'object') { throw('result not an object' + my_orgs); }
389 if (my_orgs.length == 0) { throw('empty my_orgs'); }
391 alert('Login failed on my_orgs: ' + js2JSON(E));
392 if (!debug_ignore_auth_failures) {
393 enable_login_prompts(); return;
397 mw.G.my_orgs = my_orgs;
398 mw.G.my_orgs_hash = convert_object_list_to_hash( my_orgs );
399 sdump('D_AUTH','my_orgs = ' + js2JSON(my_orgs) + '\n');
400 mw.G.acpl_my_orgs = filter_list(
403 if ( typeof obj != 'object' ) return null;
404 if ( mw.G.my_orgs_hash[ obj.owning_lib() ] ) return obj;
407 mw.G.acpl_my_orgs_hash = convert_object_list_to_hash( mw.G.acpl_my_orgs );
408 //sdump('D_AUTH', 'my_orgs.length = ' + mw.G.my_orgs.length + ' other_orgs.length = ' + mw.G.other_orgs.length + '\n');
412 'open-ils.circ.stat_cat.actor.retrieve.all',
413 [ mw.G.auth_ses[0], mw.G.user_ou.id() ],
414 my_actsc_list_callback
417 incr_progressmeter(document,'auth_meter',auth_meter_incr);
420 function my_actsc_list_callback(request) {
421 sdump('D_AUTH',arg_dump(arguments));
424 actsc_list = request.getResultObject();
425 if (!actsc_list) { throw('null result'); }
426 //if (actsc_list.length == 0) { throw('zero length result'); }
428 alert('Login failed on actsc_list: ' + js2JSON(E));
429 if (!debug_ignore_auth_failures) {
430 enable_login_prompts(); return;
433 mw.G.actsc_list = actsc_list;
434 mw.G.actsc_hash = convert_object_list_to_hash( actsc_list );
435 sdump('D_AUTH', 'actsc_list = ' + js2JSON(actsc_list) + '\n');
437 incr_progressmeter(document,'auth_meter',auth_meter_incr);
447 sdump('D_AUTH',arg_dump(arguments));
448 mw.G['auth_ses'] = '';
450 enable_login_prompts();
451 incr_progressmeter(document,'auth_meter',-100);
455 function nice_shutdown() {
456 sdump('D_AUTH',arg_dump(arguments));
457 if (ses) { logoff(); ses.disconnect(); }