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_per = 10;
33 function OpenILS_init() {
38 dump('TESTING: auth.js: ' + mw.G['main_test_variable'] + '\n');
39 var np = document.getElementById('name_prompt');
40 np.addEventListener("keypress",handle_keypress,false);
42 var pp = document.getElementById('password_prompt');
43 pp.addEventListener("keypress",handle_keypress,false);
44 self.addEventListener("unload",nice_shutdown,false);
45 G['sound'] = xp_sound_init();
50 function handle_keypress(ev) {
51 if (ev.keyCode && ev.keyCode == 13) {
53 case document.getElementById('name_prompt') :
55 var pp = document.getElementById('password_prompt');
56 pp.focus(); pp.select();
58 case document.getElementById('password_prompt') :
60 var sb = document.getElementById('submit_button');
70 function disable_login_prompts() {
71 disable_widgets('password_prompt','name_prompt','submit_button');
75 function enable_login_prompts() {
76 enable_widgets('password_prompt','name_prompt','submit_button');
77 document.getElementById('password_prompt').value = '';
78 var np = document.getElementById('name_prompt');
79 np.focus(); np.select();
80 document.getElementById('auth_meter').value = 0;
84 function authenticate() {
86 var name = document.getElementById('name_prompt').value;
87 if (name.length == 0) { enable_login_prompts(); return; }
88 // Talk to the system and authenticate the user.
91 'open-ils.auth.authenticate.init',
97 function auth_init_callback(request) {
100 auth_init = request.getResultObject();
101 if (!auth_init) { throw('null result'); }
103 alert('Login failed on auth_init: ' + js2JSON(E)); enable_login_prompts(); return;
106 dump( 'AUTH_INIT: ' + typeof(auth_init) + ' : ' + auth_init + '\n');
107 var name = document.getElementById('name_prompt').value;
108 var pw = document.getElementById('password_prompt').value;
112 'open-ils.auth.authenticate.complete',
113 [ name, hex_md5(auth_init + hex_md5(pw)) ],
116 document.getElementById('auth_meter').value += auth_meter_per;
119 function auth_ses_callback(request) {
122 auth_ses = request.getResultObject();
123 if (!auth_ses) { throw('null result'); }
124 if (auth_ses == 0) { throw('0 result'); }
126 alert('Login failed on auth_ses: ' + js2JSON(E)); enable_login_prompts(); return;
128 mw.G.auth_ses = [ auth_ses ];
129 dump( 'AUTH_SES: ' + typeof(mw.G['auth_ses'][0]) + ' : ' + mw.G['auth_ses'][0] + '\n');
133 'open-ils.actor.user.profiles.retrieve',
137 document.getElementById('auth_meter').value += auth_meter_per;
140 function ap_list_callback(request) {
143 ap_list = request.getResultObject();
144 if (!ap_list) { throw('null result'); }
145 if (ap_list.length == 0) { throw('zero length result'); }
147 alert('Login failed on ap_list: ' + js2JSON(E)); enable_login_prompts(); return;
149 mw.G.ap_list = ap_list;
150 mw.G.ap_hash = convert_object_list_to_hash( ap_list );
154 'open-ils.actor.user.ident_types.retrieve',
158 document.getElementById('auth_meter').value += auth_meter_per;
161 function cit_list_callback(request) {
164 cit_list = request.getResultObject();
165 if (!cit_list) { throw('null result'); }
166 if (cit_list.length == 0) { throw('zero length result'); }
168 alert('Login failed on cit_list: ' + js2JSON(E)); enable_login_prompts(); return;
170 mw.G.cit_list = cit_list;
171 mw.G.cit_hash = convert_object_list_to_hash( cit_list );
175 'open-ils.actor.standings.retrieve',
180 document.getElementById('auth_meter').value += auth_meter_per;
183 function cst_list_callback(request) {
186 cst_list = request.getResultObject();
187 if (!cst_list) { throw('null result'); }
188 if (cst_list.length == 0) { throw('zero length result'); }
190 alert('Login failed on cst_list: ' + js2JSON(E)); enable_login_prompts(); return;
192 mw.G.cst_list = cst_list;
193 mw.G.cst_hash = convert_object_list_to_hash( cst_list );
194 dump('cst_list = ' + js2JSON(cst_list) + '\n');
198 'open-ils.search.config.copy_location.retrieve.all',
202 document.getElementById('auth_meter').value += auth_meter_per;
206 function acpl_list_callback(request) {
209 acpl_list = request.getResultObject();
210 if (!acpl_list) { throw('null result'); }
211 if (acpl_list.length == 0) { throw('zero length result'); }
213 alert('Login failed on acpl_list: ' + js2JSON(E)); enable_login_prompts(); return;
215 mw.G.acpl_list = acpl_list;
216 mw.G.acpl_hash = convert_object_list_to_hash( acpl_list );
217 dump('acpl_list = ' + js2JSON(acpl_list) + '\n');
221 'open-ils.search.config.copy_status.retrieve.all',
225 document.getElementById('auth_meter').value += auth_meter_per;
228 function ccs_list_callback(request) {
231 ccs_list = request.getResultObject();
232 if (!ccs_list) { throw('null result'); }
233 if (ccs_list.length == 0) { throw('zero length result'); }
235 alert('Login failed on ccs_list: ' + js2JSON(E)); enable_login_prompts(); return;
237 mw.G.ccs_list = ccs_list;
238 mw.G.ccs_hash = convert_object_list_to_hash( ccs_list );
239 dump('ccs_list = ' + js2JSON(ccs_list) + '\n');
243 'open-ils.search.actor.user.session',
244 [ mw.G['auth_ses'][0] ],
247 document.getElementById('auth_meter').value += auth_meter_per;
250 function user_callback(request) {
254 user = request.getResultObject();
255 if (!user) { throw('null result'); }
256 if (typeof(user) != 'object') { throw('result not an object' + user); }
258 alert('Login failed on user: ' + js2JSON(E)); enable_login_prompts(); return;
261 mw.G.user_ou = user.home_ou();
262 dump("user: " + js2JSON(mw.G['user']) + '\n');
263 dump("user_ou: " + js2JSON(mw.G['user_ou']) + '\n');
264 /*user_async_request(
266 'open-ils.search.actor.org_tree.retrieve',
270 /*user_async_request(
272 'open-ils.actor.org_types.retrieve',
273 [ mw.G.auth_ses[0] ],
277 document.getElementById('auth_meter').value += auth_meter_per;
280 function org_type_callback(request) {
281 var aout_list = globalOrgTypes;
283 aout_list = request.getResultObject();
284 if (!aout_list) { throw('null result'); }
285 if (typeof(aout_list) != 'object') { throw('result not an object' + aout_list); }
286 if (aout_list.length == 0) { throw('empty aout_list'); }
288 alert('Login failed on aout_list: ' + js2JSON(E)); enable_login_prompts(); return;
290 mw.G.aout_list = aout_list;
291 mw.G.aout_hash = convert_object_list_to_hash( aout_list );
292 mw.G.org_tree = globalOrgTree;
293 mw.G.org_tree_hash = convert_object_list_to_hash( flatten_ou_branch( globalOrgTree ) );
294 mw.G.user_ou = find_ou( mw.G.org_tree, mw.G.user_ou );
298 'open-ils.actor.org_unit.full_path.retrieve',
299 [ mw.G.auth_ses[0] ],
302 document.getElementById('auth_meter').value += auth_meter_per;
306 function my_orgs_callback(request) {
309 my_orgs = request.getResultObject();
310 if (!my_orgs) { throw('null result'); }
311 if (typeof(my_orgs) != 'object') { throw('result not an object' + my_orgs); }
312 if (my_orgs.length == 0) { throw('empty my_orgs'); }
314 alert('Login failed on my_orgs: ' + js2JSON(E)); enable_login_prompts(); return;
317 mw.G.my_orgs = my_orgs;
318 mw.G.my_orgs_hash = convert_object_list_to_hash( my_orgs );
319 dump('my_orgs = ' + js2JSON(my_orgs) + '\n');
320 mw.G.acpl_my_orgs = filter_list(
323 if ( typeof obj != 'object' ) return null;
324 if ( mw.G.my_orgs_hash[ obj.owning_lib() ] ) return obj;
327 mw.G.acpl_my_orgs_hash = convert_object_list_to_hash( mw.G.acpl_my_orgs );
328 //dump('my_orgs.length = ' + mw.G.my_orgs.length + ' other_orgs.length = ' + mw.G.other_orgs.length + '\n');
332 'open-ils.circ.stat_cat.actor.retrieve.all',
333 [ mw.G.auth_ses[0], mw.G.user_ou.id() ],
334 my_actsc_list_callback
337 document.getElementById('auth_meter').value += auth_meter_per;
340 function my_actsc_list_callback(request) {
343 actsc_list = request.getResultObject();
344 if (!actsc_list) { throw('null result'); }
345 if (actsc_list.length == 0) { throw('zero length result'); }
347 alert('Login failed on asc_list: ' + js2JSON(E)); enable_login_prompts(); return;
349 mw.G.actsc_list = actsc_list;
350 mw.G.actsc_hash = convert_object_list_to_hash( actsc_list );
351 dump('actsc_list = ' + js2JSON(actsc_list) + '\n');
353 document.getElementById('auth_meter').value += auth_meter_per;
360 function spawn_main() {
362 var w = new_window('chrome://evergreen/content/evergreen/main.xul');
363 if (!w) { throw('window ref == null'); }
365 w.document.title = mw.G.user.usrname() + '@' + mw.G.user_ou.name();
367 alert('Hrmm. ' + pretty_print( js2JSON(E) ) );
370 alert('Login failed on new_window: ' + js2JSON(E)); enable_login_prompts(); return;
372 document.getElementById('auth_meter').value += auth_meter_per;
376 mw.G['auth_ses'] = '';
378 enable_login_prompts();
382 function nice_shutdown() {
383 if (ses) { logoff(); ses.disconnect(); }
389 function test_mvc () {
390 var w = new_window('chrome://evergreen/content/blank.xul');
392 w.addEventListener('load',test_mvc2,false);
395 function test_mvc2(ev) {
399 var cm = user_request(
401 'open-ils.search.asset.copy.batch.retrieve',
404 dump('cm = ' + js2JSON(cm) + '\n');
408 var cv = new CopyDisplayXULView();
411 var cnv = doc.getElementById('canvas');
416 var cc = new CopyController();
420 cc.render_active_view();