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 sdump('D_AUTH',arg_dump(arguments));
41 var np = document.getElementById('name_prompt');
42 np.addEventListener("keypress",handle_keypress,false);
44 var pp = document.getElementById('password_prompt');
45 pp.addEventListener("keypress",handle_keypress,false);
46 self.addEventListener("unload",nice_shutdown,false);
47 G['sound'] = xp_sound_init();
52 function handle_keypress(ev) {
53 if (ev.keyCode && ev.keyCode == 13) {
55 case document.getElementById('name_prompt') :
57 var pp = document.getElementById('password_prompt');
58 pp.focus(); pp.select();
60 case document.getElementById('password_prompt') :
62 var sb = document.getElementById('submit_button');
72 function disable_login_prompts() {
73 sdump('D_AUTH',arg_dump(arguments));
74 disable_widgets(document,'password_prompt','name_prompt','submit_button');
78 function enable_login_prompts() {
79 sdump('D_AUTH',arg_dump(arguments));
80 enable_widgets(document,'password_prompt','name_prompt','submit_button');
81 document.getElementById('password_prompt').value = '';
82 var np = document.getElementById('name_prompt');
83 np.focus(); np.select();
84 document.getElementById('auth_meter').value = 0;
85 document.getElementById('auth_meter').setAttribute('real', '0.0');
89 function authenticate() {
90 sdump('D_AUTH',arg_dump(arguments));
92 var name = document.getElementById('name_prompt').value;
93 if (name.length == 0) { enable_login_prompts(); return; }
94 // Talk to the system and authenticate the user.
97 'open-ils.auth.authenticate.init',
103 function auth_init_callback(request) {
104 sdump('D_AUTH',arg_dump(arguments));
107 auth_init = request.getResultObject();
108 if (!auth_init) { throw('null result'); }
110 alert('Login failed on auth_init: ' + js2JSON(E));
111 if (!debug_ignore_auth_failures) {
112 enable_login_prompts(); return;
116 sdump( 'D_AUTH', 'D_AUTH_INIT: ' + typeof(auth_init) + ' : ' + auth_init + '\n');
117 var name = document.getElementById('name_prompt').value;
118 var pw = document.getElementById('password_prompt').value;
122 'open-ils.auth.authenticate.complete',
123 [ name, hex_md5(auth_init + hex_md5(pw)) ],
126 incr_progressmeter(document,'auth_meter',auth_meter_incr);
129 function auth_ses_callback(request) {
130 sdump('D_AUTH',arg_dump(arguments));
133 auth_ses = request.getResultObject();
134 if (!auth_ses) { throw('null result'); }
135 if (auth_ses == 0) { throw('0 result'); }
137 alert('Login failed on auth_ses: ' + js2JSON(E));
138 if (!debug_ignore_auth_failures) {
139 enable_login_prompts(); return;
142 mw.G.auth_ses = [ auth_ses ];
143 sdump( 'D_AUTH', 'D_AUTH_SES: ' + typeof(mw.G['auth_ses'][0]) + ' : ' + mw.G['auth_ses'][0] + '\n');
147 'open-ils.actor.user.profiles.retrieve',
151 incr_progressmeter(document,'auth_meter',auth_meter_incr);
154 function ap_list_callback(request) {
155 sdump('D_AUTH',arg_dump(arguments));
158 ap_list = request.getResultObject();
159 if (!ap_list) { throw('null result'); }
160 if (ap_list.length == 0) { throw('zero length result'); }
162 alert('Login failed on ap_list: ' + js2JSON(E));
163 if (!debug_ignore_auth_failures) {
164 enable_login_prompts(); return;
167 mw.G.ap_list = ap_list;
168 mw.G.ap_hash = convert_object_list_to_hash( ap_list );
172 'open-ils.actor.user.ident_types.retrieve',
176 incr_progressmeter(document,'auth_meter',auth_meter_incr);
179 function cit_list_callback(request) {
180 sdump('D_AUTH',arg_dump(arguments));
183 cit_list = request.getResultObject();
184 if (!cit_list) { throw('null result'); }
185 if (cit_list.length == 0) { throw('zero length result'); }
187 alert('Login failed on cit_list: ' + js2JSON(E));
188 if (!debug_ignore_auth_failures) {
189 enable_login_prompts(); return;
192 mw.G.cit_list = cit_list;
193 mw.G.cit_hash = convert_object_list_to_hash( cit_list );
197 'open-ils.actor.standings.retrieve',
202 incr_progressmeter(document,'auth_meter',auth_meter_incr);
205 function cst_list_callback(request) {
206 sdump('D_AUTH',arg_dump(arguments));
209 cst_list = request.getResultObject();
210 if (!cst_list) { throw('null result'); }
211 if (cst_list.length == 0) { throw('zero length result'); }
213 alert('Login failed on cst_list: ' + js2JSON(E));
214 if (!debug_ignore_auth_failures) {
215 enable_login_prompts(); return;
218 mw.G.cst_list = cst_list;
219 mw.G.cst_hash = convert_object_list_to_hash( cst_list );
220 sdump('D_AUTH', 'cst_list = ' + js2JSON(cst_list) + '\n');
224 'open-ils.search.config.copy_location.retrieve.all',
228 incr_progressmeter(document,'auth_meter',auth_meter_incr);
232 function acpl_list_callback(request) {
233 sdump('D_AUTH',arg_dump(arguments));
236 acpl_list = request.getResultObject();
237 if (!acpl_list) { throw('null result'); }
238 if (acpl_list.length == 0) { throw('zero length result'); }
240 alert('Login failed on acpl_list: ' + js2JSON(E));
241 if (!debug_ignore_auth_failures) {
242 enable_login_prompts(); return;
245 mw.G.acpl_list = acpl_list;
246 mw.G.acpl_hash = convert_object_list_to_hash( acpl_list );
247 sdump('D_AUTH', 'acpl_list = ' + js2JSON(acpl_list) + '\n');
251 'open-ils.search.config.copy_status.retrieve.all',
255 incr_progressmeter(document,'auth_meter',auth_meter_incr);
258 function ccs_list_callback(request) {
259 sdump('D_AUTH',arg_dump(arguments));
262 ccs_list = request.getResultObject();
263 if (!ccs_list) { throw('null result'); }
264 if (ccs_list.length == 0) { throw('zero length result'); }
266 alert('Login failed on ccs_list: ' + js2JSON(E));
267 if (!debug_ignore_auth_failures) {
268 enable_login_prompts(); return;
271 mw.G.ccs_list = ccs_list;
272 mw.G.ccs_hash = convert_object_list_to_hash( ccs_list );
273 sdump('D_AUTH', 'ccs_list = ' + js2JSON(ccs_list) + '\n');
277 'open-ils.search.actor.user.session',
278 [ mw.G['auth_ses'][0] ],
281 incr_progressmeter(document,'auth_meter',auth_meter_incr);
284 function user_callback(request) {
285 sdump('D_AUTH',arg_dump(arguments));
289 user = request.getResultObject();
290 if (!user) { throw('null result'); }
291 if (typeof(user) != 'object') { throw('result not an object' + user); }
293 alert('Login failed on user: ' + js2JSON(E));
294 if (!debug_ignore_auth_failures) {
295 enable_login_prompts(); return;
299 mw.G.user_ou = user.home_ou();
300 sdump('D_AUTH', "user: " + js2JSON(mw.G['user']) + '\n');
301 sdump('D_AUTH', "user_ou: " + js2JSON(mw.G['user_ou']) + '\n');
302 /*user_async_request(
304 'open-ils.search.actor.org_tree.retrieve',
308 /*user_async_request(
310 'open-ils.actor.org_types.retrieve',
311 [ mw.G.auth_ses[0] ],
315 incr_progressmeter(document,'auth_meter',auth_meter_incr);
318 function org_type_callback(request) {
319 sdump('D_AUTH',arg_dump(arguments));
320 var aout_list = globalOrgTypes;
322 aout_list = request.getResultObject();
323 if (!aout_list) { throw('null result'); }
324 if (typeof(aout_list) != 'object') { throw('result not an object' + aout_list); }
325 if (aout_list.length == 0) { throw('empty aout_list'); }
327 alert('Login failed on aout_list: ' + js2JSON(E)); enable_login_prompts(); return;
329 mw.G.aout_list = aout_list;
330 mw.G.aout_hash = convert_object_list_to_hash( aout_list );
331 mw.G.org_tree = globalOrgTree;
332 mw.G.org_tree_hash = convert_object_list_to_hash( flatten_ou_branch( globalOrgTree ) );
333 mw.G.user_ou = find_ou( mw.G.org_tree, mw.G.user_ou );
337 'open-ils.actor.org_unit.full_path.retrieve',
338 [ mw.G.auth_ses[0] ],
341 incr_progressmeter(document,'auth_meter',auth_meter_incr);
345 function my_orgs_callback(request) {
346 sdump('D_AUTH',arg_dump(arguments));
349 my_orgs = request.getResultObject();
350 if (!my_orgs) { throw('null result'); }
351 if (typeof(my_orgs) != 'object') { throw('result not an object' + my_orgs); }
352 if (my_orgs.length == 0) { throw('empty my_orgs'); }
354 alert('Login failed on my_orgs: ' + js2JSON(E));
355 if (!debug_ignore_auth_failures) {
356 enable_login_prompts(); return;
360 mw.G.my_orgs = my_orgs;
361 mw.G.my_orgs_hash = convert_object_list_to_hash( my_orgs );
362 sdump('D_AUTH','my_orgs = ' + js2JSON(my_orgs) + '\n');
363 mw.G.acpl_my_orgs = filter_list(
366 if ( typeof obj != 'object' ) return null;
367 if ( mw.G.my_orgs_hash[ obj.owning_lib() ] ) return obj;
370 mw.G.acpl_my_orgs_hash = convert_object_list_to_hash( mw.G.acpl_my_orgs );
371 //sdump('D_AUTH', 'my_orgs.length = ' + mw.G.my_orgs.length + ' other_orgs.length = ' + mw.G.other_orgs.length + '\n');
375 'open-ils.circ.stat_cat.actor.retrieve.all',
376 [ mw.G.auth_ses[0], mw.G.user_ou.id() ],
377 my_actsc_list_callback
380 incr_progressmeter(document,'auth_meter',auth_meter_incr);
383 function my_actsc_list_callback(request) {
384 sdump('D_AUTH',arg_dump(arguments));
387 actsc_list = request.getResultObject();
388 if (!actsc_list) { throw('null result'); }
389 if (actsc_list.length == 0) { throw('zero length result'); }
391 alert('Login failed on asc_list: ' + js2JSON(E));
392 if (!debug_ignore_auth_failures) {
393 enable_login_prompts(); return;
396 mw.G.actsc_list = actsc_list;
397 mw.G.actsc_hash = convert_object_list_to_hash( actsc_list );
398 sdump('D_AUTH', 'actsc_list = ' + js2JSON(actsc_list) + '\n');
400 incr_progressmeter(document,'auth_meter',auth_meter_incr);
410 sdump('D_AUTH',arg_dump(arguments));
411 mw.G['auth_ses'] = '';
413 enable_login_prompts();
414 incr_progressmeter(document,'auth_meter',-100);
418 function nice_shutdown() {
419 sdump('D_AUTH',arg_dump(arguments));
420 if (ses) { logoff(); ses.disconnect(); }