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');
99 'cmd_close_window' : [
105 'cmd_test_server' : [
108 obj.test_server( obj.controller.view.server_prompt.value );
116 obj.controller.view.cmd_ssl_exception.setAttribute('hidden','true');
117 var x = new XMLHttpRequest();
118 x.open("GET",'chrome://pippki/content/exceptionDialog.xul',false);
120 obj.controller.view.cmd_ssl_exception.setAttribute('hidden','false');
122 obj.controller.view.cmd_ssl_exception.setAttribute('hidden','true');
127 'cmd_ssl_exception' : [
131 'chrome://pippki/content/exceptionDialog.xul',
133 'chrome,centerscreen,modal',
135 'location' : 'https://' + obj.controller.view.server_prompt.value.match(/^[^\/]*/),
136 'prefetchCert' : true
139 obj.test_server( obj.controller.view.server_prompt.value );
150 for (var s in obj.data.ws_info) {
151 var mi = document.createElement('menuitem');
152 mi.setAttribute('label',s);
153 mi.setAttribute('value',s);
163 'password_prompt' : [
169 function(e) { return function() {} }
171 'apply_locale_btn' : [
173 function(e) { return function() {} }
177 function(e) { return function() {} }
181 function(e) { return function() {
186 function(e) { return function() {
188 JSAN.use('util.widgets'); util.widgets.remove_children(e);
189 var x = document.createElement('description');
192 && obj.data.ws_info[ obj.controller.view.server_prompt.value ]) {
193 var ws = obj.data.ws_info[ obj.controller.view.server_prompt.value ];
195 document.createTextNode(
196 ws.name /*+ ' @ ' + ws.lib_shortname*/
199 JSAN.use('util.file'); var file = new util.file('last_ws_server');
200 file.set_object(obj.controller.view.server_prompt.value);
204 document.createTextNode(
205 document.getElementById('authStrings').getString('staff.auth.controller.not_configured')
216 function(e) { return function() {
223 obj.controller.view.name_prompt.focus();
225 function handle_keypress(ev) {
227 if (ev.keyCode && ev.keyCode == 13) {
229 case obj.controller.view.server_prompt:
231 obj.controller.view.name_prompt.focus(); obj.controller.view.name_prompt.select();
233 case obj.controller.view.name_prompt:
235 obj.controller.view.password_prompt.focus(); obj.controller.view.password_prompt.select();
237 case obj.controller.view.password_prompt:
239 obj.controller.view.submit_button.focus();
250 obj.controller.view.server_prompt.addEventListener(
253 obj.test_server(ev.target.value);
254 obj.controller.render('ws_deck');
258 obj.controller.view.server_prompt.addEventListener(
261 obj.controller.view.name_prompt.focus();
262 obj.controller.view.name_prompt.select();
263 obj.test_server(ev.target.value);
264 obj.controller.render('ws_deck');
269 // This talks to our ILS
270 JSAN.use('auth.session');
271 obj.session = new auth.session(obj.controller.view);
273 obj.controller.render();
274 obj.test_server( obj.controller.view.server_prompt.value );
275 obj.controller.render('ws_deck');
277 if (typeof this.on_init == 'function') {
278 this.error.sdump('D_AUTH','auth.controller.on_init()\n');
283 'test_server' : function(url) {
286 JSAN.use('util.file'); var file = new util.file('last_ws_server');
287 if (file._file.exists()) {
288 url = file.get_object(); file.close();
289 obj.controller.view.server_prompt.value = url;
292 url = url.match(/^[^\/]*/).toString(); // Only test the pre-slash URL
293 obj.controller.view.submit_button.disabled = true;
294 obj.controller.view.server_prompt.disabled = true;
295 var s = document.getElementById('status');
296 s.setAttribute('value', document.getElementById('authStrings').getString('staff.auth.controller.testing_hostname'));
297 s.setAttribute('style','color: orange;');
298 document.getElementById('version').value = '';
300 s.setAttribute('value', document.getElementById('authStrings').getString('staff.auth.controller.prompt_hostname'));
301 s.setAttribute('style','color: red;');
302 obj.controller.view.server_prompt.disabled = false;
303 obj.controller.view.server_prompt.focus();
307 if ( ! url.match(/^https:\/\//) ) url = 'https://' + url;
308 var x = new XMLHttpRequest();
309 dump('server url = ' + url + '\n');
310 x.open("GET",url,true);
311 x.onreadystatechange = function() {
313 if (x.readyState != 4) return;
314 s.setAttribute('value', document.getElementById('authStrings').getFormattedString('staff.auth.controller.status', [x.status, x.statusText]));
315 if (x.status == 200) {
316 s.setAttribute('style','color: green;');
318 s.setAttribute('style','color: red;');
320 obj.test_version(url);
322 obj.controller.view.server_prompt.disabled = false;
323 obj.controller.view.server_prompt.focus();
324 s.setAttribute('value', document.getElementById('authStrings').getString('staff.auth.controller.error_hostname'));
325 s.setAttribute('style','color: red;');
326 obj.error.sdump('D_ERROR',E);
331 s.setAttribute('value', document.getElementById('authStrings').getString('staff.auth.controller.error_hostname'));
332 s.setAttribute('style','color: brown;');
333 obj.error.sdump('D_ERROR',E);
334 obj.controller.view.server_prompt.disabled = false;
335 obj.controller.view.server_prompt.focus();
339 'test_version' : function(url) {
341 var s = document.getElementById('version');
342 s.setAttribute('value', document.getElementById('authStrings').getString('staff.auth.controller.testing_version'));
343 s.setAttribute('style','color: orange;');
345 var x = new XMLHttpRequest();
346 var url2 = url + '/xul/server/';
347 dump('version url = ' + url2 + '\n');
348 x.open("GET",url2,true);
349 x.onreadystatechange = function() {
351 if (x.readyState != 4) return;
352 s.setAttribute('value', document.getElementById('authStrings').getFormattedString('staff.auth.controller.status', [x.status, x.statusText]));
353 if (x.status == 200) {
354 s.setAttribute('style','color: green;');
355 obj.controller.view.submit_button.disabled = false;
357 s.setAttribute('style','color: red;');
358 obj.test_upgrade_instructions(url);
360 obj.controller.view.server_prompt.disabled = false;
362 s.setAttribute('value', document.getElementById('authStrings').getString('staff.auth.controller.error_version'));
363 s.setAttribute('style','color: red;');
364 obj.error.sdump('D_ERROR',E);
365 obj.controller.view.server_prompt.disabled = false;
370 s.setAttribute('value', document.getElementById('authStrings').getString('staff.auth.controller.error_version'));
371 s.setAttribute('style','color: brown;');
372 obj.error.sdump('D_ERROR',E);
373 obj.controller.view.server_prompt.disabled = false;
377 'test_upgrade_instructions' : function(url) {
380 var x = new XMLHttpRequest();
381 var url2 = url + '/xul/versions.html';
382 dump('upgrade url = ' + url2 + '\n');
383 x.open("GET",url2,true);
384 x.onreadystatechange = function() {
386 if (x.readyState != 4) return;
387 if (x.status == 200) {
388 window.open('data:text/html,'+window.escape(x.responseText),'upgrade','chrome,resizable,modal,centered');
390 if(typeof(G.upgradeCheck) == "function")
392 if (confirm("This server does not support your version of the staff client, an upgrade may be required. If you wish to check for an upgrade please press Ok. Otherwise please press cancel."))
395 alert(document.getElementById('authStrings').getString('staff.auth.controller.version_mismatch'));
398 obj.controller.view.server_prompt.disabled = false;
400 obj.error.sdump('D_ERROR',E);
401 obj.controller.view.server_prompt.disabled = false;
406 obj.error.sdump('D_ERROR',E);
407 obj.controller.view.server_prompt.disabled = false;
411 'login' : function() {
415 this.error.sdump('D_AUTH',
416 document.getElementById('authStrings').getFormattedString(
417 'staff.auth.controller.error_login', [
418 this.controller.view.name_prompt.value,
419 this.controller.view.password_prompt.value,
420 this.controller.view.server_prompt.value
424 this.controller.view.server_prompt.disabled = true;
425 this.controller.view.name_prompt.disabled = true;
426 this.controller.view.password_prompt.disabled = true;
427 this.controller.view.submit_button.disabled = true;
428 this.controller.view.apply_locale_btn.disabled = true;
429 XML_HTTP_SERVER = this.controller.view.server_prompt.value.match(/^[^\/]*/).toString();
433 if (typeof this.on_login == 'function') {
434 this.error.sdump('D_AUTH','auth.controller.session.on_init = ' +
435 'auth.controller.on_login\n');
436 this.session.on_init = this.on_login;
437 this.session.on_error = function() { obj.logoff(); };
443 var error = '!! ' + E + '\n';
444 this.error.sdump('D_ERROR',error);
447 if (E == 'open-ils.auth.authenticate.init returned false\n') {
448 this.controller.view.server_prompt.focus();
449 this.controller.view.server_prompt.select();
452 if (typeof this.on_login_error == 'function') {
453 this.error.sdump('D_AUTH','auth.controller.on_login_error()\n');
454 this.on_login_error(E);
457 // Once we are done with it, clear the password
458 this.controller.view.password_prompt.value = '';
462 'standalone' : function() {
465 if (typeof this.on_standalone == 'function') {
469 var error = '!! ' + E + '\n';
470 obj.error.sdump('D_ERROR',error);
475 'standalone_import' : function() {
478 if (typeof this.on_standalone_import == 'function') {
479 obj.on_standalone_import();
482 var error = '!! ' + E + '\n';
483 obj.error.sdump('D_ERROR',error);
488 'standalone_export' : function() {
491 if (typeof this.on_standalone_export == 'function') {
492 obj.on_standalone_export();
495 var error = '!! ' + E + '\n';
496 obj.error.sdump('D_ERROR',error);
501 'debug' : function(action) {
504 if (typeof this.on_debug == 'function') {
505 obj.on_debug(action);
508 var error = '!! ' + E + '\n';
509 obj.error.sdump('D_ERROR',error);
514 'logoff' : function() {
516 this.data.stash_retrieve();
517 if (typeof this.data.unsaved_data != 'undefined') {
518 if (this.data.unsaved_data > 0) {
519 var confirmation = window.confirm( document.getElementById('offlineStrings').getString('menu.logoff.unsaved_data_warning') );
520 if (!confirmation) { return; }
521 this.data.unsaved_data = 0;
522 this.data.stash('unsaved_data');
526 this.error.sdump('D_AUTH','logoff' + this.w + '\n');
527 this.controller.view.progress_bar.value = 0;
528 this.controller.view.progress_bar.setAttribute('real','0.0');
529 this.controller.view.submit_button.disabled = false;
530 this.controller.view.apply_locale_btn.disabled = false;
531 this.controller.view.password_prompt.disabled = false;
532 this.controller.view.password_prompt.value = '';
533 this.controller.view.name_prompt.disabled = false;
534 this.controller.view.name_prompt.focus();
535 this.controller.view.name_prompt.select();
536 this.controller.view.server_prompt.disabled = false;
538 var windowManager = Components.classes["@mozilla.org/appshell/window-mediator;1"].getService();
539 var windowManagerInterface = windowManager.QueryInterface(Components.interfaces.nsIWindowMediator);
540 var enumerator = windowManagerInterface.getEnumerator(null);
542 var w; // close all other windows
543 while ( w = enumerator.getNext() ) {
545 if (w.xulG) { w.close(); } // FIXME: kludge so we don't close Firefox windows as an extension. We should define a @windowtype for all the staff client windows and have the enumerator just pull those
549 this.controller.render('ws_deck');
551 this.session.close();
552 this.data.menu_perms = false;
553 this.data.current_hotkeyset = undefined;
554 this.data.enable_debug = this.data.debug_client;
555 this.data.session = undefined;
556 this.data.stash('menu_perms');
557 this.data.stash('current_hotkeyset');
558 this.data.stash('enable_debug');
559 this.data.stash('session');
561 /* FIXME - need some locking or object destruction for the async tests */
562 /* this.test_server( this.controller.view.server_prompt.value ); */
564 if (typeof this.on_logoff == 'function') {
565 this.error.sdump('D_AUTH','auth.controller.on_logoff()\n');
570 'close' : function() {
572 this.error.sdump('D_AUTH','close' + this.w + '\n');
574 var confirm_string = document.getElementById('authStrings').getString('staff.auth.controller.confirm_close');
576 this.data.stash_retrieve();
577 if (typeof this.data.unsaved_data != 'undefined') {
578 if (this.data.unsaved_data > 0) {
579 confirm_string = document.getElementById('offlineStrings').getString('menu.shutdown.unsaved_data_warning');
583 if (window.confirm(confirm_string)) {
584 this.data.unsaved_data = 0;
585 this.data.stash('unsaved_data');
587 this.w.close(); /* Probably won't go any further */
589 if (typeof this.on_close == 'function') {
590 this.error.sdump('D_AUTH','auth.controller.on_close()\n');
598 dump('exiting auth/controller.js\n');