1 // the master Global variable
3 /////////////////////////////////////////////////////////////////////////////////////
5 // pointer to the auth window
8 // list of open window references, used for debugging in shell
11 // list of Top Level menu interface window references
14 // list of documents for debugging. BROKEN
17 // Windows need unique names. This number helps.
18 'window_name_increment' : 0,
20 // This number gets put into the title bar for Top Level menu interface windows
21 'appshell_name_increment' : 0,
23 // I was using this to make sure I could shove references into new windows
24 // correctly. However, it's JSON that tends to behave weirdly when crossing
25 // window boundaries. [ 'a', 'b', 'c' ] could turn into { '1' : 'a', '2' : 'b',
26 'main_test_variable' : 'Hello World',
28 /////////////////////////////////////////////////////////////////////////////////////
30 // Flag for whether the staff client should act as if it were offline or not
33 // Array of Session Keys. This is an array mostly by accident, we usually
34 // only deal with one session. But this could be useful for implementing
35 // overrides with other logins.
38 // Org Unit for the login user
41 /////////////////////////////////////////////////////////////////////////////////////
42 /////////////////////////////////////////////////////////////////////////////////////
45 var debug_ignore_auth_failures = false;
49 G['my_orgs_hash'] = {};
51 G['ap_list'] = []; // actor::profile
53 G['cit_list'] = []; // config::identification_type
55 G['cst_list'] = []; // config::standing
57 G['acpl_list'] = []; // asset::copy_location
58 G['acpl_hash'] = {}; G['acpl_my_orgs'] = []; G['acpl_my_orgs_hash'] = {};
59 G['aout_list'] = []; // actor::org_unit_type
61 G['ccs_list'] = []; // config::copy_status
63 G['asc_list'] = []; // asset::stat_cat
64 G['actsc_list'] = []; // actor::stat_cat
65 G['actsc_hash']; // actor::stat_cat
67 G['itemsout_header'] = 'Welcome %PATRON_FIRSTNAME%, to %LIBRARY%!\r\nYou have the following items:<hr/><ol>';
68 G['itemsout_line_item'] = '<li>%TITLE: 50%\r\nBarcode: %COPY_BARCODE% Due: %DUE_D%\r\n';
69 G['itemsout_footer'] = '</ol><hr />%PINES_CODE% %TODAY%\r\nYou were helped by %STAFF_FIRSTNAME% %STAFF_LASTNAME%';
71 G['checkout_header'] = 'Welcome %PATRON_FIRSTNAME%, to %LIBRARY%!\r\nYou checked out the following items:<hr/><ol>';
72 G['checkout_line_item'] = '<li>%TITLE%\r\nBarcode: %COPY_BARCODE% Due: %DUE_D%\r\n';
73 G['checkout_footer'] = '</ol><hr />%PINES_CODE% %TODAY%\r\nYou were helped by %STAFF_FIRSTNAME% %STAFF_LASTNAME%';
75 var mw = G['main_window'];
76 var auth_meter_incr = 10;
78 function auth_init() {
79 sdump('D_AUTH','TESTING: auth.js: ' + mw.G['main_test_variable'] + '\n');
80 sdump('D_AUTH',arg_dump(arguments));
81 var np = document.getElementById('name_prompt');
82 np.addEventListener("keypress",handle_keypress,false);
84 var pp = document.getElementById('password_prompt');
85 pp.addEventListener("keypress",handle_keypress,false);
86 self.addEventListener("unload",nice_shutdown,false);
87 G['sound'] = xp_sound_init();
92 function handle_keypress(ev) {
93 if (ev.keyCode && ev.keyCode == 13) {
95 case document.getElementById('name_prompt') :
97 var pp = document.getElementById('password_prompt');
98 pp.focus(); pp.select();
100 case document.getElementById('password_prompt') :
102 var sb = document.getElementById('submit_button');
112 function disable_login_prompts() {
113 sdump('D_AUTH',arg_dump(arguments));
114 disable_widgets(document,'password_prompt','name_prompt','submit_button');
118 function enable_login_prompts() {
119 sdump('D_AUTH',arg_dump(arguments));
120 enable_widgets(document,'password_prompt','name_prompt','submit_button');
121 document.getElementById('password_prompt').value = '';
122 var np = document.getElementById('name_prompt');
123 np.focus(); np.select();
124 document.getElementById('auth_meter').value = 0;
125 document.getElementById('auth_meter').setAttribute('real', '0.0');
129 function authenticate() {
130 sdump('D_AUTH',arg_dump(arguments));
132 var name = document.getElementById('name_prompt').value;
133 if (name.length == 0) { enable_login_prompts(); return; }
134 // Talk to the system and authenticate the user.
137 'open-ils.auth.authenticate.init',
143 function auth_init_callback(request) {
144 sdump('D_AUTH',arg_dump(arguments));
147 auth_init = request.getResultObject();
148 if (!auth_init) { throw('null result'); }
151 sdump('D_ERROR','Error trying to communicate with the server. Entering OFFLINE mode.\n');
152 s_alert('Error trying to communicate with the server. Entering OFFLINE mode.\n');
155 sdump( 'D_AUTH', 'D_AUTH_INIT: ' + typeof(auth_init) + ' : ' + auth_init + '\n');
156 var name = document.getElementById('name_prompt').value;
157 var pw = document.getElementById('password_prompt').value;
158 G.name = name; G.pw = pw;
162 'open-ils.auth.authenticate.complete',
163 [ name, hex_md5(auth_init + hex_md5(pw)) ],
166 incr_progressmeter(document,'auth_meter',auth_meter_incr);
169 function auth_ses_callback(request) {
170 sdump('D_AUTH',arg_dump(arguments));
173 auth_ses = request.getResultObject();
174 if (!auth_ses) { if (!G.offline) { throw('null result'); } }
175 if (auth_ses == 0) { throw('0 result'); }
176 if (instanceOf(auth_ses,ex)) {
177 throw(auth_ses.err_msg());
180 alert('Login failed on auth_ses: ' + js2JSON(E));
181 if (!debug_ignore_auth_failures) {
182 enable_login_prompts(); return;
185 mw.G.auth_ses = [ auth_ses ];
186 sdump( 'D_AUTH', 'D_AUTH_SES: ' + typeof(mw.G['auth_ses'][0]) + ' : ' + mw.G['auth_ses'][0] + '\n');
188 //'open-ils.actor.user.profiles.retrieve',
191 'open-ils.actor.groups.retrieve',
195 incr_progressmeter(document,'auth_meter',auth_meter_incr);
198 function ap_list_callback(request) {
199 sdump('D_AUTH',arg_dump(arguments));
202 ap_list = request.getResultObject();
205 throw('null result');
207 var f = create_input_stream('ap_list');
208 ap_list = JSON2js( f.read(-1) ); f.close();
211 if (ap_list.length == 0) { throw('zero length result'); }
213 alert('Login failed on ap_list: ' + js2JSON(E));
214 if (!debug_ignore_auth_failures) {
215 enable_login_prompts(); return;
218 var f = create_output_stream('ap_list');
219 var ap_list_json = js2JSON( ap_list );
220 f.write( ap_list_json, ap_list_json.length ); f.close();
221 mw.G.ap_list = ap_list;
222 mw.G.ap_hash = convert_object_list_to_hash( ap_list );
226 'open-ils.actor.user.ident_types.retrieve',
230 incr_progressmeter(document,'auth_meter',auth_meter_incr);
233 function cit_list_callback(request) {
234 sdump('D_AUTH',arg_dump(arguments));
237 cit_list = request.getResultObject();
238 if (!cit_list) { throw('null result'); }
239 if (cit_list.length == 0) { throw('zero length result'); }
241 alert('Login failed on cit_list: ' + js2JSON(E));
242 if (!debug_ignore_auth_failures) {
243 enable_login_prompts(); return;
246 mw.G.cit_list = cit_list;
247 mw.G.cit_hash = convert_object_list_to_hash( cit_list );
251 'open-ils.actor.standings.retrieve',
256 incr_progressmeter(document,'auth_meter',auth_meter_incr);
259 function cst_list_callback(request) {
260 sdump('D_AUTH',arg_dump(arguments));
263 cst_list = request.getResultObject();
264 if (!cst_list) { throw('null result'); }
265 if (cst_list.length == 0) { throw('zero length result'); }
267 alert('Login failed on cst_list: ' + js2JSON(E));
268 if (!debug_ignore_auth_failures) {
269 enable_login_prompts(); return;
272 mw.G.cst_list = cst_list;
273 mw.G.cst_hash = convert_object_list_to_hash( cst_list );
274 sdump('D_AUTH', 'cst_list = ' + js2JSON(cst_list) + '\n');
278 'open-ils.search.config.copy_location.retrieve.all',
282 incr_progressmeter(document,'auth_meter',auth_meter_incr);
286 function acpl_list_callback(request) {
287 sdump('D_AUTH',arg_dump(arguments));
290 acpl_list = request.getResultObject();
291 if (!acpl_list) { throw('null result'); }
292 if (acpl_list.length == 0) { throw('zero length result'); }
294 alert('Login failed on acpl_list: ' + js2JSON(E));
295 if (!debug_ignore_auth_failures) {
296 enable_login_prompts(); return;
299 mw.G.acpl_list = acpl_list;
300 mw.G.acpl_hash = convert_object_list_to_hash( acpl_list );
301 sdump('D_AUTH', 'acpl_list = ' + js2JSON(acpl_list) + '\n');
305 'open-ils.search.config.copy_status.retrieve.all',
309 incr_progressmeter(document,'auth_meter',auth_meter_incr);
312 function ccs_list_callback(request) {
313 sdump('D_AUTH',arg_dump(arguments));
316 ccs_list = request.getResultObject();
317 if (!ccs_list) { throw('null result'); }
318 if (ccs_list.length == 0) { throw('zero length result'); }
320 alert('Login failed on ccs_list: ' + js2JSON(E));
321 if (!debug_ignore_auth_failures) {
322 enable_login_prompts(); return;
325 mw.G.ccs_list = ccs_list;
326 mw.G.ccs_hash = convert_object_list_to_hash( ccs_list );
327 sdump('D_AUTH', 'ccs_list = ' + js2JSON(ccs_list) + '\n');
331 'open-ils.search.actor.user.session',
332 [ mw.G['auth_ses'][0] ],
335 incr_progressmeter(document,'auth_meter',auth_meter_incr);
338 function user_callback(request) {
339 sdump('D_AUTH',arg_dump(arguments));
343 user = request.getResultObject();
344 if (!user) { throw('null result'); }
345 if (typeof(user) != 'object') { throw('result not an object' + user); }
347 alert('Login failed on user: ' + js2JSON(E));
348 if (!debug_ignore_auth_failures) {
349 enable_login_prompts(); return;
353 mw.G.user_ou = user.home_ou();
354 sdump('D_AUTH', "user: " + js2JSON(mw.G['user']) + '\n');
355 sdump('D_AUTH', "user_ou: " + js2JSON(mw.G['user_ou']) + '\n');
358 'open-ils.actor.org_tree.retrieve',
362 incr_progressmeter(document,'auth_meter',auth_meter_incr);
365 function org_tree_callback(request) {
368 org_tree = request.getResultObject();
369 if (!org_tree) { throw('null result'); }
370 if (typeof(org_tree) != 'object') { throw('result not an object' + org_tree); }
372 alert('Login failed on org_tree: ' + js2JSON(E)); enable_login_prompts(); return;
375 //mw.G.org_tree = globalOrgTree;
376 mw.G.org_tree = org_tree;
377 mw.G.org_tree_hash = convert_object_list_to_hash( flatten_ou_branch( mw.G.org_tree ) );
378 mw.G.user_ou = find_ou( mw.G.org_tree, mw.G.user_ou );
380 /*user_async_request(
382 'open-ils.actor.org_types.retrieve',
383 [ mw.G.auth_ses[0] ],
389 function org_type_callback(request) {
390 sdump('D_AUTH',arg_dump(arguments));
391 var aout_list = globalOrgTypes;
393 aout_list = request.getResultObject();
394 if (!aout_list) { throw('null result'); }
395 if (typeof(aout_list) != 'object') { throw('result not an object' + aout_list); }
396 if (aout_list.length == 0) { throw('empty aout_list'); }
398 alert('Login failed on aout_list: ' + js2JSON(E)); enable_login_prompts(); return;
400 mw.G.aout_list = aout_list;
401 mw.G.aout_hash = convert_object_list_to_hash( aout_list );
405 'open-ils.actor.org_unit.full_path.retrieve',
406 [ mw.G.auth_ses[0] ],
409 incr_progressmeter(document,'auth_meter',auth_meter_incr);
412 function my_orgs_callback(request) {
413 sdump('D_AUTH',arg_dump(arguments));
416 my_orgs = request.getResultObject();
417 if (!my_orgs) { throw('null result'); }
418 if (typeof(my_orgs) != 'object') { throw('result not an object' + my_orgs); }
419 if (my_orgs.length == 0) { throw('empty my_orgs'); }
421 alert('Login failed on my_orgs: ' + js2JSON(E));
422 if (!debug_ignore_auth_failures) {
423 enable_login_prompts(); return;
427 mw.G.my_orgs = my_orgs;
428 mw.G.my_orgs_hash = convert_object_list_to_hash( my_orgs );
429 sdump('D_AUTH','my_orgs = ' + js2JSON(my_orgs) + '\n');
430 mw.G.acpl_my_orgs = filter_list(
433 if ( typeof obj != 'object' ) return null;
434 if ( mw.G.my_orgs_hash[ obj.owning_lib() ] ) return obj;
437 mw.G.acpl_my_orgs_hash = convert_object_list_to_hash( mw.G.acpl_my_orgs );
438 //sdump('D_AUTH', 'my_orgs.length = ' + mw.G.my_orgs.length + ' other_orgs.length = ' + mw.G.other_orgs.length + '\n');
442 'open-ils.circ.stat_cat.actor.retrieve.all',
443 [ mw.G.auth_ses[0], mw.G.user_ou.id() ],
444 my_actsc_list_callback
447 incr_progressmeter(document,'auth_meter',auth_meter_incr);
450 function my_actsc_list_callback(request) {
451 sdump('D_AUTH',arg_dump(arguments));
454 actsc_list = request.getResultObject();
455 if (!actsc_list) { throw('null result'); }
456 //if (actsc_list.length == 0) { throw('zero length result'); }
458 alert('Login failed on actsc_list: ' + js2JSON(E));
459 if (!debug_ignore_auth_failures) {
460 enable_login_prompts(); return;
463 mw.G.actsc_list = actsc_list;
464 mw.G.actsc_hash = convert_object_list_to_hash( actsc_list );
465 sdump('D_AUTH', 'actsc_list = ' + js2JSON(actsc_list) + '\n');
467 incr_progressmeter(document,'auth_meter',auth_meter_incr);
477 sdump('D_AUTH',arg_dump(arguments));
478 mw.G['auth_ses'] = '';
480 enable_login_prompts();
481 incr_progressmeter(document,'auth_meter',-100);
485 function nice_shutdown() {
486 sdump('D_AUTH',arg_dump(arguments));
487 if (ses) { logoff(); ses.disconnect(); }