1 dump('entering auth/controller.js\n');
3 if (typeof auth == 'undefined') auth = {};
4 auth.controller = function (mw,G) {
6 this.mw = mw; this.G = G;
11 auth.controller.prototype = {
13 'init' : function () {
15 var obj = this; // so the 'this' in event handlers don't confuse us
19 // This talks to our ILS
20 JSAN.use('auth.session');
21 obj.session = new auth.session(obj,mw,G);
23 // Attach this object to the XUL through event listeners
25 var cmd_login = mw.document.getElementById('cmd_login');
27 cmd_login.addEventListener('command',function () { obj.login(); },false);
29 var cmd_logoff = mw.document.getElementById('cmd_logoff');
31 cmd_logoff.addEventListener('command',function () { obj.logoff(); },false);
33 var cmd_close_window = mw.document.getElementById('cmd_close_window');
35 cmd_close_window.addEventListener('command',function () { obj.close(); },false);
37 obj.view.name_prompt = mw.document.getElementById('name_prompt');
38 if (obj.view.name_prompt) {
39 obj.view.name_prompt.addEventListener('keypress',handle_keypress,false);
40 obj.view.name_prompt.focus();
43 obj.view.password_prompt = mw.document.getElementById('password_prompt');
44 if (obj.view.password_prompt)
45 obj.view.password_prompt.addEventListener('keypress',handle_keypress,false);
47 obj.view.submit_button = mw.document.getElementById('submit_button');
49 obj.view.progress_bar = mw.document.getElementById('auth_meter');
51 function handle_keypress(ev) {
52 if (ev.keyCode && ev.keyCode == 13) {
56 obj.view.password_prompt.focus(); obj.view.password_prompt.select();
58 case obj.view.password_prompt:
60 obj.view.submit_button.focus();
68 if (typeof this.on_init == 'function') {
69 this.G.error.sdump('D_AUTH','auth.controller.on_init()\n');
76 'login' : function() {
78 this.G.error.sdump('D_AUTH','login with ' + this.view.name_prompt.value + ' and ' + this.view.password_prompt.value + '\n');
79 this.view.name_prompt.disabled = true;
80 this.view.password_prompt.disabled = true;
81 this.view.submit_button.disabled = true;
85 if (typeof this.on_login == 'function') {
86 this.G.error.sdump('D_AUTH','auth.controller.session.on_init = ' +
87 'auth.controller.on_login\n');
88 this.session.on_init = this.on_login;
94 var error = '!! ' + E + '\n';
95 this.G.error.sdump('D_ERROR',error);
99 if (typeof this.on_login_error == 'function') {
100 this.G.error.sdump('D_AUTH','auth.controller.on_login_error()\n');
101 this.on_login_error(E);
106 'logoff' : function() {
108 this.G.error.sdump('D_AUTH','logoff' + this.mw + '\n');
109 this.view.progress_bar.value = 0; this.view.progress_bar.setAttribute('real','0.0');
110 this.view.submit_button.disabled = false;
111 this.view.password_prompt.disabled = false;
112 this.view.password_prompt.value = '';
113 this.view.name_prompt.disabled = false;
114 this.view.name_prompt.focus(); this.view.name_prompt.select();
116 this.session.close();
118 if (typeof this.on_logoff == 'function') {
119 this.G.error.sdump('D_AUTH','auth.controller.on_logoff()\n');
124 'close' : function() {
126 this.G.error.sdump('D_AUTH','close' + this.mw + '\n');
128 for (var w in this.G.window.appshell_list) {
129 this.G.window.appshell_list[w].close();
131 this.mw.close(); /* Probably won't go any further */
133 if (typeof this.on_close == 'function') {
134 this.G.error.sdump('D_AUTH','auth.controller.on_close()\n');
141 dump('exiting auth/controller.js\n');