1 dump('entering auth/controller.js\n');
3 if (typeof auth == 'undefined') auth = {};
4 auth.controller = function (params) {
5 JSAN.use('util.error'); this.error = new util.error();
6 this.w = params.window;
11 auth.controller.prototype = {
13 'init' : function () {
15 var obj = this; // so the 'this' in event handlers don't confuse us
19 JSAN.use('util.controller'); obj.controller = new util.controller();
41 'cmd_close_window' : [
62 function(e) { return function() {} }
66 function(e) { return function() {} }
70 function(e) { return function() {
75 function(e) { return function() {
80 function(e) { return function() {
87 obj.controller.view.name_prompt.focus();
89 function handle_keypress(ev) {
91 if (ev.keyCode && ev.keyCode == 13) {
93 case obj.controller.view.server_prompt:
95 obj.controller.view.name_prompt.focus(); obj.controller.view.name_prompt.select();
97 case obj.controller.view.name_prompt:
99 obj.controller.view.password_prompt.focus(); obj.controller.view.password_prompt.select();
101 case obj.controller.view.password_prompt:
103 obj.controller.view.submit_button.focus();
114 // This talks to our ILS
115 JSAN.use('auth.session');
116 obj.session = new auth.session(obj.controller.view);
118 obj.controller.render();
120 if (typeof this.on_init == 'function') {
121 this.error.sdump('D_AUTH','auth.controller.on_init()\n');
126 'login' : function() {
130 this.error.sdump('D_AUTH','login with '
131 + this.controller.view.name_prompt.value + ' and '
132 + this.controller.view.password_prompt.value + ' at '
133 + this.controller.view.server_prompt.value + '\n'
135 this.controller.view.server_prompt.disabled = true;
136 this.controller.view.name_prompt.disabled = true;
137 this.controller.view.password_prompt.disabled = true;
138 this.controller.view.submit_button.disabled = true;
139 XML_HTTP_SERVER = this.controller.view.server_prompt.value;
143 if (typeof this.on_login == 'function') {
144 this.error.sdump('D_AUTH','auth.controller.session.on_init = ' +
145 'auth.controller.on_login\n');
146 this.session.on_init = this.on_login;
147 this.session.on_error = function() { obj.logoff(); };
153 var error = '!! ' + E + '\n';
154 this.error.sdump('D_ERROR',error);
157 if (E == 'open-ils.auth.authenticate.init returned false\n') {
158 this.controller.view.server_prompt.focus();
159 this.controller.view.server_prompt.select();
162 if (typeof this.on_login_error == 'function') {
163 this.error.sdump('D_AUTH','auth.controller.on_login_error()\n');
164 this.on_login_error(E);
170 'logoff' : function() {
172 this.error.sdump('D_AUTH','logoff' + this.w + '\n');
173 this.controller.view.progress_bar.value = 0;
174 this.controller.view.progress_bar.setAttribute('real','0.0');
175 this.controller.view.submit_button.disabled = false;
176 this.controller.view.password_prompt.disabled = false;
177 this.controller.view.password_prompt.value = '';
178 this.controller.view.name_prompt.disabled = false;
179 this.controller.view.name_prompt.focus();
180 this.controller.view.name_prompt.select();
181 this.controller.view.server_prompt.disabled = false;
183 var windowManager = Components.classes["@mozilla.org/appshell/window-mediator;1"].getService();
184 var windowManagerInterface = windowManager.QueryInterface(Components.interfaces.nsIWindowMediator);
185 var enumerator = windowManagerInterface.getEnumerator(null);
187 var w; // close all other windows
188 while ( w = enumerator.getNext() ) {
189 if (w != window) w.close();
192 this.session.close();
194 if (typeof this.on_logoff == 'function') {
195 this.error.sdump('D_AUTH','auth.controller.on_logoff()\n');
200 'close' : function() {
202 this.error.sdump('D_AUTH','close' + this.w + '\n');
204 //Basically, we want to close all the windows for this application (and in case we're running this as
205 //a firefox extension, we don't want to merely shutdown mozilla). I'll probably create an XPCOM for
206 //tracking the windows.
207 //for (var w in this.G.window.appshell_list) {
208 // this.G.window.appshell_list[w].close();
210 this.w.close(); /* Probably won't go any further */
212 if (typeof this.on_close == 'function') {
213 this.error.sdump('D_AUTH','auth.controller.on_close()\n');
220 dump('exiting auth/controller.js\n');