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 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
200 JSAN.use('util.file'); var file = new util.file('last_ws_server');
201 file.set_object(obj.controller.view.server_prompt.value);
205 document.createTextNode(
206 document.getElementById('authStrings').getString('staff.auth.controller.not_configured')
217 function(e) { return function() {
224 obj.controller.view.name_prompt.focus();
226 function handle_keypress(ev) {
228 if (ev.keyCode && ev.keyCode == 13) {
230 case obj.controller.view.server_prompt:
232 obj.controller.view.name_prompt.focus(); obj.controller.view.name_prompt.select();
234 case obj.controller.view.name_prompt:
236 obj.controller.view.password_prompt.focus(); obj.controller.view.password_prompt.select();
238 case obj.controller.view.password_prompt:
240 obj.controller.view.submit_button.focus();
251 obj.controller.view.server_prompt.addEventListener(
254 obj.test_server(ev.target.value);
255 obj.controller.render('ws_deck');
259 obj.controller.view.server_prompt.addEventListener(
262 obj.controller.view.name_prompt.focus();
263 obj.controller.view.name_prompt.select();
264 obj.test_server(ev.target.value);
265 obj.controller.render('ws_deck');
270 // This talks to our ILS
271 JSAN.use('auth.session');
272 obj.session = new auth.session(obj.controller.view);
274 obj.controller.render();
275 obj.test_server( obj.controller.view.server_prompt.value );
276 obj.controller.render('ws_deck');
278 if (typeof this.on_init == 'function') {
279 this.error.sdump('D_AUTH','auth.controller.on_init()\n');
284 'test_server' : function(url) {
287 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
288 JSAN.use('util.file'); var file = new util.file('last_ws_server');
289 if (file._file.exists()) {
290 url = file.get_object(); file.close();
291 obj.controller.view.server_prompt.value = url;
294 url = url.match(/^[^\/]*/).toString(); // Only test the pre-slash URL
295 obj.controller.view.submit_button.disabled = true;
296 obj.controller.view.server_prompt.disabled = true;
297 var s = document.getElementById('status');
298 s.setAttribute('value', document.getElementById('authStrings').getString('staff.auth.controller.testing_hostname'));
299 s.setAttribute('style','color: orange;');
300 document.getElementById('version').value = '';
302 s.setAttribute('value', document.getElementById('authStrings').getString('staff.auth.controller.prompt_hostname'));
303 s.setAttribute('style','color: red;');
304 obj.controller.view.server_prompt.disabled = false;
305 obj.controller.view.server_prompt.focus();
309 if ( ! url.match(/^https:\/\//) ) url = 'https://' + url;
310 var x = new XMLHttpRequest();
311 dump('server url = ' + url + '\n');
312 x.open("GET",url,true);
313 x.onreadystatechange = function() {
315 if (x.readyState != 4) return;
316 s.setAttribute('value', document.getElementById('authStrings').getFormattedString('staff.auth.controller.status', [x.status, x.statusText]));
317 if (x.status == 200) {
318 s.setAttribute('style','color: green;');
320 s.setAttribute('style','color: red;');
322 obj.test_version(url);
324 obj.controller.view.server_prompt.disabled = false;
325 obj.controller.view.server_prompt.focus();
326 s.setAttribute('value', document.getElementById('authStrings').getString('staff.auth.controller.error_hostname'));
327 s.setAttribute('style','color: red;');
328 obj.error.sdump('D_ERROR',E);
333 s.setAttribute('value', document.getElementById('authStrings').getString('staff.auth.controller.error_hostname'));
334 s.setAttribute('style','color: brown;');
335 obj.error.sdump('D_ERROR',E);
336 obj.controller.view.server_prompt.disabled = false;
337 obj.controller.view.server_prompt.focus();
341 'test_version' : function(url) {
343 var s = document.getElementById('version');
344 s.setAttribute('value', document.getElementById('authStrings').getString('staff.auth.controller.testing_version'));
345 s.setAttribute('style','color: orange;');
347 var x = new XMLHttpRequest();
348 var url2 = url + '/xul/server/';
349 dump('version url = ' + url2 + '\n');
350 x.open("GET",url2,true);
351 x.onreadystatechange = function() {
353 if (x.readyState != 4) return;
354 s.setAttribute('value', document.getElementById('authStrings').getFormattedString('staff.auth.controller.status', [x.status, x.statusText]));
355 if (x.status == 200) {
356 s.setAttribute('style','color: green;');
357 obj.controller.view.submit_button.disabled = false;
359 s.setAttribute('style','color: red;');
360 obj.test_upgrade_instructions(url);
362 obj.controller.view.server_prompt.disabled = false;
364 s.setAttribute('value', document.getElementById('authStrings').getString('staff.auth.controller.error_version'));
365 s.setAttribute('style','color: red;');
366 obj.error.sdump('D_ERROR',E);
367 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: brown;');
374 obj.error.sdump('D_ERROR',E);
375 obj.controller.view.server_prompt.disabled = false;
379 'test_upgrade_instructions' : function(url) {
382 var x = new XMLHttpRequest();
383 var url2 = url + '/xul/versions.html';
384 dump('upgrade url = ' + url2 + '\n');
385 x.open("GET",url2,true);
386 x.onreadystatechange = function() {
388 if (x.readyState != 4) return;
389 if (x.status == 200) {
390 window.open('data:text/html,'+window.escape(x.responseText),'upgrade','chrome,resizable,modal,centered');
392 if(typeof(G.upgradeCheck) == "function")
394 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."))
397 alert(document.getElementById('authStrings').getString('staff.auth.controller.version_mismatch'));
400 obj.controller.view.server_prompt.disabled = false;
402 obj.error.sdump('D_ERROR',E);
403 obj.controller.view.server_prompt.disabled = false;
408 obj.error.sdump('D_ERROR',E);
409 obj.controller.view.server_prompt.disabled = false;
413 'login' : function() {
417 this.error.sdump('D_AUTH',
418 document.getElementById('authStrings').getFormattedString(
419 'staff.auth.controller.error_login', [
420 this.controller.view.name_prompt.value,
421 this.controller.view.password_prompt.value,
422 this.controller.view.server_prompt.value
426 this.controller.view.server_prompt.disabled = true;
427 this.controller.view.name_prompt.disabled = true;
428 this.controller.view.password_prompt.disabled = true;
429 this.controller.view.submit_button.disabled = true;
430 this.controller.view.apply_locale_btn.disabled = true;
431 XML_HTTP_SERVER = this.controller.view.server_prompt.value.match(/^[^\/]*/).toString();
435 if (typeof this.on_login == 'function') {
436 this.error.sdump('D_AUTH','auth.controller.session.on_init = ' +
437 'auth.controller.on_login\n');
438 this.session.on_init = this.on_login;
439 this.session.on_error = function() { obj.logoff(); };
445 var error = '!! ' + E + '\n';
446 this.error.sdump('D_ERROR',error);
449 if (E == 'open-ils.auth.authenticate.init returned false\n') {
450 this.controller.view.server_prompt.focus();
451 this.controller.view.server_prompt.select();
454 if (typeof this.on_login_error == 'function') {
455 this.error.sdump('D_AUTH','auth.controller.on_login_error()\n');
456 this.on_login_error(E);
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.stash('menu_perms');
555 this.data.stash('current_hotkeyset');
557 /* FIXME - need some locking or object destruction for the async tests */
558 /* this.test_server( this.controller.view.server_prompt.value ); */
560 if (typeof this.on_logoff == 'function') {
561 this.error.sdump('D_AUTH','auth.controller.on_logoff()\n');
566 'close' : function() {
568 this.error.sdump('D_AUTH','close' + this.w + '\n');
570 var confirm_string = document.getElementById('authStrings').getString('staff.auth.controller.confirm_close');
572 this.data.stash_retrieve();
573 if (typeof this.data.unsaved_data != 'undefined') {
574 if (this.data.unsaved_data > 0) {
575 confirm_string = document.getElementById('offlineStrings').getString('menu.shutdown.unsaved_data_warning');
579 if (window.confirm(confirm_string)) {
580 this.data.unsaved_data = 0;
581 this.data.stash('unsaved_data');
583 this.w.close(); /* Probably won't go any further */
585 if (typeof this.on_close == 'function') {
586 this.error.sdump('D_AUTH','auth.controller.on_close()\n');
594 dump('exiting auth/controller.js\n');