1 var G = {}; // the master Global variable
2 G['main_window'] = self;
3 G['win_list'] = new Object();
4 G['doc_list'] = new Object();
5 G['window_name_increment'] = 0;
8 G['main_test_variable'] = 'Hello World';
11 G['my_orgs_hash'] = {};
15 G['ap_list'] = []; // actor::profile
17 G['cit_list'] = []; // config::identification_type
19 G['cst_list'] = []; // config::standing
21 G['acpl_list'] = []; // asset::copy_location
22 G['acpl_hash'] = {}; G['acpl_my_orgs'] = []; G['acpl_my_orgs_hash'] = {};
23 G['aout_list'] = []; // actor::org_unit_type
25 G['ccs_list'] = []; // config::copy_status
27 G['asc_list'] = []; // asset::stat_cat
28 G['actsc_list'] = []; // actor::stat_cat
29 G['actsc_hash']; // actor::stat_cat
31 var mw = G['main_window'];
32 var auth_meter_incr = 8;
34 function auth_init() {
35 sdump('D_AUTH','TESTING: auth.js: ' + mw.G['main_test_variable'] + '\n');
36 var np = document.getElementById('name_prompt');
37 np.addEventListener("keypress",handle_keypress,false);
39 var pp = document.getElementById('password_prompt');
40 pp.addEventListener("keypress",handle_keypress,false);
41 self.addEventListener("unload",nice_shutdown,false);
42 G['sound'] = xp_sound_init();
47 function handle_keypress(ev) {
48 if (ev.keyCode && ev.keyCode == 13) {
50 case document.getElementById('name_prompt') :
52 var pp = document.getElementById('password_prompt');
53 pp.focus(); pp.select();
55 case document.getElementById('password_prompt') :
57 var sb = document.getElementById('submit_button');
67 function disable_login_prompts() {
68 disable_widgets(document,'password_prompt','name_prompt','submit_button');
72 function enable_login_prompts() {
73 enable_widgets(document,'password_prompt','name_prompt','submit_button');
74 document.getElementById('password_prompt').value = '';
75 var np = document.getElementById('name_prompt');
76 np.focus(); np.select();
77 document.getElementById('auth_meter').value = 0;
78 document.getElementById('auth_meter').setAttribute('real', '0.0');
82 function authenticate() {
84 var name = document.getElementById('name_prompt').value;
85 if (name.length == 0) { enable_login_prompts(); return; }
86 // Talk to the system and authenticate the user.
89 'open-ils.auth.authenticate.init',
95 function auth_init_callback(request) {
98 auth_init = request.getResultObject();
99 if (!auth_init) { throw('null result'); }
101 alert('Login failed on auth_init: ' + js2JSON(E)); enable_login_prompts(); return;
104 sdump( 'D_AUTH', 'D_AUTH_INIT: ' + typeof(auth_init) + ' : ' + auth_init + '\n');
105 var name = document.getElementById('name_prompt').value;
106 var pw = document.getElementById('password_prompt').value;
110 'open-ils.auth.authenticate.complete',
111 [ name, hex_md5(auth_init + hex_md5(pw)) ],
114 incr_progressmeter(document,'auth_meter',auth_meter_incr);
117 function auth_ses_callback(request) {
120 auth_ses = request.getResultObject();
121 if (!auth_ses) { throw('null result'); }
122 if (auth_ses == 0) { throw('0 result'); }
124 alert('Login failed on auth_ses: ' + js2JSON(E)); enable_login_prompts(); return;
126 mw.G.auth_ses = [ auth_ses ];
127 sdump( 'D_AUTH', 'D_AUTH_SES: ' + typeof(mw.G['auth_ses'][0]) + ' : ' + mw.G['auth_ses'][0] + '\n');
131 'open-ils.actor.user.profiles.retrieve',
135 incr_progressmeter(document,'auth_meter',auth_meter_incr);
138 function ap_list_callback(request) {
141 ap_list = request.getResultObject();
142 if (!ap_list) { throw('null result'); }
143 if (ap_list.length == 0) { throw('zero length result'); }
145 alert('Login failed on ap_list: ' + js2JSON(E)); enable_login_prompts(); return;
147 mw.G.ap_list = ap_list;
148 mw.G.ap_hash = convert_object_list_to_hash( ap_list );
152 'open-ils.actor.user.ident_types.retrieve',
156 incr_progressmeter(document,'auth_meter',auth_meter_incr);
159 function cit_list_callback(request) {
162 cit_list = request.getResultObject();
163 if (!cit_list) { throw('null result'); }
164 if (cit_list.length == 0) { throw('zero length result'); }
166 alert('Login failed on cit_list: ' + js2JSON(E)); enable_login_prompts(); return;
168 mw.G.cit_list = cit_list;
169 mw.G.cit_hash = convert_object_list_to_hash( cit_list );
173 'open-ils.actor.standings.retrieve',
178 incr_progressmeter(document,'auth_meter',auth_meter_incr);
181 function cst_list_callback(request) {
184 cst_list = request.getResultObject();
185 if (!cst_list) { throw('null result'); }
186 if (cst_list.length == 0) { throw('zero length result'); }
188 alert('Login failed on cst_list: ' + js2JSON(E)); enable_login_prompts(); return;
190 mw.G.cst_list = cst_list;
191 mw.G.cst_hash = convert_object_list_to_hash( cst_list );
192 sdump('D_AUTH', 'cst_list = ' + js2JSON(cst_list) + '\n');
196 'open-ils.search.config.copy_location.retrieve.all',
200 incr_progressmeter(document,'auth_meter',auth_meter_incr);
204 function acpl_list_callback(request) {
207 acpl_list = request.getResultObject();
208 if (!acpl_list) { throw('null result'); }
209 if (acpl_list.length == 0) { throw('zero length result'); }
211 alert('Login failed on acpl_list: ' + js2JSON(E)); enable_login_prompts(); return;
213 mw.G.acpl_list = acpl_list;
214 mw.G.acpl_hash = convert_object_list_to_hash( acpl_list );
215 sdump('D_AUTH', 'acpl_list = ' + js2JSON(acpl_list) + '\n');
219 'open-ils.search.config.copy_status.retrieve.all',
223 incr_progressmeter(document,'auth_meter',auth_meter_incr);
226 function ccs_list_callback(request) {
229 ccs_list = request.getResultObject();
230 if (!ccs_list) { throw('null result'); }
231 if (ccs_list.length == 0) { throw('zero length result'); }
233 alert('Login failed on ccs_list: ' + js2JSON(E)); enable_login_prompts(); return;
235 mw.G.ccs_list = ccs_list;
236 mw.G.ccs_hash = convert_object_list_to_hash( ccs_list );
237 sdump('D_AUTH', 'ccs_list = ' + js2JSON(ccs_list) + '\n');
241 'open-ils.search.actor.user.session',
242 [ mw.G['auth_ses'][0] ],
245 incr_progressmeter(document,'auth_meter',auth_meter_incr);
248 function user_callback(request) {
252 user = request.getResultObject();
253 if (!user) { throw('null result'); }
254 if (typeof(user) != 'object') { throw('result not an object' + user); }
256 alert('Login failed on user: ' + js2JSON(E)); enable_login_prompts(); return;
259 mw.G.user_ou = user.home_ou();
260 sdump('D_AUTH', "user: " + js2JSON(mw.G['user']) + '\n');
261 sdump('D_AUTH', "user_ou: " + js2JSON(mw.G['user_ou']) + '\n');
262 /*user_async_request(
264 'open-ils.search.actor.org_tree.retrieve',
268 /*user_async_request(
270 'open-ils.actor.org_types.retrieve',
271 [ mw.G.auth_ses[0] ],
275 incr_progressmeter(document,'auth_meter',auth_meter_incr);
278 function org_type_callback(request) {
279 var aout_list = globalOrgTypes;
281 aout_list = request.getResultObject();
282 if (!aout_list) { throw('null result'); }
283 if (typeof(aout_list) != 'object') { throw('result not an object' + aout_list); }
284 if (aout_list.length == 0) { throw('empty aout_list'); }
286 alert('Login failed on aout_list: ' + js2JSON(E)); enable_login_prompts(); return;
288 mw.G.aout_list = aout_list;
289 mw.G.aout_hash = convert_object_list_to_hash( aout_list );
290 mw.G.org_tree = globalOrgTree;
291 mw.G.org_tree_hash = convert_object_list_to_hash( flatten_ou_branch( globalOrgTree ) );
292 mw.G.user_ou = find_ou( mw.G.org_tree, mw.G.user_ou );
296 'open-ils.actor.org_unit.full_path.retrieve',
297 [ mw.G.auth_ses[0] ],
300 incr_progressmeter(document,'auth_meter',auth_meter_incr);
304 function my_orgs_callback(request) {
307 my_orgs = request.getResultObject();
308 if (!my_orgs) { throw('null result'); }
309 if (typeof(my_orgs) != 'object') { throw('result not an object' + my_orgs); }
310 if (my_orgs.length == 0) { throw('empty my_orgs'); }
312 alert('Login failed on my_orgs: ' + js2JSON(E)); enable_login_prompts(); return;
315 mw.G.my_orgs = my_orgs;
316 mw.G.my_orgs_hash = convert_object_list_to_hash( my_orgs );
317 sdump('D_AUTH','my_orgs = ' + js2JSON(my_orgs) + '\n');
318 mw.G.acpl_my_orgs = filter_list(
321 if ( typeof obj != 'object' ) return null;
322 if ( mw.G.my_orgs_hash[ obj.owning_lib() ] ) return obj;
325 mw.G.acpl_my_orgs_hash = convert_object_list_to_hash( mw.G.acpl_my_orgs );
326 //sdump('D_AUTH', 'my_orgs.length = ' + mw.G.my_orgs.length + ' other_orgs.length = ' + mw.G.other_orgs.length + '\n');
330 'open-ils.circ.stat_cat.actor.retrieve.all',
331 [ mw.G.auth_ses[0], mw.G.user_ou.id() ],
332 my_actsc_list_callback
335 incr_progressmeter(document,'auth_meter',auth_meter_incr);
338 function my_actsc_list_callback(request) {
341 actsc_list = request.getResultObject();
342 if (!actsc_list) { throw('null result'); }
343 if (actsc_list.length == 0) { throw('zero length result'); }
345 alert('Login failed on asc_list: ' + js2JSON(E)); enable_login_prompts(); return;
347 mw.G.actsc_list = actsc_list;
348 mw.G.actsc_hash = convert_object_list_to_hash( actsc_list );
349 sdump('D_AUTH', 'actsc_list = ' + js2JSON(actsc_list) + '\n');
351 incr_progressmeter(document,'auth_meter',auth_meter_incr);
359 mw.G['auth_ses'] = '';
361 enable_login_prompts();
362 incr_progressmeter(document,'auth_meter',-100);
366 function nice_shutdown() {
367 if (ses) { logoff(); ses.disconnect(); }