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;
12 G['main_test_variable'] = 'Hello World';
15 G['my_orgs_hash'] = {};
19 G['ap_list'] = []; // actor::profile
21 G['cit_list'] = []; // config::identification_type
23 G['cst_list'] = []; // config::standing
25 G['acpl_list'] = []; // asset::copy_location
26 G['acpl_hash'] = {}; G['acpl_my_orgs'] = []; G['acpl_my_orgs_hash'] = {};
27 G['aout_list'] = []; // actor::org_unit_type
29 G['ccs_list'] = []; // config::copy_status
31 G['asc_list'] = []; // asset::stat_cat
32 G['actsc_list'] = []; // actor::stat_cat
33 G['actsc_hash']; // actor::stat_cat
35 var mw = G['main_window'];
36 var auth_meter_incr = 10;
38 function auth_init() {
39 sdump('D_AUTH','TESTING: auth.js: ' + mw.G['main_test_variable'] + '\n');
40 var np = document.getElementById('name_prompt');
41 np.addEventListener("keypress",handle_keypress,false);
43 var pp = document.getElementById('password_prompt');
44 pp.addEventListener("keypress",handle_keypress,false);
45 self.addEventListener("unload",nice_shutdown,false);
46 G['sound'] = xp_sound_init();
51 function handle_keypress(ev) {
52 if (ev.keyCode && ev.keyCode == 13) {
54 case document.getElementById('name_prompt') :
56 var pp = document.getElementById('password_prompt');
57 pp.focus(); pp.select();
59 case document.getElementById('password_prompt') :
61 var sb = document.getElementById('submit_button');
71 function disable_login_prompts() {
72 disable_widgets(document,'password_prompt','name_prompt','submit_button');
76 function enable_login_prompts() {
77 enable_widgets(document,'password_prompt','name_prompt','submit_button');
78 document.getElementById('password_prompt').value = '';
79 var np = document.getElementById('name_prompt');
80 np.focus(); np.select();
81 document.getElementById('auth_meter').value = 0;
82 document.getElementById('auth_meter').setAttribute('real', '0.0');
86 function authenticate() {
88 var name = document.getElementById('name_prompt').value;
89 if (name.length == 0) { enable_login_prompts(); return; }
90 // Talk to the system and authenticate the user.
93 'open-ils.auth.authenticate.init',
99 function auth_init_callback(request) {
102 auth_init = request.getResultObject();
103 if (!auth_init) { throw('null result'); }
105 alert('Login failed on auth_init: ' + js2JSON(E));
106 if (!debug_ignore_auth_failures) {
107 enable_login_prompts(); return;
111 sdump( 'D_AUTH', 'D_AUTH_INIT: ' + typeof(auth_init) + ' : ' + auth_init + '\n');
112 var name = document.getElementById('name_prompt').value;
113 var pw = document.getElementById('password_prompt').value;
117 'open-ils.auth.authenticate.complete',
118 [ name, hex_md5(auth_init + hex_md5(pw)) ],
121 incr_progressmeter(document,'auth_meter',auth_meter_incr);
124 function auth_ses_callback(request) {
127 auth_ses = request.getResultObject();
128 if (!auth_ses) { throw('null result'); }
129 if (auth_ses == 0) { throw('0 result'); }
131 alert('Login failed on auth_ses: ' + js2JSON(E));
132 if (!debug_ignore_auth_failures) {
133 enable_login_prompts(); return;
136 mw.G.auth_ses = [ auth_ses ];
137 sdump( 'D_AUTH', 'D_AUTH_SES: ' + typeof(mw.G['auth_ses'][0]) + ' : ' + mw.G['auth_ses'][0] + '\n');
141 'open-ils.actor.user.profiles.retrieve',
145 incr_progressmeter(document,'auth_meter',auth_meter_incr);
148 function ap_list_callback(request) {
151 ap_list = request.getResultObject();
152 if (!ap_list) { throw('null result'); }
153 if (ap_list.length == 0) { throw('zero length result'); }
155 alert('Login failed on ap_list: ' + js2JSON(E));
156 if (!debug_ignore_auth_failures) {
157 enable_login_prompts(); return;
160 mw.G.ap_list = ap_list;
161 mw.G.ap_hash = convert_object_list_to_hash( ap_list );
165 'open-ils.actor.user.ident_types.retrieve',
169 incr_progressmeter(document,'auth_meter',auth_meter_incr);
172 function cit_list_callback(request) {
175 cit_list = request.getResultObject();
176 if (!cit_list) { throw('null result'); }
177 if (cit_list.length == 0) { throw('zero length result'); }
179 alert('Login failed on cit_list: ' + js2JSON(E));
180 if (!debug_ignore_auth_failures) {
181 enable_login_prompts(); return;
184 mw.G.cit_list = cit_list;
185 mw.G.cit_hash = convert_object_list_to_hash( cit_list );
189 'open-ils.actor.standings.retrieve',
194 incr_progressmeter(document,'auth_meter',auth_meter_incr);
197 function cst_list_callback(request) {
200 cst_list = request.getResultObject();
201 if (!cst_list) { throw('null result'); }
202 if (cst_list.length == 0) { throw('zero length result'); }
204 alert('Login failed on cst_list: ' + js2JSON(E));
205 if (!debug_ignore_auth_failures) {
206 enable_login_prompts(); return;
209 mw.G.cst_list = cst_list;
210 mw.G.cst_hash = convert_object_list_to_hash( cst_list );
211 sdump('D_AUTH', 'cst_list = ' + js2JSON(cst_list) + '\n');
215 'open-ils.search.config.copy_location.retrieve.all',
219 incr_progressmeter(document,'auth_meter',auth_meter_incr);
223 function acpl_list_callback(request) {
226 acpl_list = request.getResultObject();
227 if (!acpl_list) { throw('null result'); }
228 if (acpl_list.length == 0) { throw('zero length result'); }
230 alert('Login failed on acpl_list: ' + js2JSON(E));
231 if (!debug_ignore_auth_failures) {
232 enable_login_prompts(); return;
235 mw.G.acpl_list = acpl_list;
236 mw.G.acpl_hash = convert_object_list_to_hash( acpl_list );
237 sdump('D_AUTH', 'acpl_list = ' + js2JSON(acpl_list) + '\n');
241 'open-ils.search.config.copy_status.retrieve.all',
245 incr_progressmeter(document,'auth_meter',auth_meter_incr);
248 function ccs_list_callback(request) {
251 ccs_list = request.getResultObject();
252 if (!ccs_list) { throw('null result'); }
253 if (ccs_list.length == 0) { throw('zero length result'); }
255 alert('Login failed on ccs_list: ' + js2JSON(E));
256 if (!debug_ignore_auth_failures) {
257 enable_login_prompts(); return;
260 mw.G.ccs_list = ccs_list;
261 mw.G.ccs_hash = convert_object_list_to_hash( ccs_list );
262 sdump('D_AUTH', 'ccs_list = ' + js2JSON(ccs_list) + '\n');
266 'open-ils.search.actor.user.session',
267 [ mw.G['auth_ses'][0] ],
270 incr_progressmeter(document,'auth_meter',auth_meter_incr);
273 function user_callback(request) {
277 user = request.getResultObject();
278 if (!user) { throw('null result'); }
279 if (typeof(user) != 'object') { throw('result not an object' + user); }
281 alert('Login failed on user: ' + js2JSON(E));
282 if (!debug_ignore_auth_failures) {
283 enable_login_prompts(); return;
287 mw.G.user_ou = user.home_ou();
288 sdump('D_AUTH', "user: " + js2JSON(mw.G['user']) + '\n');
289 sdump('D_AUTH', "user_ou: " + js2JSON(mw.G['user_ou']) + '\n');
290 /*user_async_request(
292 'open-ils.search.actor.org_tree.retrieve',
296 /*user_async_request(
298 'open-ils.actor.org_types.retrieve',
299 [ mw.G.auth_ses[0] ],
303 incr_progressmeter(document,'auth_meter',auth_meter_incr);
306 function org_type_callback(request) {
307 var aout_list = globalOrgTypes;
309 aout_list = request.getResultObject();
310 if (!aout_list) { throw('null result'); }
311 if (typeof(aout_list) != 'object') { throw('result not an object' + aout_list); }
312 if (aout_list.length == 0) { throw('empty aout_list'); }
314 alert('Login failed on aout_list: ' + js2JSON(E)); enable_login_prompts(); return;
316 mw.G.aout_list = aout_list;
317 mw.G.aout_hash = convert_object_list_to_hash( aout_list );
318 mw.G.org_tree = globalOrgTree;
319 mw.G.org_tree_hash = convert_object_list_to_hash( flatten_ou_branch( globalOrgTree ) );
320 mw.G.user_ou = find_ou( mw.G.org_tree, mw.G.user_ou );
324 'open-ils.actor.org_unit.full_path.retrieve',
325 [ mw.G.auth_ses[0] ],
328 incr_progressmeter(document,'auth_meter',auth_meter_incr);
332 function my_orgs_callback(request) {
335 my_orgs = request.getResultObject();
336 if (!my_orgs) { throw('null result'); }
337 if (typeof(my_orgs) != 'object') { throw('result not an object' + my_orgs); }
338 if (my_orgs.length == 0) { throw('empty my_orgs'); }
340 alert('Login failed on my_orgs: ' + js2JSON(E));
341 if (!debug_ignore_auth_failures) {
342 enable_login_prompts(); return;
346 mw.G.my_orgs = my_orgs;
347 mw.G.my_orgs_hash = convert_object_list_to_hash( my_orgs );
348 sdump('D_AUTH','my_orgs = ' + js2JSON(my_orgs) + '\n');
349 mw.G.acpl_my_orgs = filter_list(
352 if ( typeof obj != 'object' ) return null;
353 if ( mw.G.my_orgs_hash[ obj.owning_lib() ] ) return obj;
356 mw.G.acpl_my_orgs_hash = convert_object_list_to_hash( mw.G.acpl_my_orgs );
357 //sdump('D_AUTH', 'my_orgs.length = ' + mw.G.my_orgs.length + ' other_orgs.length = ' + mw.G.other_orgs.length + '\n');
361 'open-ils.circ.stat_cat.actor.retrieve.all',
362 [ mw.G.auth_ses[0], mw.G.user_ou.id() ],
363 my_actsc_list_callback
366 incr_progressmeter(document,'auth_meter',auth_meter_incr);
369 function my_actsc_list_callback(request) {
372 actsc_list = request.getResultObject();
373 if (!actsc_list) { throw('null result'); }
374 if (actsc_list.length == 0) { throw('zero length result'); }
376 alert('Login failed on asc_list: ' + js2JSON(E));
377 if (!debug_ignore_auth_failures) {
378 enable_login_prompts(); return;
381 mw.G.actsc_list = actsc_list;
382 mw.G.actsc_hash = convert_object_list_to_hash( actsc_list );
383 sdump('D_AUTH', 'actsc_list = ' + js2JSON(actsc_list) + '\n');
385 incr_progressmeter(document,'auth_meter',auth_meter_incr);
395 mw.G['auth_ses'] = '';
397 enable_login_prompts();
398 incr_progressmeter(document,'auth_meter',-100);
402 function nice_shutdown() {
403 if (ses) { logoff(); ses.disconnect(); }