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 // The related org units for the login user
42 'my_orgs' : [], 'my_orgs_hash' : {},
44 /////////////////////////////////////////////////////////////////////////////////////
47 'org_tree' : '', 'org_tree_hash' : {},
49 /////////////////////////////////////////////////////////////////////////////////////
51 // Historically, was the list of actor::profile's, but now it's user groups.
52 'ap_list' : [], 'ap_hash' : {},
54 // config::identification_type
55 'cit_list' : [], 'cit_hash' : {},
58 'cst_list' : [], 'cst_hash' : {},
60 // assett::copy_location, and for my_orgs
61 'acpl_list' : [], 'acpl_hash' : {},
62 'acpl_my_orgs' : [], 'acpl_my_orgs_hash' : {},
64 // actor::org_unit_type
65 'aout_list' : [], 'aout_hash' : {},
67 // config::copy_status
68 'ccs_list' : [], 'ccs_hash' : {},
70 // asset::stat_cat. WHERE IS THIS POPULATED AGAIN?
74 'actsc_list' : [], 'actsc_hash' : {},
76 /////////////////////////////////////////////////////////////////////////////////////
78 'itemsout_header' : 'Welcome %PATRON_FIRSTNAME%, to %LIBRARY%!\r\nYou have the following items:<hr/><ol>',
79 'itemsout_line_item' : '<li>%TITLE: 50%\r\nBarcode: %COPY_BARCODE% Due: %DUE_D%\r\n',
80 'itemsout_footer' : '</ol><hr />%PINES_CODE% %TODAY%\r\nYou were helped by %STAFF_FIRSTNAME% %STAFF_LASTNAME%',
82 'checkout_header' : 'Welcome %PATRON_FIRSTNAME%, to %LIBRARY%!\r\nYou checked out the following items:<hr/><ol>',
83 'checkout_line_item' : '<li>%TITLE%\r\nBarcode: %COPY_BARCODE% Due: %DUE_D%\r\n',
84 'checkout_footer' : '</ol><hr />%PINES_CODE% %TODAY%\r\nYou were helped by %STAFF_FIRSTNAME% %STAFF_LASTNAME%'
86 /////////////////////////////////////////////////////////////////////////////////////
87 /////////////////////////////////////////////////////////////////////////////////////
90 var debug_ignore_auth_failures = false;
92 var mw = G['main_window'];
93 var auth_meter_incr = 10;
95 /////////////////////////////////////////////////////////////////////////////////////
97 function auth_init() {
98 sdump('D_AUTH','TESTING: auth.js: ' + mw.G['main_test_variable'] + '\n');
99 sdump('D_AUTH',arg_dump(arguments));
101 var np = document.getElementById('name_prompt');
102 np.addEventListener("keypress",handle_keypress,false);
104 var pp = document.getElementById('password_prompt');
105 pp.addEventListener("keypress",handle_keypress,false);
106 self.addEventListener("unload",nice_shutdown,false);
108 G['sound'] = xp_sound_init(); snd_logon();
111 function handle_keypress(ev) {
112 if (ev.keyCode && ev.keyCode == 13) {
114 case document.getElementById('name_prompt') :
116 var pp = document.getElementById('password_prompt');
117 pp.focus(); pp.select();
119 case document.getElementById('password_prompt') :
121 var sb = document.getElementById('submit_button');
131 function disable_login_prompts() {
132 sdump('D_AUTH',arg_dump(arguments));
133 disable_widgets(document,'password_prompt','name_prompt','submit_button');
137 function enable_login_prompts() {
138 sdump('D_AUTH',arg_dump(arguments));
139 enable_widgets(document,'password_prompt','name_prompt','submit_button');
140 document.getElementById('password_prompt').value = '';
141 var np = document.getElementById('name_prompt');
142 np.focus(); np.select();
143 document.getElementById('auth_meter').value = 0;
144 document.getElementById('auth_meter').setAttribute('real', '0.0');
148 /////////////////////////////////////////////////////////////////////////////////////
150 function authenticate() {
151 sdump('D_AUTH',arg_dump(arguments));
153 var name = document.getElementById('name_prompt').value;
154 if (name.length == 0) { enable_login_prompts(); return; }
155 // Talk to the system and authenticate the user.
158 'open-ils.auth.authenticate.init',
164 function auth_init_callback(request) {
165 sdump('D_AUTH',arg_dump(arguments));
168 auth_init = request.getResultObject();
169 if (!auth_init) { throw('null result'); }
172 sdump('D_ERROR','Error trying to communicate with the server. Entering OFFLINE mode.\n');
173 s_alert('Error trying to communicate with the server. Entering OFFLINE mode.\n');
176 sdump( 'D_AUTH', 'D_AUTH_INIT: ' + typeof(auth_init) + ' : ' + auth_init + '\n');
177 var name = document.getElementById('name_prompt').value;
178 var pw = document.getElementById('password_prompt').value;
179 G.name = name; G.pw = pw;
181 /////////////////////////////////////////////////////////////////////////////////////////////////////
184 'open-ils.auth.authenticate.complete',
185 [ name, hex_md5(auth_init + hex_md5(pw)) ],
188 incr_progressmeter(document,'auth_meter',auth_meter_incr);
191 function auth_ses_callback(request) {
192 sdump('D_AUTH',arg_dump(arguments));
195 auth_ses = request.getResultObject();
196 if (!auth_ses) { if (!G.offline) { throw('null result'); } }
197 if (auth_ses == 0) { throw('0 result'); }
198 if (instanceOf(auth_ses,ex)) {
199 throw(auth_ses.err_msg());
202 alert('Login failed on auth_ses: ' + js2JSON(E));
203 if (!debug_ignore_auth_failures) {
204 enable_login_prompts(); return;
207 mw.G.auth_ses = [ auth_ses ];
208 sdump( 'D_AUTH', 'D_AUTH_SES: ' + typeof(mw.G['auth_ses'][0]) + ' : ' + mw.G['auth_ses'][0] + '\n');
210 /////////////////////////////////////////////////////////////////////////////////////////////////////
211 //'open-ils.actor.user.profiles.retrieve',
214 'open-ils.actor.groups.retrieve',
218 incr_progressmeter(document,'auth_meter',auth_meter_incr);
221 function ap_list_callback(request) {
222 sdump('D_AUTH',arg_dump(arguments));
223 var ap_file = get_file('ap_list');
226 ap_list = request.getResultObject();
227 if (!ap_list && G.offline) {
228 ap_list = get_object_in_file('ap_list');
230 if (!ap_list) { throw('null result'); }
231 if (ap_list.length == 0) { throw('zero length result'); }
233 handle_error('Login failed on ap_list: ' + js2JSON(E));
234 if (!debug_ignore_auth_failures) {
235 enable_login_prompts(); return;
238 try { set_object_in_file('ap_list',ap_list); } catch(E) { handle_error(E); }
239 mw.G.ap_list = ap_list;
240 mw.G.ap_hash = convert_object_list_to_hash( ap_list );
242 /////////////////////////////////////////////////////////////////////////////////////////////////////
245 'open-ils.actor.user.ident_types.retrieve',
249 incr_progressmeter(document,'auth_meter',auth_meter_incr);
252 function cit_list_callback(request) {
253 sdump('D_AUTH',arg_dump(arguments));
256 cit_list = request.getResultObject();
257 if (!cit_list && G.offline) { cit_list = get_object_in_file('cit_list'); }
258 if (!cit_list) { throw('null result'); }
259 if (cit_list.length == 0) { throw('zero length result'); }
261 alert('Login failed on cit_list: ' + js2JSON(E));
262 if (!debug_ignore_auth_failures) {
263 enable_login_prompts(); return;
266 try { set_object_in_file('cit_list',cit_list); } catch(E) { handle_error(E); }
267 mw.G.cit_list = cit_list;
268 mw.G.cit_hash = convert_object_list_to_hash( cit_list );
270 /////////////////////////////////////////////////////////////////////////////////////////////////////
273 'open-ils.actor.standings.retrieve',
278 incr_progressmeter(document,'auth_meter',auth_meter_incr);
281 function cst_list_callback(request) {
282 sdump('D_AUTH',arg_dump(arguments));
285 cst_list = request.getResultObject();
286 if (!cst_list && G.offline) { cst_list = get_object_in_file('cst_list'); }
287 if (!cst_list) { throw('null result'); }
288 if (cst_list.length == 0) { throw('zero length result'); }
290 alert('Login failed on cst_list: ' + js2JSON(E));
291 if (!debug_ignore_auth_failures) {
292 enable_login_prompts(); return;
295 try { set_object_in_file('cst_list',cst_list); } catch(E) { handle_error(E); }
296 mw.G.cst_list = cst_list;
297 mw.G.cst_hash = convert_object_list_to_hash( cst_list );
298 sdump('D_AUTH', 'cst_list = ' + js2JSON(cst_list) + '\n');
300 /////////////////////////////////////////////////////////////////////////////////////////////////////
303 'open-ils.search.config.copy_location.retrieve.all',
307 incr_progressmeter(document,'auth_meter',auth_meter_incr);
311 function acpl_list_callback(request) {
312 sdump('D_AUTH',arg_dump(arguments));
315 acpl_list = request.getResultObject();
316 if (!acpl_list && G.offline) { acpl_list = get_object_in_file('acpl_list'); }
317 if (!acpl_list) { throw('null result'); }
318 if (acpl_list.length == 0) { throw('zero length result'); }
320 alert('Login failed on acpl_list: ' + js2JSON(E));
321 if (!debug_ignore_auth_failures) {
322 enable_login_prompts(); return;
325 try { set_object_in_file('acpl_list',acpl_list); } catch(E) { handle_error(E); }
326 mw.G.acpl_list = acpl_list;
327 mw.G.acpl_hash = convert_object_list_to_hash( acpl_list );
328 sdump('D_AUTH', 'acpl_list = ' + js2JSON(acpl_list) + '\n');
330 /////////////////////////////////////////////////////////////////////////////////////////////////////
333 'open-ils.search.config.copy_status.retrieve.all',
337 incr_progressmeter(document,'auth_meter',auth_meter_incr);
340 function ccs_list_callback(request) {
341 sdump('D_AUTH',arg_dump(arguments));
344 ccs_list = request.getResultObject();
345 if (!ccs_list && G.offline) { ccs_list = get_object_in_file('ccs_list'); }
346 if (!ccs_list) { throw('null result'); }
347 if (ccs_list.length == 0) { throw('zero length result'); }
349 alert('Login failed on ccs_list: ' + js2JSON(E));
350 if (!debug_ignore_auth_failures) {
351 enable_login_prompts(); return;
354 try { set_object_in_file('ccs_list',ccs_list); } catch(E) { handle_error(E); }
355 mw.G.ccs_list = ccs_list;
356 mw.G.ccs_hash = convert_object_list_to_hash( ccs_list );
357 sdump('D_AUTH', 'ccs_list = ' + js2JSON(ccs_list) + '\n');
359 /////////////////////////////////////////////////////////////////////////////////////////////////////
362 'open-ils.search.actor.user.session',
363 [ mw.G['auth_ses'][0] ],
366 incr_progressmeter(document,'auth_meter',auth_meter_incr);
369 function user_callback(request) {
370 sdump('D_AUTH',arg_dump(arguments));
374 user = request.getResultObject();
375 if (!user && G.offline) {
377 user.home_ou( get_object_in_file('user_ou') );
379 if (!user) { throw('null result'); }
380 if (typeof(user) != 'object') { throw('result not an object' + user); }
382 alert('Login failed on user: ' + js2JSON(E));
383 if (!debug_ignore_auth_failures) {
384 enable_login_prompts(); return;
387 try { set_object_in_file('user_ou',user.home_ou()); } catch(E) { handle_error(E); }
389 mw.G.user_ou = user.home_ou();
390 sdump('D_AUTH', "user: " + js2JSON(mw.G['user']) + '\n');
391 sdump('D_AUTH', "user_ou: " + js2JSON(mw.G['user_ou']) + '\n');
393 /////////////////////////////////////////////////////////////////////////////////////////////////////
396 'open-ils.actor.org_tree.retrieve',
400 incr_progressmeter(document,'auth_meter',auth_meter_incr);
403 function org_tree_callback(request) {
406 org_tree = request.getResultObject();
407 if (!org_tree && G.offline) { org_tree = get_object_in_file('org_tree'); }
408 if (!org_tree) { throw('null result'); }
409 if (typeof(org_tree) != 'object') { throw('result not an object' + org_tree); }
411 alert('Login failed on org_tree: ' + js2JSON(E)); enable_login_prompts(); return;
414 //mw.G.org_tree = globalOrgTree;
415 try { set_object_in_file('org_tree',org_tree); } catch(E) { handle_error(E); }
416 mw.G.org_tree = org_tree;
417 mw.G.org_tree_hash = convert_object_list_to_hash( flatten_ou_branch( mw.G.org_tree ) );
418 mw.G.user_ou = find_ou( mw.G.org_tree, mw.G.user_ou );
420 /////////////////////////////////////////////////////////////////////////////////////////////////////
421 /*user_async_request(
423 'open-ils.actor.org_types.retrieve',
424 [ mw.G.auth_ses[0] ],
430 function org_type_callback(request) {
431 sdump('D_AUTH',arg_dump(arguments));
432 var aout_list = globalOrgTypes;
434 aout_list = request.getResultObject();
435 if (!aout_list) { throw('null result'); }
436 if (typeof(aout_list) != 'object') { throw('result not an object' + aout_list); }
437 if (aout_list.length == 0) { throw('empty aout_list'); }
439 alert('Login failed on aout_list: ' + js2JSON(E)); enable_login_prompts(); return;
441 mw.G.aout_list = aout_list;
442 mw.G.aout_hash = convert_object_list_to_hash( aout_list );
444 /////////////////////////////////////////////////////////////////////////////////////////////////////
447 'open-ils.actor.org_unit.full_path.retrieve',
448 [ mw.G.auth_ses[0] ],
451 incr_progressmeter(document,'auth_meter',auth_meter_incr);
454 function my_orgs_callback(request) {
455 sdump('D_AUTH',arg_dump(arguments));
458 my_orgs = request.getResultObject();
459 if (!my_orgs && G.offline) { my_orgs = get_object_in_file('my_orgs'); }
460 if (!my_orgs) { throw('null result'); }
461 if (typeof(my_orgs) != 'object') { throw('result not an object' + my_orgs); }
462 if (my_orgs.length == 0) { throw('empty my_orgs'); }
464 alert('Login failed on my_orgs: ' + js2JSON(E));
465 if (!debug_ignore_auth_failures) {
466 enable_login_prompts(); return;
470 try { set_object_in_file('my_orgs',my_orgs); } catch(E) { handle_error(E); }
471 mw.G.my_orgs = my_orgs;
472 mw.G.my_orgs_hash = convert_object_list_to_hash( my_orgs );
473 sdump('D_AUTH','my_orgs = ' + js2JSON(my_orgs) + '\n');
474 mw.G.acpl_my_orgs = filter_list(
477 if ( typeof obj != 'object' ) return null;
478 if ( mw.G.my_orgs_hash[ obj.owning_lib() ] ) return obj;
481 mw.G.acpl_my_orgs_hash = convert_object_list_to_hash( mw.G.acpl_my_orgs );
482 //sdump('D_AUTH', 'my_orgs.length = ' + mw.G.my_orgs.length + ' other_orgs.length = ' + mw.G.other_orgs.length + '\n');
484 /////////////////////////////////////////////////////////////////////////////////////////////////////
487 'open-ils.circ.stat_cat.actor.retrieve.all',
488 [ mw.G.auth_ses[0], mw.G.user_ou.id() ],
489 my_actsc_list_callback
492 incr_progressmeter(document,'auth_meter',auth_meter_incr);
495 function my_actsc_list_callback(request) {
496 sdump('D_AUTH',arg_dump(arguments));
499 actsc_list = request.getResultObject();
500 if (!actsc_list && G.offline) { actsc_list = get_object_in_file('actsc_list'); }
501 if (!actsc_list) { throw('null result'); }
502 //if (actsc_list.length == 0) { throw('zero length result'); }
504 alert('Login failed on actsc_list: ' + js2JSON(E));
505 if (!debug_ignore_auth_failures) {
506 enable_login_prompts(); return;
509 try { set_object_in_file('actsc_list',actsc_list); } catch(E) { handle_error(E); }
510 mw.G.actsc_list = actsc_list;
511 mw.G.actsc_hash = convert_object_list_to_hash( actsc_list );
512 sdump('D_AUTH', 'actsc_list = ' + js2JSON(actsc_list) + '\n');
514 incr_progressmeter(document,'auth_meter',auth_meter_incr);
524 sdump('D_AUTH',arg_dump(arguments));
525 mw.G['auth_ses'] = '';
527 enable_login_prompts();
528 incr_progressmeter(document,'auth_meter',-100);
532 function nice_shutdown() {
533 sdump('D_AUTH',arg_dump(arguments));
534 if (ses) { logoff(); ses.disconnect(); }