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.test_server( obj.controller.view.server_prompt.value );
280 obj.controller.render('ws_deck');
282 if (typeof this.on_init == 'function') {
283 this.error.sdump('D_AUTH','auth.controller.on_init()\n');
288 'test_server' : function(url) {
291 JSAN.use('util.file'); var file = new util.file('last_ws_server');
292 if (file._file.exists()) {
293 url = file.get_object(); file.close();
294 obj.controller.view.server_prompt.value = url;
297 url = url.match(/^[^\/]*/).toString(); // Only test the pre-slash URL
298 obj.controller.view.submit_button.disabled = true;
299 obj.controller.view.server_prompt.disabled = true;
300 var s = document.getElementById('status');
301 s.setAttribute('value', document.getElementById('authStrings').getString('staff.auth.controller.testing_hostname'));
302 s.setAttribute('style','color: orange;');
303 document.getElementById('version').value = '';
305 s.setAttribute('value', document.getElementById('authStrings').getString('staff.auth.controller.prompt_hostname'));
306 s.setAttribute('style','color: red;');
307 obj.controller.view.server_prompt.disabled = false;
308 obj.controller.view.server_prompt.focus();
312 if ( ! url.match(/^https:\/\//) ) url = 'https://' + url;
313 var x = new XMLHttpRequest();
314 dump('server url = ' + url + '\n');
315 x.open("GET",url,true);
316 x.onreadystatechange = function() {
318 if (x.readyState != 4) return;
319 s.setAttribute('value', document.getElementById('authStrings').getFormattedString('staff.auth.controller.status', [x.status, x.statusText]));
320 if (x.status == 200) {
321 s.setAttribute('style','color: green;');
323 s.setAttribute('style','color: red;');
325 obj.test_version(url);
327 obj.controller.view.server_prompt.disabled = false;
328 obj.controller.view.server_prompt.focus();
329 s.setAttribute('value', document.getElementById('authStrings').getString('staff.auth.controller.error_hostname'));
330 s.setAttribute('style','color: red;');
331 obj.error.sdump('D_ERROR',E);
336 s.setAttribute('value', document.getElementById('authStrings').getString('staff.auth.controller.error_hostname'));
337 s.setAttribute('style','color: brown;');
338 obj.error.sdump('D_ERROR',E);
339 obj.controller.view.server_prompt.disabled = false;
340 obj.controller.view.server_prompt.focus();
344 'test_version' : function(url) {
346 var s = document.getElementById('version');
347 s.setAttribute('value', document.getElementById('authStrings').getString('staff.auth.controller.testing_version'));
348 s.setAttribute('style','color: orange;');
350 var x = new XMLHttpRequest();
351 var url2 = url + '/xul/server/';
352 dump('version url = ' + url2 + '\n');
353 x.open("GET",url2,true);
354 x.onreadystatechange = function() {
356 if (x.readyState != 4) return;
357 s.setAttribute('value', document.getElementById('authStrings').getFormattedString('staff.auth.controller.status', [x.status, x.statusText]));
358 if (x.status == 200) {
359 s.setAttribute('style','color: green;');
360 obj.controller.view.submit_button.disabled = false;
362 s.setAttribute('style','color: red;');
363 obj.test_upgrade_instructions(url);
365 obj.controller.view.server_prompt.disabled = false;
367 s.setAttribute('value', document.getElementById('authStrings').getString('staff.auth.controller.error_version'));
368 s.setAttribute('style','color: red;');
369 obj.error.sdump('D_ERROR',E);
370 obj.controller.view.server_prompt.disabled = false;
375 s.setAttribute('value', document.getElementById('authStrings').getString('staff.auth.controller.error_version'));
376 s.setAttribute('style','color: brown;');
377 obj.error.sdump('D_ERROR',E);
378 obj.controller.view.server_prompt.disabled = false;
382 'test_upgrade_instructions' : function(url) {
385 var x = new XMLHttpRequest();
386 var url2 = url + '/xul/versions.html';
387 dump('upgrade url = ' + url2 + '\n');
388 x.open("GET",url2,true);
389 x.onreadystatechange = function() {
391 if (x.readyState != 4) return;
392 if (x.status == 200) {
393 window.open('data:text/html,'+window.escape(x.responseText),'upgrade','chrome,resizable,modal,centered');
395 if(typeof(G.upgradeCheck) == "function")
397 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."))
400 alert(document.getElementById('authStrings').getString('staff.auth.controller.version_mismatch'));
403 obj.controller.view.server_prompt.disabled = false;
405 obj.error.sdump('D_ERROR',E);
406 obj.controller.view.server_prompt.disabled = false;
411 obj.error.sdump('D_ERROR',E);
412 obj.controller.view.server_prompt.disabled = false;
416 'login' : function() {
420 this.error.sdump('D_AUTH',
421 document.getElementById('authStrings').getFormattedString(
422 'staff.auth.controller.error_login', [
423 this.controller.view.name_prompt.value,
424 this.controller.view.password_prompt.value,
425 this.controller.view.server_prompt.value
429 this.controller.view.server_prompt.disabled = true;
430 this.controller.view.name_prompt.disabled = true;
431 this.controller.view.password_prompt.disabled = true;
432 this.controller.view.submit_button.disabled = true;
433 this.controller.view.apply_locale_btn.disabled = true;
434 XML_HTTP_SERVER = this.controller.view.server_prompt.value.match(/^[^\/]*/).toString();
438 if (typeof this.on_login == 'function') {
439 this.error.sdump('D_AUTH','auth.controller.session.on_init = ' +
440 'auth.controller.on_login\n');
441 this.session.on_init = this.on_login;
442 this.session.on_error = function() { obj.logoff(); };
448 var error = '!! ' + E + '\n';
449 this.error.sdump('D_ERROR',error);
452 if (E == 'open-ils.auth.authenticate.init returned false\n') {
453 this.controller.view.server_prompt.focus();
454 this.controller.view.server_prompt.select();
457 if (typeof this.on_login_error == 'function') {
458 this.error.sdump('D_AUTH','auth.controller.on_login_error()\n');
459 this.on_login_error(E);
462 // Once we are done with it, clear the password
463 this.controller.view.password_prompt.value = '';
467 'standalone' : function() {
470 if (typeof this.on_standalone == 'function') {
474 var error = '!! ' + E + '\n';
475 obj.error.sdump('D_ERROR',error);
480 'standalone_import' : function() {
483 if (typeof this.on_standalone_import == 'function') {
484 obj.on_standalone_import();
487 var error = '!! ' + E + '\n';
488 obj.error.sdump('D_ERROR',error);
493 'standalone_export' : function() {
496 if (typeof this.on_standalone_export == 'function') {
497 obj.on_standalone_export();
500 var error = '!! ' + E + '\n';
501 obj.error.sdump('D_ERROR',error);
506 'debug' : function(action) {
509 if (typeof this.on_debug == 'function') {
510 obj.on_debug(action);
513 var error = '!! ' + E + '\n';
514 obj.error.sdump('D_ERROR',error);
519 'logoff' : function() {
521 this.data.stash_retrieve();
522 if (typeof this.data.unsaved_data != 'undefined') {
523 if (this.data.unsaved_data > 0) {
524 var confirmation = window.confirm( document.getElementById('offlineStrings').getString('menu.logoff.unsaved_data_warning') );
525 if (!confirmation) { return; }
526 this.data.unsaved_data = 0;
527 this.data.stash('unsaved_data');
531 this.error.sdump('D_AUTH','logoff' + this.w + '\n');
532 this.controller.view.progress_bar.value = 0;
533 this.controller.view.progress_bar.setAttribute('real','0.0');
534 this.controller.view.submit_button.disabled = false;
535 this.controller.view.apply_locale_btn.disabled = false;
536 this.controller.view.password_prompt.disabled = false;
537 this.controller.view.password_prompt.value = '';
538 this.controller.view.name_prompt.disabled = false;
539 this.controller.view.name_prompt.focus();
540 this.controller.view.name_prompt.select();
541 this.controller.view.server_prompt.disabled = false;
543 var windowManager = Components.classes["@mozilla.org/appshell/window-mediator;1"].getService();
544 var windowManagerInterface = windowManager.QueryInterface(Components.interfaces.nsIWindowMediator);
545 var enumerator = windowManagerInterface.getEnumerator(null);
547 var w; // close all other windows
548 while ( w = enumerator.getNext() ) {
550 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
554 this.controller.render('ws_deck');
556 this.session.close();
557 this.data.menu_perms = false;
558 this.data.current_hotkeyset = undefined;
559 this.data.enable_debug = this.data.debug_client;
560 this.data.session = undefined;
561 this.data.stash('menu_perms');
562 this.data.stash('current_hotkeyset');
563 this.data.stash('enable_debug');
564 this.data.stash('session');
566 /* FIXME - need some locking or object destruction for the async tests */
567 /* this.test_server( this.controller.view.server_prompt.value ); */
569 if (typeof this.on_logoff == 'function') {
570 this.error.sdump('D_AUTH','auth.controller.on_logoff()\n');
575 'close' : function() {
577 this.error.sdump('D_AUTH','close' + this.w + '\n');
579 var confirm_string = document.getElementById('authStrings').getString('staff.auth.controller.confirm_close');
581 this.data.stash_retrieve();
582 if (typeof this.data.unsaved_data != 'undefined') {
583 if (this.data.unsaved_data > 0) {
584 confirm_string = document.getElementById('offlineStrings').getString('menu.shutdown.unsaved_data_warning');
588 if (window.confirm(confirm_string)) {
589 this.data.unsaved_data = 0;
590 this.data.stash('unsaved_data');
592 this.w.close(); /* Probably won't go any further */
594 if (typeof this.on_close == 'function') {
595 this.error.sdump('D_AUTH','auth.controller.on_close()\n');
603 dump('exiting auth/controller.js\n');