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();
109 var pref = Components.classes["@mozilla.org/preferences-service;1"]
110 .getService(Components.interfaces.nsIPrefBranch);
112 pref.setCharPref("capability.principal.codebase.p0.granted", "UniversalXPConnect UniversalPreferencesWrite UniversalBrowserWrite UniversalPreferencesRead UniversalBrowserRead");
113 pref.setCharPref("capability.principal.codebase.p0.id", "http://dev.gapines.org");
117 function handle_keypress(ev) {
118 if (ev.keyCode && ev.keyCode == 13) {
120 case document.getElementById('name_prompt') :
122 var pp = document.getElementById('password_prompt');
123 pp.focus(); pp.select();
125 case document.getElementById('password_prompt') :
127 var sb = document.getElementById('submit_button');
137 function disable_login_prompts() {
138 sdump('D_AUTH',arg_dump(arguments));
139 disable_widgets(document,'password_prompt','name_prompt','submit_button');
143 function enable_login_prompts() {
144 sdump('D_AUTH',arg_dump(arguments));
145 enable_widgets(document,'password_prompt','name_prompt','submit_button');
146 document.getElementById('password_prompt').value = '';
147 var np = document.getElementById('name_prompt');
148 np.focus(); np.select();
149 document.getElementById('auth_meter').value = 0;
150 document.getElementById('auth_meter').setAttribute('real', '0.0');
154 /////////////////////////////////////////////////////////////////////////////////////
156 function authenticate() {
157 sdump('D_AUTH',arg_dump(arguments));
159 var name = document.getElementById('name_prompt').value;
160 if (name.length == 0) { enable_login_prompts(); return; }
161 // Talk to the system and authenticate the user.
164 'open-ils.auth.authenticate.init',
170 function auth_init_callback(request) {
171 sdump('D_AUTH',arg_dump(arguments));
174 auth_init = request.getResultObject();
175 if (!auth_init) { throw('null result'); }
178 sdump('D_ERROR','Error trying to communicate with the server. Entering OFFLINE mode.\n' + js2JSON(E) + '\n');
179 s_alert('Error trying to communicate with the server. Entering OFFLINE mode.\n' + js2JSON(E) + '\n');
182 sdump( 'D_AUTH', 'D_AUTH_INIT: ' + typeof(auth_init) + ' : ' + auth_init + '\n');
183 var name = document.getElementById('name_prompt').value;
184 var pw = document.getElementById('password_prompt').value;
185 G.name = name; G.pw = pw;
187 /////////////////////////////////////////////////////////////////////////////////////////////////////
190 'open-ils.auth.authenticate.complete',
191 [ name, hex_md5(auth_init + hex_md5(pw)) ],
194 incr_progressmeter(document,'auth_meter',auth_meter_incr);
197 function auth_ses_callback(request) {
198 sdump('D_AUTH',arg_dump(arguments));
201 auth_ses = request.getResultObject();
202 if (!auth_ses) { if (!G.offline) { throw('null result'); } }
203 if (auth_ses == 0) { throw('0 result'); }
204 if (instanceOf(auth_ses,ex)) {
205 throw(auth_ses.err_msg());
208 alert('Login failed on auth_ses: ' + js2JSON(E));
209 if (!debug_ignore_auth_failures) {
210 enable_login_prompts(); return;
213 mw.G.auth_ses = [ auth_ses ];
214 sdump( 'D_AUTH', 'D_AUTH_SES: ' + typeof(mw.G['auth_ses'][0]) + ' : ' + mw.G['auth_ses'][0] + '\n');
216 /////////////////////////////////////////////////////////////////////////////////////////////////////
217 //'open-ils.actor.user.profiles.retrieve',
220 'open-ils.actor.groups.retrieve',
224 incr_progressmeter(document,'auth_meter',auth_meter_incr);
227 function ap_list_callback(request) {
228 sdump('D_AUTH',arg_dump(arguments));
229 //var ap_file = get_file('ap_list');
232 ap_list = request.getResultObject();
233 if (!ap_list && G.offline) {
234 //ap_list = get_object_in_file('ap_list');
236 if (!ap_list) { throw('null result'); }
237 if (ap_list.length == 0) { throw('zero length result'); }
239 handle_error('Login failed on ap_list: ' + js2JSON(E));
240 if (!debug_ignore_auth_failures) {
241 enable_login_prompts(); return;
244 //try { set_object_in_file('ap_list',ap_list); } catch(E) { handle_error(E); }
245 mw.G.ap_list = ap_list;
246 mw.G.ap_hash = convert_object_list_to_hash( ap_list );
248 /////////////////////////////////////////////////////////////////////////////////////////////////////
251 'open-ils.actor.user.ident_types.retrieve',
255 incr_progressmeter(document,'auth_meter',auth_meter_incr);
258 function cit_list_callback(request) {
259 sdump('D_AUTH',arg_dump(arguments));
262 cit_list = request.getResultObject();
263 //if (!cit_list && G.offline) { cit_list = get_object_in_file('cit_list'); }
264 if (!cit_list) { throw('null result'); }
265 if (cit_list.length == 0) { throw('zero length result'); }
267 alert('Login failed on cit_list: ' + js2JSON(E));
268 if (!debug_ignore_auth_failures) {
269 enable_login_prompts(); return;
272 //try { set_object_in_file('cit_list',cit_list); } catch(E) { handle_error(E); }
273 mw.G.cit_list = cit_list;
274 mw.G.cit_hash = convert_object_list_to_hash( cit_list );
276 /////////////////////////////////////////////////////////////////////////////////////////////////////
279 'open-ils.actor.standings.retrieve',
284 incr_progressmeter(document,'auth_meter',auth_meter_incr);
287 function cst_list_callback(request) {
288 sdump('D_AUTH',arg_dump(arguments));
291 cst_list = request.getResultObject();
292 //if (!cst_list && G.offline) { cst_list = get_object_in_file('cst_list'); }
293 if (!cst_list) { throw('null result'); }
294 if (cst_list.length == 0) { throw('zero length result'); }
296 alert('Login failed on cst_list: ' + js2JSON(E));
297 if (!debug_ignore_auth_failures) {
298 enable_login_prompts(); return;
301 //try { set_object_in_file('cst_list',cst_list); } catch(E) { handle_error(E); }
302 mw.G.cst_list = cst_list;
303 mw.G.cst_hash = convert_object_list_to_hash( cst_list );
304 sdump('D_AUTH', 'cst_list = ' + js2JSON(cst_list) + '\n');
306 /////////////////////////////////////////////////////////////////////////////////////////////////////
309 'open-ils.search.config.copy_location.retrieve.all',
313 incr_progressmeter(document,'auth_meter',auth_meter_incr);
317 function acpl_list_callback(request) {
318 sdump('D_AUTH',arg_dump(arguments));
321 acpl_list = request.getResultObject();
322 //if (!acpl_list && G.offline) { acpl_list = get_object_in_file('acpl_list'); }
323 if (!acpl_list) { throw('null result'); }
324 if (acpl_list.length == 0) { throw('zero length result'); }
326 alert('Login failed on acpl_list: ' + js2JSON(E));
327 if (!debug_ignore_auth_failures) {
328 enable_login_prompts(); return;
331 //try { set_object_in_file('acpl_list',acpl_list); } catch(E) { handle_error(E); }
332 mw.G.acpl_list = acpl_list;
333 mw.G.acpl_hash = convert_object_list_to_hash( acpl_list );
334 sdump('D_AUTH', 'acpl_list = ' + js2JSON(acpl_list) + '\n');
336 /////////////////////////////////////////////////////////////////////////////////////////////////////
339 'open-ils.search.config.copy_status.retrieve.all',
343 incr_progressmeter(document,'auth_meter',auth_meter_incr);
346 function ccs_list_callback(request) {
347 sdump('D_AUTH',arg_dump(arguments));
350 ccs_list = request.getResultObject();
351 //if (!ccs_list && G.offline) { ccs_list = get_object_in_file('ccs_list'); }
352 if (!ccs_list) { throw('null result'); }
353 if (ccs_list.length == 0) { throw('zero length result'); }
355 alert('Login failed on ccs_list: ' + js2JSON(E));
356 if (!debug_ignore_auth_failures) {
357 enable_login_prompts(); return;
360 //try { set_object_in_file('ccs_list',ccs_list); } catch(E) { handle_error(E); }
361 mw.G.ccs_list = ccs_list;
362 mw.G.ccs_hash = convert_object_list_to_hash( ccs_list );
363 sdump('D_AUTH', 'ccs_list = ' + js2JSON(ccs_list) + '\n');
365 /////////////////////////////////////////////////////////////////////////////////////////////////////
368 'open-ils.search.actor.user.session',
369 [ mw.G['auth_ses'][0] ],
372 incr_progressmeter(document,'auth_meter',auth_meter_incr);
375 function user_callback(request) {
376 sdump('D_AUTH',arg_dump(arguments));
380 user = request.getResultObject();
381 if (!user && G.offline) {
383 //user.home_ou( get_object_in_file('user_ou') );
385 if (!user) { throw('null result'); }
386 if (typeof(user) != 'object') { throw('result not an object' + user); }
388 alert('Login failed on user: ' + js2JSON(E));
389 if (!debug_ignore_auth_failures) {
390 enable_login_prompts(); return;
393 //try { set_object_in_file('user_ou',user.home_ou()); } catch(E) { handle_error(E); }
395 mw.G.user_ou = user.home_ou();
396 sdump('D_AUTH', "user: " + js2JSON(mw.G['user']) + '\n');
397 sdump('D_AUTH', "user_ou: " + js2JSON(mw.G['user_ou']) + '\n');
399 /////////////////////////////////////////////////////////////////////////////////////////////////////
402 'open-ils.actor.org_tree.retrieve',
406 incr_progressmeter(document,'auth_meter',auth_meter_incr);
409 function org_tree_callback(request) {
412 org_tree = request.getResultObject();
413 //if (!org_tree && G.offline) { org_tree = get_object_in_file('org_tree'); }
414 if (!org_tree) { throw('null result'); }
415 if (typeof(org_tree) != 'object') { throw('result not an object' + org_tree); }
417 alert('Login failed on org_tree: ' + js2JSON(E)); enable_login_prompts(); return;
420 //mw.G.org_tree = globalOrgTree;
421 //try { set_object_in_file('org_tree',org_tree); } catch(E) { handle_error(E); }
422 mw.G.org_tree = org_tree;
423 mw.G.org_tree_hash = convert_object_list_to_hash( flatten_ou_branch( mw.G.org_tree ) );
424 mw.G.user_ou = find_ou( mw.G.org_tree, mw.G.user_ou );
426 /////////////////////////////////////////////////////////////////////////////////////////////////////
427 /*user_async_request(
429 'open-ils.actor.org_types.retrieve',
430 [ mw.G.auth_ses[0] ],
436 function org_type_callback(request) {
437 sdump('D_AUTH',arg_dump(arguments));
438 var aout_list = globalOrgTypes;
440 aout_list = request.getResultObject();
441 if (!aout_list) { throw('null result'); }
442 if (typeof(aout_list) != 'object') { throw('result not an object' + aout_list); }
443 if (aout_list.length == 0) { throw('empty aout_list'); }
445 alert('Login failed on aout_list: ' + js2JSON(E)); enable_login_prompts(); return;
447 mw.G.aout_list = aout_list;
448 mw.G.aout_hash = convert_object_list_to_hash( aout_list );
450 /////////////////////////////////////////////////////////////////////////////////////////////////////
453 'open-ils.actor.org_unit.full_path.retrieve',
454 [ mw.G.auth_ses[0] ],
457 incr_progressmeter(document,'auth_meter',auth_meter_incr);
460 function my_orgs_callback(request) {
461 sdump('D_AUTH',arg_dump(arguments));
464 my_orgs = request.getResultObject();
465 //if (!my_orgs && G.offline) { my_orgs = get_object_in_file('my_orgs'); }
466 if (!my_orgs) { throw('null result'); }
467 if (typeof(my_orgs) != 'object') { throw('result not an object' + my_orgs); }
468 if (my_orgs.length == 0) { throw('empty my_orgs'); }
470 alert('Login failed on my_orgs: ' + js2JSON(E));
471 if (!debug_ignore_auth_failures) {
472 enable_login_prompts(); return;
476 //try { set_object_in_file('my_orgs',my_orgs); } catch(E) { handle_error(E); }
477 mw.G.my_orgs = my_orgs;
478 mw.G.my_orgs_hash = convert_object_list_to_hash( my_orgs );
479 sdump('D_AUTH','my_orgs = ' + js2JSON(my_orgs) + '\n');
480 mw.G.acpl_my_orgs = filter_list(
483 if ( typeof obj != 'object' ) return null;
484 if ( mw.G.my_orgs_hash[ obj.owning_lib() ] ) return obj;
487 mw.G.acpl_my_orgs_hash = convert_object_list_to_hash( mw.G.acpl_my_orgs );
488 //sdump('D_AUTH', 'my_orgs.length = ' + mw.G.my_orgs.length + ' other_orgs.length = ' + mw.G.other_orgs.length + '\n');
490 /////////////////////////////////////////////////////////////////////////////////////////////////////
493 'open-ils.circ.stat_cat.actor.retrieve.all',
494 [ mw.G.auth_ses[0], mw.G.user_ou.id() ],
495 my_actsc_list_callback
498 incr_progressmeter(document,'auth_meter',auth_meter_incr);
501 function my_actsc_list_callback(request) {
502 sdump('D_AUTH',arg_dump(arguments));
505 actsc_list = request.getResultObject();
506 //if (!actsc_list && G.offline) { actsc_list = get_object_in_file('actsc_list'); }
507 if (!actsc_list) { throw('null result'); }
508 //if (actsc_list.length == 0) { throw('zero length result'); }
510 alert('Login failed on actsc_list: ' + js2JSON(E));
511 if (!debug_ignore_auth_failures) {
512 enable_login_prompts(); return;
515 //try { set_object_in_file('actsc_list',actsc_list); } catch(E) { handle_error(E); }
516 mw.G.actsc_list = actsc_list;
517 mw.G.actsc_hash = convert_object_list_to_hash( actsc_list );
518 sdump('D_AUTH', 'actsc_list = ' + js2JSON(actsc_list) + '\n');
520 incr_progressmeter(document,'auth_meter',auth_meter_incr);
530 sdump('D_AUTH',arg_dump(arguments));
531 mw.G['auth_ses'] = '';
533 enable_login_prompts();
534 incr_progressmeter(document,'auth_meter',-100);
538 function nice_shutdown() {
539 sdump('D_AUTH',arg_dump(arguments));
540 if (ses) { logoff(); ses.disconnect(); }