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,
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 obj.controller.view.submit_button.disabled = true;
295 obj.controller.view.server_prompt.disabled = true;
296 var s = document.getElementById('status');
297 s.setAttribute('value', document.getElementById('authStrings').getString('staff.auth.controller.testing_hostname'));
298 s.setAttribute('style','color: orange;');
299 document.getElementById('version').value = '';
301 s.setAttribute('value', document.getElementById('authStrings').getString('staff.auth.controller.prompt_hostname'));
302 s.setAttribute('style','color: red;');
303 obj.controller.view.server_prompt.disabled = false;
304 obj.controller.view.server_prompt.focus();
308 if ( ! url.match(/^https:\/\//) ) url = 'https://' + url;
309 var x = new XMLHttpRequest();
310 dump('server url = ' + url + '\n');
311 x.open("GET",url,true);
312 x.onreadystatechange = function() {
314 if (x.readyState != 4) return;
315 s.setAttribute('value', document.getElementById('authStrings').getFormattedString('staff.auth.controller.status', [x.status, x.statusText]));
316 if (x.status == 200) {
317 s.setAttribute('style','color: green;');
319 s.setAttribute('style','color: red;');
321 obj.test_version(url);
323 obj.controller.view.server_prompt.disabled = false;
324 obj.controller.view.server_prompt.focus();
325 s.setAttribute('value', document.getElementById('authStrings').getString('staff.auth.controller.error_hostname'));
326 s.setAttribute('style','color: red;');
327 obj.error.sdump('D_ERROR',E);
332 s.setAttribute('value', document.getElementById('authStrings').getString('staff.auth.controller.error_hostname'));
333 s.setAttribute('style','color: brown;');
334 obj.error.sdump('D_ERROR',E);
335 obj.controller.view.server_prompt.disabled = false;
336 obj.controller.view.server_prompt.focus();
340 'test_version' : function(url) {
342 var s = document.getElementById('version');
343 s.setAttribute('value', document.getElementById('authStrings').getString('staff.auth.controller.testing_version'));
344 s.setAttribute('style','color: orange;');
346 var x = new XMLHttpRequest();
347 var url2 = url + '/xul/server/';
348 dump('version url = ' + url2 + '\n');
349 x.open("GET",url2,true);
350 x.onreadystatechange = function() {
352 if (x.readyState != 4) return;
353 s.setAttribute('value', document.getElementById('authStrings').getFormattedString('staff.auth.controller.status', [x.status, x.statusText]));
354 if (x.status == 200) {
355 s.setAttribute('style','color: green;');
356 obj.controller.view.submit_button.disabled = false;
358 s.setAttribute('style','color: red;');
359 obj.test_upgrade_instructions(url);
361 obj.controller.view.server_prompt.disabled = false;
363 s.setAttribute('value', document.getElementById('authStrings').getString('staff.auth.controller.error_version'));
364 s.setAttribute('style','color: red;');
365 obj.error.sdump('D_ERROR',E);
366 obj.controller.view.server_prompt.disabled = false;
371 s.setAttribute('value', document.getElementById('authStrings').getString('staff.auth.controller.error_version'));
372 s.setAttribute('style','color: brown;');
373 obj.error.sdump('D_ERROR',E);
374 obj.controller.view.server_prompt.disabled = false;
378 'test_upgrade_instructions' : function(url) {
381 var x = new XMLHttpRequest();
382 var url2 = url + '/xul/versions.html';
383 dump('upgrade url = ' + url2 + '\n');
384 x.open("GET",url2,true);
385 x.onreadystatechange = function() {
387 if (x.readyState != 4) return;
388 if (x.status == 200) {
389 window.open('data:text/html,'+window.escape(x.responseText),'upgrade','chrome,resizable,modal,centered');
391 if(typeof(G.upgradeCheck) == "function")
393 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."))
396 alert(document.getElementById('authStrings').getString('staff.auth.controller.version_mismatch'));
399 obj.controller.view.server_prompt.disabled = false;
401 obj.error.sdump('D_ERROR',E);
402 obj.controller.view.server_prompt.disabled = false;
407 obj.error.sdump('D_ERROR',E);
408 obj.controller.view.server_prompt.disabled = false;
412 'login' : function() {
416 this.error.sdump('D_AUTH',
417 document.getElementById('authStrings').getFormattedString(
418 'staff.auth.controller.error_login', [
419 this.controller.view.name_prompt.value,
420 this.controller.view.password_prompt.value,
421 this.controller.view.server_prompt.value
425 this.controller.view.server_prompt.disabled = true;
426 this.controller.view.name_prompt.disabled = true;
427 this.controller.view.password_prompt.disabled = true;
428 this.controller.view.submit_button.disabled = true;
429 this.controller.view.apply_locale_btn.disabled = true;
430 XML_HTTP_SERVER = this.controller.view.server_prompt.value;
434 if (typeof this.on_login == 'function') {
435 this.error.sdump('D_AUTH','auth.controller.session.on_init = ' +
436 'auth.controller.on_login\n');
437 this.session.on_init = this.on_login;
438 this.session.on_error = function() { obj.logoff(); };
444 var error = '!! ' + E + '\n';
445 this.error.sdump('D_ERROR',error);
448 if (E == 'open-ils.auth.authenticate.init returned false\n') {
449 this.controller.view.server_prompt.focus();
450 this.controller.view.server_prompt.select();
453 if (typeof this.on_login_error == 'function') {
454 this.error.sdump('D_AUTH','auth.controller.on_login_error()\n');
455 this.on_login_error(E);
461 'standalone' : function() {
464 if (typeof this.on_standalone == 'function') {
468 var error = '!! ' + E + '\n';
469 obj.error.sdump('D_ERROR',error);
474 'standalone_import' : function() {
477 if (typeof this.on_standalone_import == 'function') {
478 obj.on_standalone_import();
481 var error = '!! ' + E + '\n';
482 obj.error.sdump('D_ERROR',error);
487 'standalone_export' : function() {
490 if (typeof this.on_standalone_export == 'function') {
491 obj.on_standalone_export();
494 var error = '!! ' + E + '\n';
495 obj.error.sdump('D_ERROR',error);
500 'debug' : function(action) {
503 if (typeof this.on_debug == 'function') {
504 obj.on_debug(action);
507 var error = '!! ' + E + '\n';
508 obj.error.sdump('D_ERROR',error);
513 'logoff' : function() {
515 this.data.stash_retrieve();
516 if (typeof this.data.unsaved_data != 'undefined') {
517 if (this.data.unsaved_data > 0) {
518 var confirmation = window.confirm( document.getElementById('offlineStrings').getString('menu.logoff.unsaved_data_warning') );
519 if (!confirmation) { return; }
520 this.data.unsaved_data = 0;
521 this.data.stash('unsaved_data');
525 this.error.sdump('D_AUTH','logoff' + this.w + '\n');
526 this.controller.view.progress_bar.value = 0;
527 this.controller.view.progress_bar.setAttribute('real','0.0');
528 this.controller.view.submit_button.disabled = false;
529 this.controller.view.apply_locale_btn.disabled = false;
530 this.controller.view.password_prompt.disabled = false;
531 this.controller.view.password_prompt.value = '';
532 this.controller.view.name_prompt.disabled = false;
533 this.controller.view.name_prompt.focus();
534 this.controller.view.name_prompt.select();
535 this.controller.view.server_prompt.disabled = false;
537 var windowManager = Components.classes["@mozilla.org/appshell/window-mediator;1"].getService();
538 var windowManagerInterface = windowManager.QueryInterface(Components.interfaces.nsIWindowMediator);
539 var enumerator = windowManagerInterface.getEnumerator(null);
541 var w; // close all other windows
542 while ( w = enumerator.getNext() ) {
544 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
548 this.controller.render('ws_deck');
550 this.session.close();
551 this.data.menu_perms = false;
552 this.data.current_hotkeyset = undefined;
553 this.data.stash('menu_perms');
554 this.data.stash('current_hotkeyset');
556 /* FIXME - need some locking or object destruction for the async tests */
557 /* this.test_server( this.controller.view.server_prompt.value ); */
559 if (typeof this.on_logoff == 'function') {
560 this.error.sdump('D_AUTH','auth.controller.on_logoff()\n');
565 'close' : function() {
567 this.error.sdump('D_AUTH','close' + this.w + '\n');
569 var confirm_string = document.getElementById('authStrings').getString('staff.auth.controller.confirm_close');
571 this.data.stash_retrieve();
572 if (typeof this.data.unsaved_data != 'undefined') {
573 if (this.data.unsaved_data > 0) {
574 confirm_string = document.getElementById('offlineStrings').getString('menu.shutdown.unsaved_data_warning');
578 if (window.confirm(confirm_string)) {
579 this.data.unsaved_data = 0;
580 this.data.stash('unsaved_data');
582 this.w.close(); /* Probably won't go any further */
584 if (typeof this.on_close == 'function') {
585 this.error.sdump('D_AUTH','auth.controller.on_close()\n');
593 dump('exiting auth/controller.js\n');