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() {} }
134 'apply_locale_btn' : [
136 function(e) { return function() {} }
140 function(e) { return function() {} }
144 function(e) { return function() {
149 function(e) { return function() {
151 JSAN.use('util.widgets'); util.widgets.remove_children(e);
152 var x = document.createElement('description');
155 && obj.data.ws_info[ obj.controller.view.server_prompt.value ]) {
156 var ws = obj.data.ws_info[ obj.controller.view.server_prompt.value ];
158 document.createTextNode(
159 ws.name /*+ ' @ ' + ws.lib_shortname*/
162 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
163 JSAN.use('util.file'); var file = new util.file('last_ws_server');
164 file.set_object(obj.controller.view.server_prompt.value);
168 document.createTextNode(
169 document.getElementById('authStrings').getString('staff.auth.controller.not_configured')
180 function(e) { return function() {
187 obj.controller.view.name_prompt.focus();
189 function handle_keypress(ev) {
191 if (ev.keyCode && ev.keyCode == 13) {
193 case obj.controller.view.server_prompt:
195 obj.controller.view.name_prompt.focus(); obj.controller.view.name_prompt.select();
197 case obj.controller.view.name_prompt:
199 obj.controller.view.password_prompt.focus(); obj.controller.view.password_prompt.select();
201 case obj.controller.view.password_prompt:
203 obj.controller.view.submit_button.focus();
214 obj.controller.view.server_prompt.addEventListener(
217 obj.test_server(ev.target.value);
218 obj.controller.render('ws_deck');
223 // This talks to our ILS
224 JSAN.use('auth.session');
225 obj.session = new auth.session(obj.controller.view);
227 obj.controller.render();
228 obj.test_server( obj.controller.view.server_prompt.value );
229 obj.controller.render('ws_deck');
231 if (typeof this.on_init == 'function') {
232 this.error.sdump('D_AUTH','auth.controller.on_init()\n');
237 'test_server' : function(url) {
240 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
241 JSAN.use('util.file'); var file = new util.file('last_ws_server');
242 if (file._file.exists()) {
243 url = file.get_object(); file.close();
244 obj.controller.view.server_prompt.value = url;
247 obj.controller.view.submit_button.disabled = true;
248 obj.controller.view.server_prompt.disabled = true;
249 var s = document.getElementById('status');
250 s.setAttribute('value', document.getElementById('authStrings').getString('staff.auth.controller.testing_hostname'));
251 s.setAttribute('style','color: orange;');
252 document.getElementById('version').value = '';
254 s.setAttribute('value', document.getElementById('authStrings').getString('staff.auth.controller.prompt_hostname'));
255 s.setAttribute('style','color: red;');
256 obj.controller.view.server_prompt.disabled = false;
257 obj.controller.view.server_prompt.focus();
261 if ( ! url.match(/^https:\/\//) ) url = 'https://' + url;
262 var x = new XMLHttpRequest();
263 dump('server url = ' + url + '\n');
264 x.open("GET",url,true);
265 x.onreadystatechange = function() {
267 if (x.readyState != 4) return;
268 s.setAttribute('value', document.getElementById('authStrings').getFormattedString('staff.auth.controller.status', [x.status, x.statusText]));
269 if (x.status == 200) {
270 s.setAttribute('style','color: green;');
272 s.setAttribute('style','color: red;');
274 obj.test_version(url);
276 obj.controller.view.server_prompt.disabled = false;
277 obj.controller.view.server_prompt.focus();
278 s.setAttribute('value', document.getElementById('authStrings').getString('staff.auth.controller.error_hostname'));
279 s.setAttribute('style','color: red;');
280 obj.error.sdump('D_ERROR',E);
285 s.setAttribute('value', document.getElementById('authStrings').getString('staff.auth.controller.error_hostname'));
286 s.setAttribute('style','color: brown;');
287 obj.error.sdump('D_ERROR',E);
288 obj.controller.view.server_prompt.disabled = false;
289 obj.controller.view.server_prompt.focus();
293 'test_version' : function(url) {
295 var s = document.getElementById('version');
296 s.setAttribute('value', document.getElementById('authStrings').getString('staff.auth.controller.testing_version'));
297 s.setAttribute('style','color: orange;');
299 var x = new XMLHttpRequest();
300 var url2 = url + '/xul/server/';
301 dump('version url = ' + url2 + '\n');
302 x.open("GET",url2,true);
303 x.onreadystatechange = function() {
305 if (x.readyState != 4) return;
306 s.setAttribute('value', document.getElementById('authStrings').getFormattedString('staff.auth.controller.status', [x.status, x.statusText]));
307 if (x.status == 200) {
308 s.setAttribute('style','color: green;');
309 obj.controller.view.submit_button.disabled = false;
311 s.setAttribute('style','color: red;');
312 obj.test_upgrade_instructions(url);
314 obj.controller.view.server_prompt.disabled = false;
316 s.setAttribute('value', document.getElementById('authStrings').getString('staff.auth.controller.error_version'));
317 s.setAttribute('style','color: red;');
318 obj.error.sdump('D_ERROR',E);
319 obj.controller.view.server_prompt.disabled = false;
324 s.setAttribute('value', document.getElementById('authStrings').getString('staff.auth.controller.error_version'));
325 s.setAttribute('style','color: brown;');
326 obj.error.sdump('D_ERROR',E);
327 obj.controller.view.server_prompt.disabled = false;
331 'test_upgrade_instructions' : function(url) {
334 var x = new XMLHttpRequest();
335 var url2 = url + '/xul/versions.html';
336 dump('upgrade url = ' + url2 + '\n');
337 x.open("GET",url2,true);
338 x.onreadystatechange = function() {
340 if (x.readyState != 4) return;
341 if (x.status == 200) {
342 window.open('data:text/html,'+window.escape(x.responseText),'upgrade','chrome,resizable,modal,centered');
344 alert(document.getElementById('authStrings').getString('staff.auth.controller.version_mismatch'));
346 obj.controller.view.server_prompt.disabled = false;
348 obj.error.sdump('D_ERROR',E);
349 obj.controller.view.server_prompt.disabled = false;
354 obj.error.sdump('D_ERROR',E);
355 obj.controller.view.server_prompt.disabled = false;
359 'login' : function() {
363 this.error.sdump('D_AUTH',
364 document.getElementById('authStrings').getFormattedString(
365 'staff.auth.controller.error_login', [
366 this.controller.view.name_prompt.value,
367 this.controller.view.password_prompt.value,
368 this.controller.view.server_prompt.value
372 this.controller.view.server_prompt.disabled = true;
373 this.controller.view.name_prompt.disabled = true;
374 this.controller.view.password_prompt.disabled = true;
375 this.controller.view.submit_button.disabled = true;
376 this.controller.view.apply_locale_btn.disabled = true;
377 XML_HTTP_SERVER = this.controller.view.server_prompt.value;
381 if (typeof this.on_login == 'function') {
382 this.error.sdump('D_AUTH','auth.controller.session.on_init = ' +
383 'auth.controller.on_login\n');
384 this.session.on_init = this.on_login;
385 this.session.on_error = function() { obj.logoff(); };
391 var error = '!! ' + E + '\n';
392 this.error.sdump('D_ERROR',error);
395 if (E == 'open-ils.auth.authenticate.init returned false\n') {
396 this.controller.view.server_prompt.focus();
397 this.controller.view.server_prompt.select();
400 if (typeof this.on_login_error == 'function') {
401 this.error.sdump('D_AUTH','auth.controller.on_login_error()\n');
402 this.on_login_error(E);
408 'standalone' : function() {
411 if (typeof this.on_standalone == 'function') {
415 var error = '!! ' + E + '\n';
416 obj.error.sdump('D_ERROR',error);
421 'standalone_import' : function() {
424 if (typeof this.on_standalone_import == 'function') {
425 obj.on_standalone_import();
428 var error = '!! ' + E + '\n';
429 obj.error.sdump('D_ERROR',error);
434 'standalone_export' : function() {
437 if (typeof this.on_standalone_export == 'function') {
438 obj.on_standalone_export();
441 var error = '!! ' + E + '\n';
442 obj.error.sdump('D_ERROR',error);
447 'debug' : function(action) {
450 if (typeof this.on_debug == 'function') {
451 obj.on_debug(action);
454 var error = '!! ' + E + '\n';
455 obj.error.sdump('D_ERROR',error);
460 'logoff' : function() {
462 this.error.sdump('D_AUTH','logoff' + this.w + '\n');
463 this.controller.view.progress_bar.value = 0;
464 this.controller.view.progress_bar.setAttribute('real','0.0');
465 this.controller.view.submit_button.disabled = false;
466 this.controller.view.apply_locale_btn.disabled = false;
467 this.controller.view.password_prompt.disabled = false;
468 this.controller.view.password_prompt.value = '';
469 this.controller.view.name_prompt.disabled = false;
470 this.controller.view.name_prompt.focus();
471 this.controller.view.name_prompt.select();
472 this.controller.view.server_prompt.disabled = false;
474 var windowManager = Components.classes["@mozilla.org/appshell/window-mediator;1"].getService();
475 var windowManagerInterface = windowManager.QueryInterface(Components.interfaces.nsIWindowMediator);
476 var enumerator = windowManagerInterface.getEnumerator(null);
478 var w; // close all other windows
479 while ( w = enumerator.getNext() ) {
480 if (w != window) w.close();
483 this.controller.render('ws_deck');
485 this.session.close();
487 /* FIXME - need some locking or object destruction for the async tests */
488 /* this.test_server( this.controller.view.server_prompt.value ); */
490 if (typeof this.on_logoff == 'function') {
491 this.error.sdump('D_AUTH','auth.controller.on_logoff()\n');
496 'close' : function() {
498 this.error.sdump('D_AUTH','close' + this.w + '\n');
500 if (window.confirm(document.getElementById('authStrings').getString('staff.auth.controller.confirm_close'))) {
502 this.w.close(); /* Probably won't go any further */
504 if (typeof this.on_close == 'function') {
505 this.error.sdump('D_AUTH','auth.controller.on_close()\n');
513 dump('exiting auth/controller.js\n');