]> git.evergreen-ils.org Git - Evergreen.git/blob - Evergreen/staff_client/chrome/content/evergreen/auth/auth.js
typo, and checkin handling
[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         sdump('D_AUTH',arg_dump(arguments));
41         var np = document.getElementById('name_prompt');
42         np.addEventListener("keypress",handle_keypress,false);
43         np.focus();
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(); 
48         //G.sound.beep();
49         snd_logon();
50 }
51
52 function handle_keypress(ev) {
53         if (ev.keyCode && ev.keyCode == 13) {
54                 switch(this) {
55                         case document.getElementById('name_prompt') :
56                                 ev.preventDefault();
57                                 var pp = document.getElementById('password_prompt');
58                                 pp.focus(); pp.select();
59                         break;
60                         case document.getElementById('password_prompt') :
61                                 ev.preventDefault();
62                                 var sb = document.getElementById('submit_button');
63                                 sb.focus();
64                                 authenticate();
65                         break;
66                         default:
67                         break;
68                 }
69         }
70 }
71
72 function disable_login_prompts() {
73         sdump('D_AUTH',arg_dump(arguments));
74         disable_widgets(document,'password_prompt','name_prompt','submit_button');
75         G.sound.beep();
76 }
77
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');
86         G.sound.beep();
87 }
88
89 function authenticate() {
90         sdump('D_AUTH',arg_dump(arguments));
91         timer_init('cat');
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.
95         user_async_request(
96                 'open-ils.auth',
97                 'open-ils.auth.authenticate.init',
98                 [ name ],
99                 auth_init_callback
100         );
101 }
102
103 function auth_init_callback(request) {
104         sdump('D_AUTH',arg_dump(arguments));
105         var auth_init;
106         try {
107                 auth_init = request.getResultObject();
108                 if (!auth_init) { throw('null result'); }
109         } catch(E) {
110                 alert('Login failed on auth_init: ' + js2JSON(E)); 
111                 if (!debug_ignore_auth_failures) {
112                         enable_login_prompts(); return;
113                 }
114         }
115
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;
119
120         user_async_request(
121                 'open-ils.auth',
122                 'open-ils.auth.authenticate.complete',
123                 [ name, hex_md5(auth_init + hex_md5(pw)) ],
124                 auth_ses_callback
125         );
126         incr_progressmeter(document,'auth_meter',auth_meter_incr);
127 }
128
129 function auth_ses_callback(request) {
130         sdump('D_AUTH',arg_dump(arguments));
131         var auth_ses;
132         try {
133                 auth_ses = request.getResultObject();
134                 if (!auth_ses) { throw('null result'); }
135                 if (auth_ses == 0) { throw('0 result'); }
136         } catch(E) {
137                 alert('Login failed on auth_ses: ' + js2JSON(E)); 
138                 if (!debug_ignore_auth_failures) {
139                         enable_login_prompts(); return;
140                 }
141         }
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');
144
145         //'open-ils.actor.user.profiles.retrieve',
146         user_async_request(
147                 'open-ils.actor',
148                 'open-ils.actor.groups.retrieve',
149                 [],
150                 ap_list_callback
151         );
152         incr_progressmeter(document,'auth_meter',auth_meter_incr);
153 }
154
155 function ap_list_callback(request) {
156         sdump('D_AUTH',arg_dump(arguments));
157         var ap_list;
158         try {
159                 ap_list = request.getResultObject();
160                 if (!ap_list) { throw('null result'); }
161                 if (ap_list.length == 0) { throw('zero length result'); }
162         } catch(E) {
163                 alert('Login failed on ap_list: ' + js2JSON(E)); 
164                 if (!debug_ignore_auth_failures) {
165                         enable_login_prompts(); return;
166                 }
167         }
168         mw.G.ap_list = ap_list;
169         mw.G.ap_hash = convert_object_list_to_hash( ap_list );
170
171         user_async_request(
172                 'open-ils.actor',
173                 'open-ils.actor.user.ident_types.retrieve',
174                 [],
175                 cit_list_callback
176         );
177         incr_progressmeter(document,'auth_meter',auth_meter_incr);
178 }
179
180 function cit_list_callback(request) {
181         sdump('D_AUTH',arg_dump(arguments));
182         var cit_list;
183         try {
184                 cit_list = request.getResultObject();
185                 if (!cit_list) { throw('null result'); }
186                 if (cit_list.length == 0) { throw('zero length result'); }
187         } catch(E) {
188                 alert('Login failed on cit_list: ' + js2JSON(E)); 
189                 if (!debug_ignore_auth_failures) {
190                         enable_login_prompts(); return;
191                 }
192         }
193         mw.G.cit_list = cit_list;
194         mw.G.cit_hash = convert_object_list_to_hash( cit_list );
195         
196         user_async_request(
197                 'open-ils.actor',
198                 'open-ils.actor.standings.retrieve',
199                 [],
200                 cst_list_callback
201         );
202
203         incr_progressmeter(document,'auth_meter',auth_meter_incr);
204 }
205
206 function cst_list_callback(request) {
207         sdump('D_AUTH',arg_dump(arguments));
208         var cst_list;
209         try {
210                 cst_list = request.getResultObject();
211                 if (!cst_list) { throw('null result'); }
212                 if (cst_list.length == 0) { throw('zero length result'); }
213         } catch(E) {
214                 alert('Login failed on cst_list: ' + js2JSON(E)); 
215                 if (!debug_ignore_auth_failures) {
216                         enable_login_prompts(); return;
217                 }
218         }
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');
222
223         user_async_request(
224                 'open-ils.search',
225                 'open-ils.search.config.copy_location.retrieve.all',
226                 [],
227                 acpl_list_callback
228         );
229         incr_progressmeter(document,'auth_meter',auth_meter_incr);
230
231 }
232
233 function acpl_list_callback(request) {
234         sdump('D_AUTH',arg_dump(arguments));
235         var acpl_list;
236         try {
237                 acpl_list = request.getResultObject();
238                 if (!acpl_list) { throw('null result'); }
239                 if (acpl_list.length == 0) { throw('zero length result'); }
240         } catch(E) {
241                 alert('Login failed on acpl_list: ' + js2JSON(E)); 
242                 if (!debug_ignore_auth_failures) {
243                         enable_login_prompts(); return;
244                 }
245         }
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');
249
250         user_async_request(
251                 'open-ils.search',
252                 'open-ils.search.config.copy_status.retrieve.all',
253                 [],
254                 ccs_list_callback
255         );
256         incr_progressmeter(document,'auth_meter',auth_meter_incr);
257 }
258
259 function ccs_list_callback(request) {
260         sdump('D_AUTH',arg_dump(arguments));
261         var ccs_list;
262         try {
263                 ccs_list = request.getResultObject();
264                 if (!ccs_list) { throw('null result'); }
265                 if (ccs_list.length == 0) { throw('zero length result'); }
266         } catch(E) {
267                 alert('Login failed on ccs_list: ' + js2JSON(E)); 
268                 if (!debug_ignore_auth_failures) {
269                         enable_login_prompts(); return;
270                 }
271         }
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');
275
276         user_async_request(
277                 'open-ils.search',
278                 'open-ils.search.actor.user.session',
279                 [ mw.G['auth_ses'][0] ],
280                 user_callback
281         );
282         incr_progressmeter(document,'auth_meter',auth_meter_incr);
283 }
284
285 function user_callback(request) {
286         sdump('D_AUTH',arg_dump(arguments));
287         var user;
288         var user_ou;
289         try {
290                 user = request.getResultObject();
291                 if (!user) { throw('null result'); }
292                 if (typeof(user) != 'object') { throw('result not an object' + user); }
293         } catch(E) {
294                 alert('Login failed on user: ' + js2JSON(E)); 
295                 if (!debug_ignore_auth_failures) {
296                         enable_login_prompts(); return;
297                 }
298         }
299         mw.G.user = user;
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(
304                 'open-ils.search',
305                 'open-ils.search.actor.org_tree.retrieve',
306                 [],
307                 org_tree_callback
308         );*/
309         /*user_async_request(
310                 'open-ils.actor',
311                 'open-ils.actor.org_types.retrieve',
312                 [ mw.G.auth_ses[0] ],
313                 org_type_callback
314         );*/
315         org_type_callback();
316         incr_progressmeter(document,'auth_meter',auth_meter_incr);
317 }
318
319 function org_type_callback(request) {
320         sdump('D_AUTH',arg_dump(arguments));
321         var aout_list = globalOrgTypes;
322         /*try {
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'); }
327         } catch(E) {
328                 alert('Login failed on aout_list: ' + js2JSON(E)); enable_login_prompts(); return;
329         }*/
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 );
335
336         user_async_request(
337                 'open-ils.actor',
338                 'open-ils.actor.org_unit.full_path.retrieve',
339                 [ mw.G.auth_ses[0] ],
340                 my_orgs_callback
341         );
342         incr_progressmeter(document,'auth_meter',auth_meter_incr);
343
344 }
345
346 function my_orgs_callback(request) {
347         sdump('D_AUTH',arg_dump(arguments));
348         var my_orgs;
349         try {
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'); }
354         } catch(E) {
355                 alert('Login failed on my_orgs: ' + js2JSON(E)); 
356                 if (!debug_ignore_auth_failures) {
357                         enable_login_prompts(); return;
358                 }
359         }
360
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( 
365                 mw.G.acpl_list, 
366                 function (obj) {
367                         if ( typeof obj != 'object' ) return null;
368                         if ( mw.G.my_orgs_hash[ obj.owning_lib() ] ) return obj;
369                 }
370         );
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');
373
374         user_async_request(
375                 'open-ils.circ',
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
379         );
380
381         incr_progressmeter(document,'auth_meter',auth_meter_incr);
382 }
383
384 function my_actsc_list_callback(request) {
385         sdump('D_AUTH',arg_dump(arguments));
386         var actsc_list;
387         try {
388                 actsc_list = request.getResultObject();
389                 if (!actsc_list) { throw('null result'); }
390                 if (actsc_list.length == 0) { throw('zero length result'); }
391         } catch(E) {
392                 alert('Login failed on actsc_list: ' + js2JSON(E)); 
393                 if (!debug_ignore_auth_failures) {
394                         enable_login_prompts(); return;
395                 }
396         }
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');
400
401         incr_progressmeter(document,'auth_meter',auth_meter_incr);
402
403         spawn_main();
404
405         mw.minimize();
406
407 }
408
409
410 function logoff() {
411         sdump('D_AUTH',arg_dump(arguments));
412         mw.G['auth_ses'] = '';
413         close_all_windows();
414         enable_login_prompts();
415         incr_progressmeter(document,'auth_meter',-100);
416         snd_logoff();
417 }
418
419 function nice_shutdown() {
420         sdump('D_AUTH',arg_dump(arguments));
421         if (ses) { logoff(); ses.disconnect(); }
422         snd_exit;
423         close_all_windows();
424         window.close();
425 }
426