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');
145 //'open-ils.actor.user.profiles.retrieve',
148 'open-ils.actor.groups.retrieve',
152 incr_progressmeter(document,'auth_meter',auth_meter_incr);
155 function ap_list_callback(request) {
156 sdump('D_AUTH',arg_dump(arguments));
159 ap_list = request.getResultObject();
160 if (!ap_list) { throw('null result'); }
161 if (ap_list.length == 0) { throw('zero length result'); }
163 alert('Login failed on ap_list: ' + js2JSON(E));
164 if (!debug_ignore_auth_failures) {
165 enable_login_prompts(); return;
168 mw.G.ap_list = ap_list;
169 mw.G.ap_hash = convert_object_list_to_hash( ap_list );
173 'open-ils.actor.user.ident_types.retrieve',
177 incr_progressmeter(document,'auth_meter',auth_meter_incr);
180 function cit_list_callback(request) {
181 sdump('D_AUTH',arg_dump(arguments));
184 cit_list = request.getResultObject();
185 if (!cit_list) { throw('null result'); }
186 if (cit_list.length == 0) { throw('zero length result'); }
188 alert('Login failed on cit_list: ' + js2JSON(E));
189 if (!debug_ignore_auth_failures) {
190 enable_login_prompts(); return;
193 mw.G.cit_list = cit_list;
194 mw.G.cit_hash = convert_object_list_to_hash( cit_list );
198 'open-ils.actor.standings.retrieve',
203 incr_progressmeter(document,'auth_meter',auth_meter_incr);
206 function cst_list_callback(request) {
207 sdump('D_AUTH',arg_dump(arguments));
210 cst_list = request.getResultObject();
211 if (!cst_list) { throw('null result'); }
212 if (cst_list.length == 0) { throw('zero length result'); }
214 alert('Login failed on cst_list: ' + js2JSON(E));
215 if (!debug_ignore_auth_failures) {
216 enable_login_prompts(); return;
219 mw.G.cst_list = cst_list;
220 mw.G.cst_hash = convert_object_list_to_hash( cst_list );
221 sdump('D_AUTH', 'cst_list = ' + js2JSON(cst_list) + '\n');
225 'open-ils.search.config.copy_location.retrieve.all',
229 incr_progressmeter(document,'auth_meter',auth_meter_incr);
233 function acpl_list_callback(request) {
234 sdump('D_AUTH',arg_dump(arguments));
237 acpl_list = request.getResultObject();
238 if (!acpl_list) { throw('null result'); }
239 if (acpl_list.length == 0) { throw('zero length result'); }
241 alert('Login failed on acpl_list: ' + js2JSON(E));
242 if (!debug_ignore_auth_failures) {
243 enable_login_prompts(); return;
246 mw.G.acpl_list = acpl_list;
247 mw.G.acpl_hash = convert_object_list_to_hash( acpl_list );
248 sdump('D_AUTH', 'acpl_list = ' + js2JSON(acpl_list) + '\n');
252 'open-ils.search.config.copy_status.retrieve.all',
256 incr_progressmeter(document,'auth_meter',auth_meter_incr);
259 function ccs_list_callback(request) {
260 sdump('D_AUTH',arg_dump(arguments));
263 ccs_list = request.getResultObject();
264 if (!ccs_list) { throw('null result'); }
265 if (ccs_list.length == 0) { throw('zero length result'); }
267 alert('Login failed on ccs_list: ' + js2JSON(E));
268 if (!debug_ignore_auth_failures) {
269 enable_login_prompts(); return;
272 mw.G.ccs_list = ccs_list;
273 mw.G.ccs_hash = convert_object_list_to_hash( ccs_list );
274 sdump('D_AUTH', 'ccs_list = ' + js2JSON(ccs_list) + '\n');
278 'open-ils.search.actor.user.session',
279 [ mw.G['auth_ses'][0] ],
282 incr_progressmeter(document,'auth_meter',auth_meter_incr);
285 function user_callback(request) {
286 sdump('D_AUTH',arg_dump(arguments));
290 user = request.getResultObject();
291 if (!user) { throw('null result'); }
292 if (typeof(user) != 'object') { throw('result not an object' + user); }
294 alert('Login failed on user: ' + js2JSON(E));
295 if (!debug_ignore_auth_failures) {
296 enable_login_prompts(); return;
300 mw.G.user_ou = user.home_ou();
301 sdump('D_AUTH', "user: " + js2JSON(mw.G['user']) + '\n');
302 sdump('D_AUTH', "user_ou: " + js2JSON(mw.G['user_ou']) + '\n');
303 /*user_async_request(
305 'open-ils.search.actor.org_tree.retrieve',
309 /*user_async_request(
311 'open-ils.actor.org_types.retrieve',
312 [ mw.G.auth_ses[0] ],
316 incr_progressmeter(document,'auth_meter',auth_meter_incr);
319 function org_type_callback(request) {
320 sdump('D_AUTH',arg_dump(arguments));
321 var aout_list = globalOrgTypes;
323 aout_list = request.getResultObject();
324 if (!aout_list) { throw('null result'); }
325 if (typeof(aout_list) != 'object') { throw('result not an object' + aout_list); }
326 if (aout_list.length == 0) { throw('empty aout_list'); }
328 alert('Login failed on aout_list: ' + js2JSON(E)); enable_login_prompts(); return;
330 mw.G.aout_list = aout_list;
331 mw.G.aout_hash = convert_object_list_to_hash( aout_list );
332 mw.G.org_tree = globalOrgTree;
333 mw.G.org_tree_hash = convert_object_list_to_hash( flatten_ou_branch( globalOrgTree ) );
334 mw.G.user_ou = find_ou( mw.G.org_tree, mw.G.user_ou );
338 'open-ils.actor.org_unit.full_path.retrieve',
339 [ mw.G.auth_ses[0] ],
342 incr_progressmeter(document,'auth_meter',auth_meter_incr);
346 function my_orgs_callback(request) {
347 sdump('D_AUTH',arg_dump(arguments));
350 my_orgs = request.getResultObject();
351 if (!my_orgs) { throw('null result'); }
352 if (typeof(my_orgs) != 'object') { throw('result not an object' + my_orgs); }
353 if (my_orgs.length == 0) { throw('empty my_orgs'); }
355 alert('Login failed on my_orgs: ' + js2JSON(E));
356 if (!debug_ignore_auth_failures) {
357 enable_login_prompts(); return;
361 mw.G.my_orgs = my_orgs;
362 mw.G.my_orgs_hash = convert_object_list_to_hash( my_orgs );
363 sdump('D_AUTH','my_orgs = ' + js2JSON(my_orgs) + '\n');
364 mw.G.acpl_my_orgs = filter_list(
367 if ( typeof obj != 'object' ) return null;
368 if ( mw.G.my_orgs_hash[ obj.owning_lib() ] ) return obj;
371 mw.G.acpl_my_orgs_hash = convert_object_list_to_hash( mw.G.acpl_my_orgs );
372 //sdump('D_AUTH', 'my_orgs.length = ' + mw.G.my_orgs.length + ' other_orgs.length = ' + mw.G.other_orgs.length + '\n');
376 'open-ils.circ.stat_cat.actor.retrieve.all',
377 [ mw.G.auth_ses[0], mw.G.user_ou.id() ],
378 my_actsc_list_callback
381 incr_progressmeter(document,'auth_meter',auth_meter_incr);
384 function my_actsc_list_callback(request) {
385 sdump('D_AUTH',arg_dump(arguments));
388 actsc_list = request.getResultObject();
389 if (!actsc_list) { throw('null result'); }
390 if (actsc_list.length == 0) { throw('zero length result'); }
392 alert('Login failed on actsc_list: ' + js2JSON(E));
393 if (!debug_ignore_auth_failures) {
394 enable_login_prompts(); return;
397 mw.G.actsc_list = actsc_list;
398 mw.G.actsc_hash = convert_object_list_to_hash( actsc_list );
399 sdump('D_AUTH', 'actsc_list = ' + js2JSON(actsc_list) + '\n');
401 incr_progressmeter(document,'auth_meter',auth_meter_incr);
411 sdump('D_AUTH',arg_dump(arguments));
412 mw.G['auth_ses'] = '';
414 enable_login_prompts();
415 incr_progressmeter(document,'auth_meter',-100);
419 function nice_shutdown() {
420 sdump('D_AUTH',arg_dump(arguments));
421 if (ses) { logoff(); ses.disconnect(); }