1 var G = {}; // the master Global variable
3 var debug_ignore_auth_failures = false;
6 G['main_window'] = self;
8 G['appshell_list'] = [];
10 G['window_name_increment'] = 0;
11 G['appshell_name_increment'] = 0;
14 G['main_test_variable'] = 'Hello World';
17 G['my_orgs_hash'] = {};
21 G['ap_list'] = []; // actor::profile
23 G['cit_list'] = []; // config::identification_type
25 G['cst_list'] = []; // config::standing
27 G['acpl_list'] = []; // asset::copy_location
28 G['acpl_hash'] = {}; G['acpl_my_orgs'] = []; G['acpl_my_orgs_hash'] = {};
29 G['aout_list'] = []; // actor::org_unit_type
31 G['ccs_list'] = []; // config::copy_status
33 G['asc_list'] = []; // asset::stat_cat
34 G['actsc_list'] = []; // actor::stat_cat
35 G['actsc_hash']; // actor::stat_cat
37 G['itemsout_header'] = 'Welcome %PATRON_FIRSTNAME%, to %LIBRARY%!\r\nYou have the following items:<hr/><ol>';
38 G['itemsout_line_item'] = '<li>%TITLE: 50%\r\nBarcode: %COPY_BARCODE% Due: %DUE_D%\r\n';
39 G['itemsout_footer'] = '</ol><hr />%PINES_CODE% %TODAY%\r\nYou were helped by %STAFF_FIRSTNAME% %STAFF_LASTNAME%';
41 G['checkout_header'] = 'Welcome %PATRON_FIRSTNAME%, to %LIBRARY%!\r\nYou checked out the following items:<hr/><ol>';
42 G['checkout_line_item'] = '<li>%TITLE%\r\nBarcode: %COPY_BARCODE% Due: %DUE_D%\r\n';
43 G['checkout_footer'] = '</ol><hr />%PINES_CODE% %TODAY%\r\nYou were helped by %STAFF_FIRSTNAME% %STAFF_LASTNAME%';
45 var mw = G['main_window'];
46 var auth_meter_incr = 10;
48 function auth_init() {
49 sdump('D_AUTH','TESTING: auth.js: ' + mw.G['main_test_variable'] + '\n');
50 sdump('D_AUTH',arg_dump(arguments));
51 var np = document.getElementById('name_prompt');
52 np.addEventListener("keypress",handle_keypress,false);
54 var pp = document.getElementById('password_prompt');
55 pp.addEventListener("keypress",handle_keypress,false);
56 self.addEventListener("unload",nice_shutdown,false);
57 G['sound'] = xp_sound_init();
62 function handle_keypress(ev) {
63 if (ev.keyCode && ev.keyCode == 13) {
65 case document.getElementById('name_prompt') :
67 var pp = document.getElementById('password_prompt');
68 pp.focus(); pp.select();
70 case document.getElementById('password_prompt') :
72 var sb = document.getElementById('submit_button');
82 function disable_login_prompts() {
83 sdump('D_AUTH',arg_dump(arguments));
84 disable_widgets(document,'password_prompt','name_prompt','submit_button');
88 function enable_login_prompts() {
89 sdump('D_AUTH',arg_dump(arguments));
90 enable_widgets(document,'password_prompt','name_prompt','submit_button');
91 document.getElementById('password_prompt').value = '';
92 var np = document.getElementById('name_prompt');
93 np.focus(); np.select();
94 document.getElementById('auth_meter').value = 0;
95 document.getElementById('auth_meter').setAttribute('real', '0.0');
99 function authenticate() {
100 sdump('D_AUTH',arg_dump(arguments));
102 var name = document.getElementById('name_prompt').value;
103 if (name.length == 0) { enable_login_prompts(); return; }
104 // Talk to the system and authenticate the user.
107 'open-ils.auth.authenticate.init',
113 function auth_init_callback(request) {
114 sdump('D_AUTH',arg_dump(arguments));
117 auth_init = request.getResultObject();
118 if (!auth_init) { throw('null result'); }
121 sdump('D_ERROR','Error trying to communicate with the server. Entering OFFLINE mode.\n');
122 s_alert('Error trying to communicate with the server. Entering OFFLINE mode.\n');
125 sdump( 'D_AUTH', 'D_AUTH_INIT: ' + typeof(auth_init) + ' : ' + auth_init + '\n');
126 var name = document.getElementById('name_prompt').value;
127 var pw = document.getElementById('password_prompt').value;
131 'open-ils.auth.authenticate.complete',
132 [ name, hex_md5(auth_init + hex_md5(pw)) ],
135 incr_progressmeter(document,'auth_meter',auth_meter_incr);
138 function auth_ses_callback(request) {
139 sdump('D_AUTH',arg_dump(arguments));
142 auth_ses = request.getResultObject();
143 if (!auth_ses) { throw('null result'); }
144 if (auth_ses == 0) { throw('0 result'); }
145 if (instanceOf(auth_ses,ex)) {
146 throw(auth_ses.err_msg());
149 alert('Login failed on auth_ses: ' + js2JSON(E));
150 if (!debug_ignore_auth_failures) {
151 enable_login_prompts(); return;
154 mw.G.auth_ses = [ auth_ses ];
155 sdump( 'D_AUTH', 'D_AUTH_SES: ' + typeof(mw.G['auth_ses'][0]) + ' : ' + mw.G['auth_ses'][0] + '\n');
157 //'open-ils.actor.user.profiles.retrieve',
160 'open-ils.actor.groups.retrieve',
164 incr_progressmeter(document,'auth_meter',auth_meter_incr);
167 function ap_list_callback(request) {
168 sdump('D_AUTH',arg_dump(arguments));
171 ap_list = request.getResultObject();
172 if (!ap_list) { throw('null result'); }
173 if (ap_list.length == 0) { throw('zero length result'); }
175 alert('Login failed on ap_list: ' + js2JSON(E));
176 if (!debug_ignore_auth_failures) {
177 enable_login_prompts(); return;
180 mw.G.ap_list = ap_list;
181 mw.G.ap_hash = convert_object_list_to_hash( ap_list );
185 'open-ils.actor.user.ident_types.retrieve',
189 incr_progressmeter(document,'auth_meter',auth_meter_incr);
192 function cit_list_callback(request) {
193 sdump('D_AUTH',arg_dump(arguments));
196 cit_list = request.getResultObject();
197 if (!cit_list) { throw('null result'); }
198 if (cit_list.length == 0) { throw('zero length result'); }
200 alert('Login failed on cit_list: ' + js2JSON(E));
201 if (!debug_ignore_auth_failures) {
202 enable_login_prompts(); return;
205 mw.G.cit_list = cit_list;
206 mw.G.cit_hash = convert_object_list_to_hash( cit_list );
210 'open-ils.actor.standings.retrieve',
215 incr_progressmeter(document,'auth_meter',auth_meter_incr);
218 function cst_list_callback(request) {
219 sdump('D_AUTH',arg_dump(arguments));
222 cst_list = request.getResultObject();
223 if (!cst_list) { throw('null result'); }
224 if (cst_list.length == 0) { throw('zero length result'); }
226 alert('Login failed on cst_list: ' + js2JSON(E));
227 if (!debug_ignore_auth_failures) {
228 enable_login_prompts(); return;
231 mw.G.cst_list = cst_list;
232 mw.G.cst_hash = convert_object_list_to_hash( cst_list );
233 sdump('D_AUTH', 'cst_list = ' + js2JSON(cst_list) + '\n');
237 'open-ils.search.config.copy_location.retrieve.all',
241 incr_progressmeter(document,'auth_meter',auth_meter_incr);
245 function acpl_list_callback(request) {
246 sdump('D_AUTH',arg_dump(arguments));
249 acpl_list = request.getResultObject();
250 if (!acpl_list) { throw('null result'); }
251 if (acpl_list.length == 0) { throw('zero length result'); }
253 alert('Login failed on acpl_list: ' + js2JSON(E));
254 if (!debug_ignore_auth_failures) {
255 enable_login_prompts(); return;
258 mw.G.acpl_list = acpl_list;
259 mw.G.acpl_hash = convert_object_list_to_hash( acpl_list );
260 sdump('D_AUTH', 'acpl_list = ' + js2JSON(acpl_list) + '\n');
264 'open-ils.search.config.copy_status.retrieve.all',
268 incr_progressmeter(document,'auth_meter',auth_meter_incr);
271 function ccs_list_callback(request) {
272 sdump('D_AUTH',arg_dump(arguments));
275 ccs_list = request.getResultObject();
276 if (!ccs_list) { throw('null result'); }
277 if (ccs_list.length == 0) { throw('zero length result'); }
279 alert('Login failed on ccs_list: ' + js2JSON(E));
280 if (!debug_ignore_auth_failures) {
281 enable_login_prompts(); return;
284 mw.G.ccs_list = ccs_list;
285 mw.G.ccs_hash = convert_object_list_to_hash( ccs_list );
286 sdump('D_AUTH', 'ccs_list = ' + js2JSON(ccs_list) + '\n');
290 'open-ils.search.actor.user.session',
291 [ mw.G['auth_ses'][0] ],
294 incr_progressmeter(document,'auth_meter',auth_meter_incr);
297 function user_callback(request) {
298 sdump('D_AUTH',arg_dump(arguments));
302 user = request.getResultObject();
303 if (!user) { throw('null result'); }
304 if (typeof(user) != 'object') { throw('result not an object' + user); }
306 alert('Login failed on user: ' + js2JSON(E));
307 if (!debug_ignore_auth_failures) {
308 enable_login_prompts(); return;
312 mw.G.user_ou = user.home_ou();
313 sdump('D_AUTH', "user: " + js2JSON(mw.G['user']) + '\n');
314 sdump('D_AUTH', "user_ou: " + js2JSON(mw.G['user_ou']) + '\n');
317 'open-ils.actor.org_tree.retrieve',
321 incr_progressmeter(document,'auth_meter',auth_meter_incr);
324 function org_tree_callback(request) {
327 org_tree = request.getResultObject();
328 if (!org_tree) { throw('null result'); }
329 if (typeof(org_tree) != 'object') { throw('result not an object' + org_tree); }
331 alert('Login failed on org_tree: ' + js2JSON(E)); enable_login_prompts(); return;
334 //mw.G.org_tree = globalOrgTree;
335 mw.G.org_tree = org_tree;
336 mw.G.org_tree_hash = convert_object_list_to_hash( flatten_ou_branch( mw.G.org_tree ) );
337 mw.G.user_ou = find_ou( mw.G.org_tree, mw.G.user_ou );
339 /*user_async_request(
341 'open-ils.actor.org_types.retrieve',
342 [ mw.G.auth_ses[0] ],
348 function org_type_callback(request) {
349 sdump('D_AUTH',arg_dump(arguments));
350 var aout_list = globalOrgTypes;
352 aout_list = request.getResultObject();
353 if (!aout_list) { throw('null result'); }
354 if (typeof(aout_list) != 'object') { throw('result not an object' + aout_list); }
355 if (aout_list.length == 0) { throw('empty aout_list'); }
357 alert('Login failed on aout_list: ' + js2JSON(E)); enable_login_prompts(); return;
359 mw.G.aout_list = aout_list;
360 mw.G.aout_hash = convert_object_list_to_hash( aout_list );
364 'open-ils.actor.org_unit.full_path.retrieve',
365 [ mw.G.auth_ses[0] ],
368 incr_progressmeter(document,'auth_meter',auth_meter_incr);
371 function my_orgs_callback(request) {
372 sdump('D_AUTH',arg_dump(arguments));
375 my_orgs = request.getResultObject();
376 if (!my_orgs) { throw('null result'); }
377 if (typeof(my_orgs) != 'object') { throw('result not an object' + my_orgs); }
378 if (my_orgs.length == 0) { throw('empty my_orgs'); }
380 alert('Login failed on my_orgs: ' + js2JSON(E));
381 if (!debug_ignore_auth_failures) {
382 enable_login_prompts(); return;
386 mw.G.my_orgs = my_orgs;
387 mw.G.my_orgs_hash = convert_object_list_to_hash( my_orgs );
388 sdump('D_AUTH','my_orgs = ' + js2JSON(my_orgs) + '\n');
389 mw.G.acpl_my_orgs = filter_list(
392 if ( typeof obj != 'object' ) return null;
393 if ( mw.G.my_orgs_hash[ obj.owning_lib() ] ) return obj;
396 mw.G.acpl_my_orgs_hash = convert_object_list_to_hash( mw.G.acpl_my_orgs );
397 //sdump('D_AUTH', 'my_orgs.length = ' + mw.G.my_orgs.length + ' other_orgs.length = ' + mw.G.other_orgs.length + '\n');
401 'open-ils.circ.stat_cat.actor.retrieve.all',
402 [ mw.G.auth_ses[0], mw.G.user_ou.id() ],
403 my_actsc_list_callback
406 incr_progressmeter(document,'auth_meter',auth_meter_incr);
409 function my_actsc_list_callback(request) {
410 sdump('D_AUTH',arg_dump(arguments));
413 actsc_list = request.getResultObject();
414 if (!actsc_list) { throw('null result'); }
415 //if (actsc_list.length == 0) { throw('zero length result'); }
417 alert('Login failed on actsc_list: ' + js2JSON(E));
418 if (!debug_ignore_auth_failures) {
419 enable_login_prompts(); return;
422 mw.G.actsc_list = actsc_list;
423 mw.G.actsc_hash = convert_object_list_to_hash( actsc_list );
424 sdump('D_AUTH', 'actsc_list = ' + js2JSON(actsc_list) + '\n');
426 incr_progressmeter(document,'auth_meter',auth_meter_incr);
436 sdump('D_AUTH',arg_dump(arguments));
437 mw.G['auth_ses'] = '';
439 enable_login_prompts();
440 incr_progressmeter(document,'auth_meter',-100);
444 function nice_shutdown() {
445 sdump('D_AUTH',arg_dump(arguments));
446 if (ses) { logoff(); ses.disconnect(); }