1 dump('entering auth/controller.js\n');
4 if (typeof auth == 'undefined') auth = {};
5 auth.controller = function (params) {
6 JSAN.use('util.error'); this.error = new util.error();
7 this.w = params.window;
12 auth.controller.prototype = {
14 'init' : function () {
16 var obj = this; // so the 'this' in event handlers don't confuse us
19 JSAN.use('OpenILS.data');
20 obj.data = new OpenILS.data(); obj.data.init({'via':'stash'});
23 JSAN.use('util.controller'); obj.controller = new util.controller();
39 'cmd_standalone_import' : [
42 obj.standalone_import();
45 'cmd_standalone_export' : [
48 obj.standalone_export();
54 obj.debug('clear_cache');
60 obj.debug('js_console');
75 'cmd_close_window' : [
84 obj.test_server( obj.controller.view.server_prompt.value );
92 obj.controller.view.cmd_ssl_exception.setAttribute('hidden','true');
93 var x = new XMLHttpRequest();
94 x.open("GET",'chrome://pippki/content/exceptionDialog.xul',false);
96 obj.controller.view.cmd_ssl_exception.setAttribute('hidden','false');
98 obj.controller.view.cmd_ssl_exception.setAttribute('hidden','true');
103 'cmd_ssl_exception' : [
107 'chrome://pippki/content/exceptionDialog.xul',
109 'chrome,centerscreen,modal',
111 'location' : 'https://' + obj.controller.view.server_prompt.value,
112 'prefetchCert' : true
115 obj.test_server( obj.controller.view.server_prompt.value );
126 'password_prompt' : [
132 function(e) { return function() {} }
136 function(e) { return function() {} }
140 function(e) { return function() {
145 function(e) { return function() {
147 JSAN.use('util.widgets'); util.widgets.remove_children(e);
148 var x = document.createElement('description');
151 && obj.data.ws_info[ obj.controller.view.server_prompt.value ]) {
152 var ws = obj.data.ws_info[ obj.controller.view.server_prompt.value ];
154 document.createTextNode(
155 ws.name /*+ ' @ ' + ws.lib_shortname*/
158 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
159 JSAN.use('util.file'); var file = new util.file('last_ws_server');
160 file.set_object(obj.controller.view.server_prompt.value);
164 document.createTextNode(
165 document.getElementById('authStrings').getString('staff.auth.controller.not_configured')
176 function(e) { return function() {
183 obj.controller.view.name_prompt.focus();
185 function handle_keypress(ev) {
187 if (ev.keyCode && ev.keyCode == 13) {
189 case obj.controller.view.server_prompt:
191 obj.controller.view.name_prompt.focus(); obj.controller.view.name_prompt.select();
193 case obj.controller.view.name_prompt:
195 obj.controller.view.password_prompt.focus(); obj.controller.view.password_prompt.select();
197 case obj.controller.view.password_prompt:
199 obj.controller.view.submit_button.focus();
210 obj.controller.view.server_prompt.addEventListener(
213 obj.test_server(ev.target.value);
214 obj.controller.render('ws_deck');
219 // This talks to our ILS
220 JSAN.use('auth.session');
221 obj.session = new auth.session(obj.controller.view);
223 obj.controller.render();
224 obj.test_server( obj.controller.view.server_prompt.value );
225 obj.controller.render('ws_deck');
227 if (typeof this.on_init == 'function') {
228 this.error.sdump('D_AUTH','auth.controller.on_init()\n');
233 'test_server' : function(url) {
236 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
237 JSAN.use('util.file'); var file = new util.file('last_ws_server');
238 if (file._file.exists()) {
239 url = file.get_object(); file.close();
240 obj.controller.view.server_prompt.value = url;
243 obj.controller.view.submit_button.disabled = true;
244 obj.controller.view.server_prompt.disabled = true;
245 var s = document.getElementById('status');
246 s.setAttribute('value', document.getElementById('authStrings').getString('staff.auth.controller.testing_hostname'));
247 s.setAttribute('style','color: orange;');
248 document.getElementById('version').value = '';
250 s.setAttribute('value', document.getElementById('authStrings').getString('staff.auth.controller.prompt_hostname'));
251 s.setAttribute('style','color: red;');
252 obj.controller.view.server_prompt.disabled = false;
253 obj.controller.view.server_prompt.focus();
257 if ( ! url.match(/^http:\/\//) ) url = 'http://' + url;
258 var x = new XMLHttpRequest();
259 dump('server url = ' + url + '\n');
260 x.open("GET",url,true);
261 x.onreadystatechange = function() {
263 if (x.readyState != 4) return;
264 s.setAttribute('value', document.getElementById('authStrings').getFormattedString('staff.auth.controller.status', [x.status, x.statusText]));
265 if (x.status == 200) {
266 s.setAttribute('style','color: green;');
268 s.setAttribute('style','color: red;');
270 obj.test_version(url);
272 obj.controller.view.server_prompt.disabled = false;
273 obj.controller.view.server_prompt.focus();
274 s.setAttribute('value', document.getElementById('authStrings').getString('staff.auth.controller.error_hostname'));
275 s.setAttribute('style','color: red;');
276 obj.error.sdump('D_ERROR',E);
281 s.setAttribute('value', document.getElementById('authStrings').getString('staff.auth.controller.error_hostname'));
282 s.setAttribute('style','color: brown;');
283 obj.error.sdump('D_ERROR',E);
284 obj.controller.view.server_prompt.disabled = false;
285 obj.controller.view.server_prompt.focus();
289 'test_version' : function(url) {
291 var s = document.getElementById('version');
292 s.setAttribute('value', document.getElementById('authStrings').getString('staff.auth.controller.testing_version'));
293 s.setAttribute('style','color: orange;');
295 var x = new XMLHttpRequest();
296 var url2 = url + '/xul/server/';
297 dump('version url = ' + url2 + '\n');
298 x.open("GET",url2,true);
299 x.onreadystatechange = function() {
301 if (x.readyState != 4) return;
302 s.setAttribute('value', document.getElementById('authStrings').getFormattedString('staff.auth.controller.status', [x.status, x.statusText]));
303 if (x.status == 200) {
304 s.setAttribute('style','color: green;');
305 obj.controller.view.submit_button.disabled = false;
307 s.setAttribute('style','color: red;');
308 obj.test_upgrade_instructions(url);
310 obj.controller.view.server_prompt.disabled = false;
312 s.setAttribute('value', document.getElementById('authStrings').getString('staff.auth.controller.error_version'));
313 s.setAttribute('style','color: red;');
314 obj.error.sdump('D_ERROR',E);
315 obj.controller.view.server_prompt.disabled = false;
320 s.setAttribute('value', document.getElementById('authStrings').getString('staff.auth.controller.error_version'));
321 s.setAttribute('style','color: brown;');
322 obj.error.sdump('D_ERROR',E);
323 obj.controller.view.server_prompt.disabled = false;
327 'test_upgrade_instructions' : function(url) {
330 var x = new XMLHttpRequest();
331 var url2 = url + '/xul/versions.html';
332 dump('upgrade url = ' + url2 + '\n');
333 x.open("GET",url2,true);
334 x.onreadystatechange = function() {
336 if (x.readyState != 4) return;
337 if (x.status == 200) {
338 window.open('data:text/html,'+window.escape(x.responseText),'upgrade','chrome,resizable,modal,centered');
340 alert(document.getElementById('authStrings').getString('staff.auth.controller.version_mismatch'));
342 obj.controller.view.server_prompt.disabled = false;
344 obj.error.sdump('D_ERROR',E);
345 obj.controller.view.server_prompt.disabled = false;
350 obj.error.sdump('D_ERROR',E);
351 obj.controller.view.server_prompt.disabled = false;
355 'login' : function() {
359 this.error.sdump('D_AUTH',
360 document.getElementById('authStrings').getFormattedString(
361 'staff.auth.controller.error_login', [
362 this.controller.view.name_prompt.value,
363 this.controller.view.password_prompt.value,
364 this.controller.view.server_prompt.value
368 this.controller.view.server_prompt.disabled = true;
369 this.controller.view.name_prompt.disabled = true;
370 this.controller.view.password_prompt.disabled = true;
371 this.controller.view.submit_button.disabled = true;
372 XML_HTTP_SERVER = this.controller.view.server_prompt.value;
376 if (typeof this.on_login == 'function') {
377 this.error.sdump('D_AUTH','auth.controller.session.on_init = ' +
378 'auth.controller.on_login\n');
379 this.session.on_init = this.on_login;
380 this.session.on_error = function() { obj.logoff(); };
386 var error = '!! ' + E + '\n';
387 this.error.sdump('D_ERROR',error);
390 if (E == 'open-ils.auth.authenticate.init returned false\n') {
391 this.controller.view.server_prompt.focus();
392 this.controller.view.server_prompt.select();
395 if (typeof this.on_login_error == 'function') {
396 this.error.sdump('D_AUTH','auth.controller.on_login_error()\n');
397 this.on_login_error(E);
403 'standalone' : function() {
406 if (typeof this.on_standalone == 'function') {
410 var error = '!! ' + E + '\n';
411 obj.error.sdump('D_ERROR',error);
416 'standalone_import' : function() {
419 if (typeof this.on_standalone_import == 'function') {
420 obj.on_standalone_import();
423 var error = '!! ' + E + '\n';
424 obj.error.sdump('D_ERROR',error);
429 'standalone_export' : function() {
432 if (typeof this.on_standalone_export == 'function') {
433 obj.on_standalone_export();
436 var error = '!! ' + E + '\n';
437 obj.error.sdump('D_ERROR',error);
442 'debug' : function(action) {
445 if (typeof this.on_debug == 'function') {
446 obj.on_debug(action);
449 var error = '!! ' + E + '\n';
450 obj.error.sdump('D_ERROR',error);
455 'logoff' : function() {
457 this.error.sdump('D_AUTH','logoff' + this.w + '\n');
458 this.controller.view.progress_bar.value = 0;
459 this.controller.view.progress_bar.setAttribute('real','0.0');
460 this.controller.view.submit_button.disabled = false;
461 this.controller.view.password_prompt.disabled = false;
462 this.controller.view.password_prompt.value = '';
463 this.controller.view.name_prompt.disabled = false;
464 this.controller.view.name_prompt.focus();
465 this.controller.view.name_prompt.select();
466 this.controller.view.server_prompt.disabled = false;
468 var windowManager = Components.classes["@mozilla.org/appshell/window-mediator;1"].getService();
469 var windowManagerInterface = windowManager.QueryInterface(Components.interfaces.nsIWindowMediator);
470 var enumerator = windowManagerInterface.getEnumerator(null);
472 var w; // close all other windows
473 while ( w = enumerator.getNext() ) {
474 if (w != window) w.close();
477 this.controller.render('ws_deck');
479 this.session.close();
481 /* FIXME - need some locking or object destruction for the async tests */
482 /* this.test_server( this.controller.view.server_prompt.value ); */
484 if (typeof this.on_logoff == 'function') {
485 this.error.sdump('D_AUTH','auth.controller.on_logoff()\n');
490 'close' : function() {
492 this.error.sdump('D_AUTH','close' + this.w + '\n');
494 if (window.confirm(document.getElementById('authStrings').getString('staff.auth.controller.confirm_close'))) {
496 this.w.close(); /* Probably won't go any further */
498 if (typeof this.on_close == 'function') {
499 this.error.sdump('D_AUTH','auth.controller.on_close()\n');
507 dump('exiting auth/controller.js\n');