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 alert(document.getElementById('authStrings').getString('staff.auth.controller.version_mismatch'));
393 obj.controller.view.server_prompt.disabled = false;
395 obj.error.sdump('D_ERROR',E);
396 obj.controller.view.server_prompt.disabled = false;
401 obj.error.sdump('D_ERROR',E);
402 obj.controller.view.server_prompt.disabled = false;
406 'login' : function() {
410 this.error.sdump('D_AUTH',
411 document.getElementById('authStrings').getFormattedString(
412 'staff.auth.controller.error_login', [
413 this.controller.view.name_prompt.value,
414 this.controller.view.password_prompt.value,
415 this.controller.view.server_prompt.value
419 this.controller.view.server_prompt.disabled = true;
420 this.controller.view.name_prompt.disabled = true;
421 this.controller.view.password_prompt.disabled = true;
422 this.controller.view.submit_button.disabled = true;
423 this.controller.view.apply_locale_btn.disabled = true;
424 XML_HTTP_SERVER = this.controller.view.server_prompt.value;
428 if (typeof this.on_login == 'function') {
429 this.error.sdump('D_AUTH','auth.controller.session.on_init = ' +
430 'auth.controller.on_login\n');
431 this.session.on_init = this.on_login;
432 this.session.on_error = function() { obj.logoff(); };
438 var error = '!! ' + E + '\n';
439 this.error.sdump('D_ERROR',error);
442 if (E == 'open-ils.auth.authenticate.init returned false\n') {
443 this.controller.view.server_prompt.focus();
444 this.controller.view.server_prompt.select();
447 if (typeof this.on_login_error == 'function') {
448 this.error.sdump('D_AUTH','auth.controller.on_login_error()\n');
449 this.on_login_error(E);
455 'standalone' : function() {
458 if (typeof this.on_standalone == 'function') {
462 var error = '!! ' + E + '\n';
463 obj.error.sdump('D_ERROR',error);
468 'standalone_import' : function() {
471 if (typeof this.on_standalone_import == 'function') {
472 obj.on_standalone_import();
475 var error = '!! ' + E + '\n';
476 obj.error.sdump('D_ERROR',error);
481 'standalone_export' : function() {
484 if (typeof this.on_standalone_export == 'function') {
485 obj.on_standalone_export();
488 var error = '!! ' + E + '\n';
489 obj.error.sdump('D_ERROR',error);
494 'debug' : function(action) {
497 if (typeof this.on_debug == 'function') {
498 obj.on_debug(action);
501 var error = '!! ' + E + '\n';
502 obj.error.sdump('D_ERROR',error);
507 'logoff' : function() {
509 this.error.sdump('D_AUTH','logoff' + this.w + '\n');
510 this.controller.view.progress_bar.value = 0;
511 this.controller.view.progress_bar.setAttribute('real','0.0');
512 this.controller.view.submit_button.disabled = false;
513 this.controller.view.apply_locale_btn.disabled = false;
514 this.controller.view.password_prompt.disabled = false;
515 this.controller.view.password_prompt.value = '';
516 this.controller.view.name_prompt.disabled = false;
517 this.controller.view.name_prompt.focus();
518 this.controller.view.name_prompt.select();
519 this.controller.view.server_prompt.disabled = false;
521 var windowManager = Components.classes["@mozilla.org/appshell/window-mediator;1"].getService();
522 var windowManagerInterface = windowManager.QueryInterface(Components.interfaces.nsIWindowMediator);
523 var enumerator = windowManagerInterface.getEnumerator(null);
525 var w; // close all other windows
526 while ( w = enumerator.getNext() ) {
528 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
532 this.controller.render('ws_deck');
534 this.session.close();
536 /* FIXME - need some locking or object destruction for the async tests */
537 /* this.test_server( this.controller.view.server_prompt.value ); */
539 if (typeof this.on_logoff == 'function') {
540 this.error.sdump('D_AUTH','auth.controller.on_logoff()\n');
545 'close' : function() {
547 this.error.sdump('D_AUTH','close' + this.w + '\n');
549 if (window.confirm(document.getElementById('authStrings').getString('staff.auth.controller.confirm_close'))) {
551 this.w.close(); /* Probably won't go any further */
553 if (typeof this.on_close == 'function') {
554 this.error.sdump('D_AUTH','auth.controller.on_close()\n');
562 dump('exiting auth/controller.js\n');