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 );
151 for (var s in obj.data.ws_info) {
155 for (var i = 0; i < list.length; i++) {
156 var mi = document.createElement('menuitem');
157 mi.setAttribute('label',list[i]);
158 mi.setAttribute('value',list[i]);
168 'password_prompt' : [
174 function(e) { return function() {} }
176 'apply_locale_btn' : [
178 function(e) { return function() {} }
182 function(e) { return function() {} }
186 function(e) { return function() {
191 function(e) { return function() {
193 JSAN.use('util.widgets'); util.widgets.remove_children(e);
194 var x = document.createElement('description');
197 && obj.data.ws_info[ obj.controller.view.server_prompt.value ]) {
198 var ws = obj.data.ws_info[ obj.controller.view.server_prompt.value ];
200 document.createTextNode(
201 ws.name /*+ ' @ ' + ws.lib_shortname*/
204 JSAN.use('util.file'); var file = new util.file('last_ws_server');
205 file.set_object(obj.controller.view.server_prompt.value);
209 document.createTextNode(
210 document.getElementById('authStrings').getString('staff.auth.controller.not_configured')
221 function(e) { return function() {
228 obj.controller.view.name_prompt.focus();
230 function handle_keypress(ev) {
232 if (ev.keyCode && ev.keyCode == 13) {
234 case obj.controller.view.server_prompt:
236 obj.controller.view.name_prompt.focus(); obj.controller.view.name_prompt.select();
238 case obj.controller.view.name_prompt:
240 obj.controller.view.password_prompt.focus(); obj.controller.view.password_prompt.select();
242 case obj.controller.view.password_prompt:
244 obj.controller.view.submit_button.focus();
255 obj.controller.view.server_prompt.addEventListener(
258 obj.test_server(ev.target.value);
259 obj.controller.render('ws_deck');
263 obj.controller.view.server_prompt.addEventListener(
266 obj.controller.view.name_prompt.focus();
267 obj.controller.view.name_prompt.select();
268 obj.test_server(ev.target.value);
269 obj.controller.render('ws_deck');
274 // This talks to our ILS
275 JSAN.use('auth.session');
276 obj.session = new auth.session(obj.controller.view);
278 obj.controller.render();
279 obj.controller.render('ws_deck');
281 if (typeof this.on_init == 'function') {
282 this.error.sdump('D_AUTH','auth.controller.on_init()\n');
287 'test_server' : function(url) {
290 JSAN.use('util.file'); var file = new util.file('last_ws_server');
291 if (file._file.exists()) {
292 url = file.get_object(); file.close();
293 obj.controller.view.server_prompt.value = url;
296 url = url.match(/^[^\/]*/).toString(); // Only test the pre-slash URL
297 obj.controller.view.submit_button.disabled = true;
298 obj.controller.view.server_prompt.disabled = true;
299 var s = document.getElementById('status');
300 s.setAttribute('value', document.getElementById('authStrings').getString('staff.auth.controller.testing_hostname'));
301 s.setAttribute('style','color: orange;');
302 document.getElementById('version').value = '';
304 s.setAttribute('value', document.getElementById('authStrings').getString('staff.auth.controller.prompt_hostname'));
305 s.setAttribute('style','color: red;');
306 obj.controller.view.server_prompt.disabled = false;
307 obj.controller.view.server_prompt.focus();
311 if ( ! url.match(/^https:\/\//) ) url = 'https://' + url;
312 var x = new XMLHttpRequest();
313 dump('server url = ' + url + '\n');
314 x.open("GET",url,true);
315 x.onreadystatechange = function() {
317 if (x.readyState != 4) return;
318 s.setAttribute('value', document.getElementById('authStrings').getFormattedString('staff.auth.controller.status', [x.status, x.statusText]));
319 if (x.status == 200) {
320 s.setAttribute('style','color: green;');
323 s.setAttribute('value', document.getElementById('authStrings').getString('staff.auth.controller.error_hostname'));
324 obj.controller.view.server_prompt.disabled = false;
325 obj.controller.view.server_prompt.focus();
327 s.setAttribute('style','color: red;');
330 obj.test_version(url);
332 obj.controller.view.server_prompt.disabled = false;
333 obj.controller.view.server_prompt.focus();
334 s.setAttribute('value', document.getElementById('authStrings').getString('staff.auth.controller.error_hostname'));
335 s.setAttribute('style','color: red;');
336 obj.error.sdump('D_ERROR',E);
341 s.setAttribute('value', document.getElementById('authStrings').getString('staff.auth.controller.error_hostname'));
342 s.setAttribute('style','color: brown;');
343 obj.error.sdump('D_ERROR',E);
344 obj.controller.view.server_prompt.disabled = false;
345 obj.controller.view.server_prompt.focus();
349 'test_version' : function(url) {
351 var s = document.getElementById('version');
352 s.setAttribute('value', document.getElementById('authStrings').getString('staff.auth.controller.testing_version'));
353 s.setAttribute('style','color: orange;');
355 var x = new XMLHttpRequest();
356 var url2 = url + '/xul/server/';
357 dump('version url = ' + url2 + '\n');
358 x.open("GET",url2,true);
359 x.onreadystatechange = function() {
361 if (x.readyState != 4) return;
362 s.setAttribute('value', document.getElementById('authStrings').getFormattedString('staff.auth.controller.status', [x.status, x.statusText]));
363 if (x.status == 200) {
364 s.setAttribute('style','color: green;');
365 obj.controller.view.submit_button.disabled = false;
367 s.setAttribute('style','color: red;');
368 obj.test_upgrade_instructions(url);
370 obj.controller.view.server_prompt.disabled = false;
372 s.setAttribute('value', document.getElementById('authStrings').getString('staff.auth.controller.error_version'));
373 s.setAttribute('style','color: red;');
374 obj.error.sdump('D_ERROR',E);
375 obj.controller.view.server_prompt.disabled = false;
380 s.setAttribute('value', document.getElementById('authStrings').getString('staff.auth.controller.error_version'));
381 s.setAttribute('style','color: brown;');
382 obj.error.sdump('D_ERROR',E);
383 obj.controller.view.server_prompt.disabled = false;
387 'test_upgrade_instructions' : function(url) {
390 var x = new XMLHttpRequest();
391 var url2 = url + '/xul/versions.html';
392 dump('upgrade url = ' + url2 + '\n');
393 x.open("GET",url2,true);
394 x.onreadystatechange = function() {
396 if (x.readyState != 4) return;
397 if (x.status == 200) {
398 window.open('data:text/html;charset=UTF-8,'+window.encodeURIComponent(x.responseText),'upgrade','chrome,resizable,modal,centered');
400 if(typeof(G.upgradeCheck) == "function")
402 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."))
405 alert(document.getElementById('authStrings').getString('staff.auth.controller.version_mismatch'));
408 obj.controller.view.server_prompt.disabled = false;
410 obj.error.sdump('D_ERROR',E);
411 obj.controller.view.server_prompt.disabled = false;
416 obj.error.sdump('D_ERROR',E);
417 obj.controller.view.server_prompt.disabled = false;
421 'login' : function() {
425 this.error.sdump('D_AUTH',
426 document.getElementById('authStrings').getFormattedString(
427 'staff.auth.controller.error_login', [
428 this.controller.view.name_prompt.value,
429 this.controller.view.password_prompt.value,
430 this.controller.view.server_prompt.value
434 this.controller.view.server_prompt.disabled = true;
435 this.controller.view.name_prompt.disabled = true;
436 this.controller.view.password_prompt.disabled = true;
437 this.controller.view.submit_button.disabled = true;
438 this.controller.view.apply_locale_btn.disabled = true;
439 XML_HTTP_SERVER = this.controller.view.server_prompt.value.match(/^[^\/]*/).toString();
443 if (typeof this.on_login == 'function') {
444 this.error.sdump('D_AUTH','auth.controller.session.on_init = ' +
445 'auth.controller.on_login\n');
446 this.session.on_init = this.on_login;
447 this.session.on_error = function() { obj.logoff(); };
453 var error = '!! ' + E + '\n';
454 this.error.sdump('D_ERROR',error);
457 if (E == 'open-ils.auth.authenticate.init returned false\n') {
458 this.controller.view.server_prompt.focus();
459 this.controller.view.server_prompt.select();
462 if (typeof this.on_login_error == 'function') {
463 this.error.sdump('D_AUTH','auth.controller.on_login_error()\n');
464 this.on_login_error(E);
467 // Once we are done with it, clear the password
468 this.controller.view.password_prompt.value = '';
472 'standalone' : function() {
475 if (typeof this.on_standalone == 'function') {
479 var error = '!! ' + E + '\n';
480 obj.error.sdump('D_ERROR',error);
485 'standalone_import' : function() {
488 if (typeof this.on_standalone_import == 'function') {
489 obj.on_standalone_import();
492 var error = '!! ' + E + '\n';
493 obj.error.sdump('D_ERROR',error);
498 'standalone_export' : function() {
501 if (typeof this.on_standalone_export == 'function') {
502 obj.on_standalone_export();
505 var error = '!! ' + E + '\n';
506 obj.error.sdump('D_ERROR',error);
511 'debug' : function(action) {
514 if (typeof this.on_debug == 'function') {
515 obj.on_debug(action);
518 var error = '!! ' + E + '\n';
519 obj.error.sdump('D_ERROR',error);
524 'logoff' : function() {
526 this.data.stash_retrieve();
527 if (typeof this.data.unsaved_data != 'undefined') {
528 if (this.data.unsaved_data > 0) {
529 var confirmation = window.confirm( document.getElementById('offlineStrings').getString('menu.logoff.unsaved_data_warning') );
530 if (!confirmation) { return; }
531 this.data.unsaved_data = 0;
532 this.data.stash('unsaved_data');
536 this.error.sdump('D_AUTH','logoff' + this.w + '\n');
537 this.controller.view.progress_bar.value = 0;
538 this.controller.view.progress_bar.setAttribute('real','0.0');
539 this.controller.view.submit_button.disabled = false;
540 this.controller.view.apply_locale_btn.disabled = false;
541 this.controller.view.password_prompt.disabled = false;
542 this.controller.view.password_prompt.value = '';
543 this.controller.view.name_prompt.disabled = false;
544 this.controller.view.name_prompt.focus();
545 this.controller.view.name_prompt.select();
546 this.controller.view.server_prompt.disabled = false;
548 var windowManager = Components.classes["@mozilla.org/appshell/window-mediator;1"].getService();
549 var windowManagerInterface = windowManager.QueryInterface(Components.interfaces.nsIWindowMediator);
550 var enumerator = windowManagerInterface.getEnumerator(null);
552 var w; // close all other windows
553 while ( w = enumerator.getNext() ) {
555 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
559 this.controller.render('ws_deck');
561 this.session.close();
562 this.data.menu_perms = false;
563 this.data.current_hotkeyset = undefined;
564 this.data.enable_debug = this.data.debug_client;
565 this.data.session = undefined;
566 this.data.stash('menu_perms');
567 this.data.stash('current_hotkeyset');
568 this.data.stash('enable_debug');
569 this.data.stash('session');
571 /* FIXME - need some locking or object destruction for the async tests */
572 /* this.test_server( this.controller.view.server_prompt.value ); */
574 if (typeof this.on_logoff == 'function') {
575 this.error.sdump('D_AUTH','auth.controller.on_logoff()\n');
580 'close' : function() {
582 this.error.sdump('D_AUTH','close' + this.w + '\n');
584 var confirm_string = document.getElementById('authStrings').getString('staff.auth.controller.confirm_close');
586 this.data.stash_retrieve();
587 if (typeof this.data.unsaved_data != 'undefined') {
588 if (this.data.unsaved_data > 0) {
589 confirm_string = document.getElementById('offlineStrings').getString('menu.shutdown.unsaved_data_warning');
593 if (window.confirm(confirm_string)) {
594 this.data.unsaved_data = 0;
595 this.data.stash('unsaved_data');
597 this.w.close(); /* Probably won't go any further */
599 if (typeof this.on_close == 'function') {
600 this.error.sdump('D_AUTH','auth.controller.on_close()\n');
608 dump('exiting auth/controller.js\n');