]> git.evergreen-ils.org Git - Evergreen.git/blob - Evergreen/staff_client/chrome/content/evergreen/auth/auth.js
option for blasting through (ignoring) auth errors on logon. Minimize the auth window.
[Evergreen.git] / Evergreen / staff_client / chrome / content / evergreen / auth / auth.js
1 var G = {}; // the master Global variable
2
3 var debug_ignore_auth_failures = false;
4
5 G['main_window'] = self;
6 G['win_list'] = [];
7 G['appshell_list'] = [];
8 G['doc_list'] = [];
9 G['window_name_increment'] = 0;
10 G['auth_ses'] = '';
11 G['user_ou'] = '';
12 G['main_test_variable'] = 'Hello World';
13 G['org_tree'] = '';
14 G['my_orgs'] = [];
15 G['my_orgs_hash'] = {};
16 G['fieldmap'] = '';
17 G['patrons'] = {};
18
19 G['ap_list'] = []; // actor::profile
20 G['ap_hash'] = {};
21 G['cit_list'] = []; // config::identification_type
22 G['cit_hash'] = {};
23 G['cst_list'] = []; // config::standing
24 G['cst_hash'] = {};
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
28 G['aout_hash'] = {};
29 G['ccs_list'] = []; // config::copy_status
30 G['ccs_hash'] = {};
31 G['asc_list'] = []; // asset::stat_cat
32 G['actsc_list'] = []; // actor::stat_cat
33 G['actsc_hash']; // actor::stat_cat
34
35 var mw = G['main_window'];
36 var auth_meter_incr = 10;
37
38 function auth_init() {
39         sdump('D_AUTH','TESTING: auth.js: ' + mw.G['main_test_variable'] + '\n');
40         var np = document.getElementById('name_prompt');
41         np.addEventListener("keypress",handle_keypress,false);
42         np.focus();
43         var pp = document.getElementById('password_prompt');
44         pp.addEventListener("keypress",handle_keypress,false);
45         self.addEventListener("unload",nice_shutdown,false);
46         G['sound'] = xp_sound_init(); 
47         //G.sound.beep();
48         snd_logon();
49 }
50
51 function handle_keypress(ev) {
52         if (ev.keyCode && ev.keyCode == 13) {
53                 switch(this) {
54                         case document.getElementById('name_prompt') :
55                                 ev.preventDefault();
56                                 var pp = document.getElementById('password_prompt');
57                                 pp.focus(); pp.select();
58                         break;
59                         case document.getElementById('password_prompt') :
60                                 ev.preventDefault();
61                                 var sb = document.getElementById('submit_button');
62                                 sb.focus();
63                                 authenticate();
64                         break;
65                         default:
66                         break;
67                 }
68         }
69 }
70
71 function disable_login_prompts() {
72         disable_widgets(document,'password_prompt','name_prompt','submit_button');
73         G.sound.beep();
74 }
75
76 function enable_login_prompts() {
77         enable_widgets(document,'password_prompt','name_prompt','submit_button');
78         document.getElementById('password_prompt').value = '';
79         var np = document.getElementById('name_prompt');
80         np.focus(); np.select();
81         document.getElementById('auth_meter').value = 0;
82         document.getElementById('auth_meter').setAttribute('real', '0.0');
83         G.sound.beep();
84 }
85
86 function authenticate() {
87         timer_init('cat');
88         var name = document.getElementById('name_prompt').value;
89         if (name.length == 0) { enable_login_prompts(); return; }
90         // Talk to the system and authenticate the user.
91         user_async_request(
92                 'open-ils.auth',
93                 'open-ils.auth.authenticate.init',
94                 [ name ],
95                 auth_init_callback
96         );
97 }
98
99 function auth_init_callback(request) {
100         var auth_init;
101         try {
102                 auth_init = request.getResultObject();
103                 if (!auth_init) { throw('null result'); }
104         } catch(E) {
105                 alert('Login failed on auth_init: ' + js2JSON(E)); 
106                 if (!debug_ignore_auth_failures) {
107                         enable_login_prompts(); return;
108                 }
109         }
110
111         sdump( 'D_AUTH', 'D_AUTH_INIT: ' + typeof(auth_init) + ' : ' + auth_init + '\n');
112         var name = document.getElementById('name_prompt').value;
113         var pw = document.getElementById('password_prompt').value;
114
115         user_async_request(
116                 'open-ils.auth',
117                 'open-ils.auth.authenticate.complete',
118                 [ name, hex_md5(auth_init + hex_md5(pw)) ],
119                 auth_ses_callback
120         );
121         incr_progressmeter(document,'auth_meter',auth_meter_incr);
122 }
123
124 function auth_ses_callback(request) {
125         var auth_ses;
126         try {
127                 auth_ses = request.getResultObject();
128                 if (!auth_ses) { throw('null result'); }
129                 if (auth_ses == 0) { throw('0 result'); }
130         } catch(E) {
131                 alert('Login failed on auth_ses: ' + js2JSON(E)); 
132                 if (!debug_ignore_auth_failures) {
133                         enable_login_prompts(); return;
134                 }
135         }
136         mw.G.auth_ses = [ auth_ses ];
137         sdump( 'D_AUTH', 'D_AUTH_SES: ' + typeof(mw.G['auth_ses'][0]) + ' : ' + mw.G['auth_ses'][0] + '\n');
138
139         user_async_request(
140                 'open-ils.actor',
141                 'open-ils.actor.user.profiles.retrieve',
142                 [],
143                 ap_list_callback
144         );
145         incr_progressmeter(document,'auth_meter',auth_meter_incr);
146 }
147
148 function ap_list_callback(request) {
149         var ap_list;
150         try {
151                 ap_list = request.getResultObject();
152                 if (!ap_list) { throw('null result'); }
153                 if (ap_list.length == 0) { throw('zero length result'); }
154         } catch(E) {
155                 alert('Login failed on ap_list: ' + js2JSON(E)); 
156                 if (!debug_ignore_auth_failures) {
157                         enable_login_prompts(); return;
158                 }
159         }
160         mw.G.ap_list = ap_list;
161         mw.G.ap_hash = convert_object_list_to_hash( ap_list );
162
163         user_async_request(
164                 'open-ils.actor',
165                 'open-ils.actor.user.ident_types.retrieve',
166                 [],
167                 cit_list_callback
168         );
169         incr_progressmeter(document,'auth_meter',auth_meter_incr);
170 }
171
172 function cit_list_callback(request) {
173         var cit_list;
174         try {
175                 cit_list = request.getResultObject();
176                 if (!cit_list) { throw('null result'); }
177                 if (cit_list.length == 0) { throw('zero length result'); }
178         } catch(E) {
179                 alert('Login failed on cit_list: ' + js2JSON(E)); 
180                 if (!debug_ignore_auth_failures) {
181                         enable_login_prompts(); return;
182                 }
183         }
184         mw.G.cit_list = cit_list;
185         mw.G.cit_hash = convert_object_list_to_hash( cit_list );
186         
187         user_async_request(
188                 'open-ils.actor',
189                 'open-ils.actor.standings.retrieve',
190                 [],
191                 cst_list_callback
192         );
193
194         incr_progressmeter(document,'auth_meter',auth_meter_incr);
195 }
196
197 function cst_list_callback(request) {
198         var cst_list;
199         try {
200                 cst_list = request.getResultObject();
201                 if (!cst_list) { throw('null result'); }
202                 if (cst_list.length == 0) { throw('zero length result'); }
203         } catch(E) {
204                 alert('Login failed on cst_list: ' + js2JSON(E)); 
205                 if (!debug_ignore_auth_failures) {
206                         enable_login_prompts(); return;
207                 }
208         }
209         mw.G.cst_list = cst_list;
210         mw.G.cst_hash = convert_object_list_to_hash( cst_list );
211         sdump('D_AUTH', 'cst_list = ' + js2JSON(cst_list) + '\n');
212
213         user_async_request(
214                 'open-ils.search',
215                 'open-ils.search.config.copy_location.retrieve.all',
216                 [],
217                 acpl_list_callback
218         );
219         incr_progressmeter(document,'auth_meter',auth_meter_incr);
220
221 }
222
223 function acpl_list_callback(request) {
224         var acpl_list;
225         try {
226                 acpl_list = request.getResultObject();
227                 if (!acpl_list) { throw('null result'); }
228                 if (acpl_list.length == 0) { throw('zero length result'); }
229         } catch(E) {
230                 alert('Login failed on acpl_list: ' + js2JSON(E)); 
231                 if (!debug_ignore_auth_failures) {
232                         enable_login_prompts(); return;
233                 }
234         }
235         mw.G.acpl_list = acpl_list;
236         mw.G.acpl_hash = convert_object_list_to_hash( acpl_list );
237         sdump('D_AUTH', 'acpl_list = ' + js2JSON(acpl_list) + '\n');
238
239         user_async_request(
240                 'open-ils.search',
241                 'open-ils.search.config.copy_status.retrieve.all',
242                 [],
243                 ccs_list_callback
244         );
245         incr_progressmeter(document,'auth_meter',auth_meter_incr);
246 }
247
248 function ccs_list_callback(request) {
249         var ccs_list;
250         try {
251                 ccs_list = request.getResultObject();
252                 if (!ccs_list) { throw('null result'); }
253                 if (ccs_list.length == 0) { throw('zero length result'); }
254         } catch(E) {
255                 alert('Login failed on ccs_list: ' + js2JSON(E)); 
256                 if (!debug_ignore_auth_failures) {
257                         enable_login_prompts(); return;
258                 }
259         }
260         mw.G.ccs_list = ccs_list;
261         mw.G.ccs_hash = convert_object_list_to_hash( ccs_list );
262         sdump('D_AUTH', 'ccs_list = ' + js2JSON(ccs_list) + '\n');
263
264         user_async_request(
265                 'open-ils.search',
266                 'open-ils.search.actor.user.session',
267                 [ mw.G['auth_ses'][0] ],
268                 user_callback
269         );
270         incr_progressmeter(document,'auth_meter',auth_meter_incr);
271 }
272
273 function user_callback(request) {
274         var user;
275         var user_ou;
276         try {
277                 user = request.getResultObject();
278                 if (!user) { throw('null result'); }
279                 if (typeof(user) != 'object') { throw('result not an object' + user); }
280         } catch(E) {
281                 alert('Login failed on user: ' + js2JSON(E)); 
282                 if (!debug_ignore_auth_failures) {
283                         enable_login_prompts(); return;
284                 }
285         }
286         mw.G.user = user;
287         mw.G.user_ou = user.home_ou();
288         sdump('D_AUTH', "user: " + js2JSON(mw.G['user']) + '\n');
289         sdump('D_AUTH', "user_ou: " + js2JSON(mw.G['user_ou']) + '\n');
290         /*user_async_request(
291                 'open-ils.search',
292                 'open-ils.search.actor.org_tree.retrieve',
293                 [],
294                 org_tree_callback
295         );*/
296         /*user_async_request(
297                 'open-ils.actor',
298                 'open-ils.actor.org_types.retrieve',
299                 [ mw.G.auth_ses[0] ],
300                 org_type_callback
301         );*/
302         org_type_callback();
303         incr_progressmeter(document,'auth_meter',auth_meter_incr);
304 }
305
306 function org_type_callback(request) {
307         var aout_list = globalOrgTypes;
308         /*try {
309                 aout_list = request.getResultObject();
310                 if (!aout_list) { throw('null result'); }
311                 if (typeof(aout_list) != 'object') { throw('result not an object' + aout_list); }
312                 if (aout_list.length == 0) { throw('empty aout_list'); }
313         } catch(E) {
314                 alert('Login failed on aout_list: ' + js2JSON(E)); enable_login_prompts(); return;
315         }*/
316         mw.G.aout_list = aout_list;
317         mw.G.aout_hash = convert_object_list_to_hash( aout_list );
318         mw.G.org_tree = globalOrgTree;
319         mw.G.org_tree_hash = convert_object_list_to_hash( flatten_ou_branch( globalOrgTree ) );
320         mw.G.user_ou = find_ou( mw.G.org_tree, mw.G.user_ou );
321
322         user_async_request(
323                 'open-ils.actor',
324                 'open-ils.actor.org_unit.full_path.retrieve',
325                 [ mw.G.auth_ses[0] ],
326                 my_orgs_callback
327         );
328         incr_progressmeter(document,'auth_meter',auth_meter_incr);
329
330 }
331
332 function my_orgs_callback(request) {
333         var my_orgs;
334         try {
335                 my_orgs = request.getResultObject();
336                 if (!my_orgs) { throw('null result'); }
337                 if (typeof(my_orgs) != 'object') { throw('result not an object' + my_orgs); }
338                 if (my_orgs.length == 0) { throw('empty my_orgs'); }
339         } catch(E) {
340                 alert('Login failed on my_orgs: ' + js2JSON(E)); 
341                 if (!debug_ignore_auth_failures) {
342                         enable_login_prompts(); return;
343                 }
344         }
345
346         mw.G.my_orgs = my_orgs;
347         mw.G.my_orgs_hash = convert_object_list_to_hash( my_orgs );
348         sdump('D_AUTH','my_orgs = ' + js2JSON(my_orgs) + '\n');
349         mw.G.acpl_my_orgs = filter_list( 
350                 mw.G.acpl_list, 
351                 function (obj) {
352                         if ( typeof obj != 'object' ) return null;
353                         if ( mw.G.my_orgs_hash[ obj.owning_lib() ] ) return obj;
354                 }
355         );
356         mw.G.acpl_my_orgs_hash = convert_object_list_to_hash( mw.G.acpl_my_orgs );
357         //sdump('D_AUTH', 'my_orgs.length = ' + mw.G.my_orgs.length + '   other_orgs.length = ' + mw.G.other_orgs.length + '\n');
358
359         user_async_request(
360                 'open-ils.circ',
361                 'open-ils.circ.stat_cat.actor.retrieve.all',
362                 [ mw.G.auth_ses[0], mw.G.user_ou.id() ],
363                 my_actsc_list_callback
364         );
365
366         incr_progressmeter(document,'auth_meter',auth_meter_incr);
367 }
368
369 function my_actsc_list_callback(request) {
370         var actsc_list;
371         try {
372                 actsc_list = request.getResultObject();
373                 if (!actsc_list) { throw('null result'); }
374                 if (actsc_list.length == 0) { throw('zero length result'); }
375         } catch(E) {
376                 alert('Login failed on asc_list: ' + js2JSON(E)); 
377                 if (!debug_ignore_auth_failures) {
378                         enable_login_prompts(); return;
379                 }
380         }
381         mw.G.actsc_list = actsc_list;
382         mw.G.actsc_hash = convert_object_list_to_hash( actsc_list );
383         sdump('D_AUTH', 'actsc_list = ' + js2JSON(actsc_list) + '\n');
384
385         incr_progressmeter(document,'auth_meter',auth_meter_incr);
386
387         spawn_main();
388
389         mw.minimize();
390
391 }
392
393
394 function logoff() {
395         mw.G['auth_ses'] = '';
396         close_all_windows();
397         enable_login_prompts();
398         incr_progressmeter(document,'auth_meter',-100);
399         snd_logoff();
400 }
401
402 function nice_shutdown() {
403         if (ses) { logoff(); ses.disconnect(); }
404         snd_exit;
405         close_all_windows();
406         window.close();
407 }
408