1 var G = {}; // the master Global variable
2 G['main_window'] = self;
3 G['win_list'] = new Array();
4 G['window_name_increment'] = 0;
7 G['main_test_variable'] = 'Hello World';
10 G['my_orgs_hash'] = {};
14 G['ap_list'] = []; // actor::profile
16 G['cit_list'] = []; // config::identification_type
18 G['cst_list'] = []; // config::standing
20 G['acpl_list'] = []; // asset::copy_location
21 G['acpl_hash'] = {}; G['acpl_my_orgs'] = []; G['acpl_my_orgs_hash'] = {};
22 G['aout_list'] = []; // actor::org_unit_type
24 G['ccs_list'] = []; // config::copy_status
26 G['asc_list'] = []; // asset::stat_cat
27 G['actsc_list'] = []; // actor::stat_cat
28 G['actsc_hash']; // actor::stat_cat
30 var mw = G['main_window'];
31 var auth_meter_incr = 8;
33 function auth_init() {
34 sdump('D_AUTH','TESTING: auth.js: ' + mw.G['main_test_variable'] + '\n');
35 var np = document.getElementById('name_prompt');
36 np.addEventListener("keypress",handle_keypress,false);
38 var pp = document.getElementById('password_prompt');
39 pp.addEventListener("keypress",handle_keypress,false);
40 self.addEventListener("unload",nice_shutdown,false);
41 G['sound'] = xp_sound_init();
46 function handle_keypress(ev) {
47 if (ev.keyCode && ev.keyCode == 13) {
49 case document.getElementById('name_prompt') :
51 var pp = document.getElementById('password_prompt');
52 pp.focus(); pp.select();
54 case document.getElementById('password_prompt') :
56 var sb = document.getElementById('submit_button');
66 function disable_login_prompts() {
67 disable_widgets('password_prompt','name_prompt','submit_button');
71 function enable_login_prompts() {
72 enable_widgets('password_prompt','name_prompt','submit_button');
73 document.getElementById('password_prompt').value = '';
74 var np = document.getElementById('name_prompt');
75 np.focus(); np.select();
76 document.getElementById('auth_meter').value = 0;
77 document.getElementById('auth_meter').setAttribute('real', '0.0');
81 function authenticate() {
83 var name = document.getElementById('name_prompt').value;
84 if (name.length == 0) { enable_login_prompts(); return; }
85 // Talk to the system and authenticate the user.
88 'open-ils.auth.authenticate.init',
94 function auth_init_callback(request) {
97 auth_init = request.getResultObject();
98 if (!auth_init) { throw('null result'); }
100 alert('Login failed on auth_init: ' + js2JSON(E)); enable_login_prompts(); return;
103 sdump( 'D_AUTH', 'D_AUTH_INIT: ' + typeof(auth_init) + ' : ' + auth_init + '\n');
104 var name = document.getElementById('name_prompt').value;
105 var pw = document.getElementById('password_prompt').value;
109 'open-ils.auth.authenticate.complete',
110 [ name, hex_md5(auth_init + hex_md5(pw)) ],
113 incr_progressmeter('auth_meter',auth_meter_incr);
116 function auth_ses_callback(request) {
119 auth_ses = request.getResultObject();
120 if (!auth_ses) { throw('null result'); }
121 if (auth_ses == 0) { throw('0 result'); }
123 alert('Login failed on auth_ses: ' + js2JSON(E)); enable_login_prompts(); return;
125 mw.G.auth_ses = [ auth_ses ];
126 sdump( 'D_AUTH', 'D_AUTH_SES: ' + typeof(mw.G['auth_ses'][0]) + ' : ' + mw.G['auth_ses'][0] + '\n');
130 'open-ils.actor.user.profiles.retrieve',
134 incr_progressmeter('auth_meter',auth_meter_incr);
137 function ap_list_callback(request) {
140 ap_list = request.getResultObject();
141 if (!ap_list) { throw('null result'); }
142 if (ap_list.length == 0) { throw('zero length result'); }
144 alert('Login failed on ap_list: ' + js2JSON(E)); enable_login_prompts(); return;
146 mw.G.ap_list = ap_list;
147 mw.G.ap_hash = convert_object_list_to_hash( ap_list );
151 'open-ils.actor.user.ident_types.retrieve',
155 incr_progressmeter('auth_meter',auth_meter_incr);
158 function cit_list_callback(request) {
161 cit_list = request.getResultObject();
162 if (!cit_list) { throw('null result'); }
163 if (cit_list.length == 0) { throw('zero length result'); }
165 alert('Login failed on cit_list: ' + js2JSON(E)); enable_login_prompts(); return;
167 mw.G.cit_list = cit_list;
168 mw.G.cit_hash = convert_object_list_to_hash( cit_list );
172 'open-ils.actor.standings.retrieve',
177 incr_progressmeter('auth_meter',auth_meter_incr);
180 function cst_list_callback(request) {
183 cst_list = request.getResultObject();
184 if (!cst_list) { throw('null result'); }
185 if (cst_list.length == 0) { throw('zero length result'); }
187 alert('Login failed on cst_list: ' + js2JSON(E)); enable_login_prompts(); return;
189 mw.G.cst_list = cst_list;
190 mw.G.cst_hash = convert_object_list_to_hash( cst_list );
191 sdump('D_AUTH', 'cst_list = ' + js2JSON(cst_list) + '\n');
195 'open-ils.search.config.copy_location.retrieve.all',
199 incr_progressmeter('auth_meter',auth_meter_incr);
203 function acpl_list_callback(request) {
206 acpl_list = request.getResultObject();
207 if (!acpl_list) { throw('null result'); }
208 if (acpl_list.length == 0) { throw('zero length result'); }
210 alert('Login failed on acpl_list: ' + js2JSON(E)); enable_login_prompts(); return;
212 mw.G.acpl_list = acpl_list;
213 mw.G.acpl_hash = convert_object_list_to_hash( acpl_list );
214 sdump('D_AUTH', 'acpl_list = ' + js2JSON(acpl_list) + '\n');
218 'open-ils.search.config.copy_status.retrieve.all',
222 incr_progressmeter('auth_meter',auth_meter_incr);
225 function ccs_list_callback(request) {
228 ccs_list = request.getResultObject();
229 if (!ccs_list) { throw('null result'); }
230 if (ccs_list.length == 0) { throw('zero length result'); }
232 alert('Login failed on ccs_list: ' + js2JSON(E)); enable_login_prompts(); return;
234 mw.G.ccs_list = ccs_list;
235 mw.G.ccs_hash = convert_object_list_to_hash( ccs_list );
236 sdump('D_AUTH', 'ccs_list = ' + js2JSON(ccs_list) + '\n');
240 'open-ils.search.actor.user.session',
241 [ mw.G['auth_ses'][0] ],
244 incr_progressmeter('auth_meter',auth_meter_incr);
247 function user_callback(request) {
251 user = request.getResultObject();
252 if (!user) { throw('null result'); }
253 if (typeof(user) != 'object') { throw('result not an object' + user); }
255 alert('Login failed on user: ' + js2JSON(E)); enable_login_prompts(); return;
258 mw.G.user_ou = user.home_ou();
259 sdump('D_AUTH', "user: " + js2JSON(mw.G['user']) + '\n');
260 sdump('D_AUTH', "user_ou: " + js2JSON(mw.G['user_ou']) + '\n');
261 /*user_async_request(
263 'open-ils.search.actor.org_tree.retrieve',
267 /*user_async_request(
269 'open-ils.actor.org_types.retrieve',
270 [ mw.G.auth_ses[0] ],
274 incr_progressmeter('auth_meter',auth_meter_incr);
277 function org_type_callback(request) {
278 var aout_list = globalOrgTypes;
280 aout_list = request.getResultObject();
281 if (!aout_list) { throw('null result'); }
282 if (typeof(aout_list) != 'object') { throw('result not an object' + aout_list); }
283 if (aout_list.length == 0) { throw('empty aout_list'); }
285 alert('Login failed on aout_list: ' + js2JSON(E)); enable_login_prompts(); return;
287 mw.G.aout_list = aout_list;
288 mw.G.aout_hash = convert_object_list_to_hash( aout_list );
289 mw.G.org_tree = globalOrgTree;
290 mw.G.org_tree_hash = convert_object_list_to_hash( flatten_ou_branch( globalOrgTree ) );
291 mw.G.user_ou = find_ou( mw.G.org_tree, mw.G.user_ou );
295 'open-ils.actor.org_unit.full_path.retrieve',
296 [ mw.G.auth_ses[0] ],
299 incr_progressmeter('auth_meter',auth_meter_incr);
303 function my_orgs_callback(request) {
306 my_orgs = request.getResultObject();
307 if (!my_orgs) { throw('null result'); }
308 if (typeof(my_orgs) != 'object') { throw('result not an object' + my_orgs); }
309 if (my_orgs.length == 0) { throw('empty my_orgs'); }
311 alert('Login failed on my_orgs: ' + js2JSON(E)); enable_login_prompts(); return;
314 mw.G.my_orgs = my_orgs;
315 mw.G.my_orgs_hash = convert_object_list_to_hash( my_orgs );
316 sdump('D_AUTH','my_orgs = ' + js2JSON(my_orgs) + '\n');
317 mw.G.acpl_my_orgs = filter_list(
320 if ( typeof obj != 'object' ) return null;
321 if ( mw.G.my_orgs_hash[ obj.owning_lib() ] ) return obj;
324 mw.G.acpl_my_orgs_hash = convert_object_list_to_hash( mw.G.acpl_my_orgs );
325 //sdump('D_AUTH', 'my_orgs.length = ' + mw.G.my_orgs.length + ' other_orgs.length = ' + mw.G.other_orgs.length + '\n');
329 'open-ils.circ.stat_cat.actor.retrieve.all',
330 [ mw.G.auth_ses[0], mw.G.user_ou.id() ],
331 my_actsc_list_callback
334 incr_progressmeter('auth_meter',auth_meter_incr);
337 function my_actsc_list_callback(request) {
340 actsc_list = request.getResultObject();
341 if (!actsc_list) { throw('null result'); }
342 if (actsc_list.length == 0) { throw('zero length result'); }
344 alert('Login failed on asc_list: ' + js2JSON(E)); enable_login_prompts(); return;
346 mw.G.actsc_list = actsc_list;
347 mw.G.actsc_hash = convert_object_list_to_hash( actsc_list );
348 sdump('D_AUTH', 'actsc_list = ' + js2JSON(actsc_list) + '\n');
350 incr_progressmeter('auth_meter',auth_meter_incr);
358 mw.G['auth_ses'] = '';
360 enable_login_prompts();
361 incr_progressmeter('auth_meter',-100);
365 function nice_shutdown() {
366 if (ses) { logoff(); ses.disconnect(); }