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();
35 'cmd_close_window' : [
55 function(e) { return function() {} }
59 function(e) { return function() {} }
64 obj.controller.view.name_prompt.focus();
66 function handle_keypress(ev) {
67 if (ev.keyCode && ev.keyCode == 13) {
69 case obj.controller.view.server_prompt:
71 obj.controller.view.name_prompt.focus(); obj.controller.view.name_prompt.select();
73 case obj.controller.view.name_prompt:
75 obj.controller.view.password_prompt.focus(); obj.controller.view.password_prompt.select();
77 case obj.controller.view.password_prompt:
79 obj.controller.view.submit_button.focus();
87 // This talks to our ILS
88 JSAN.use('auth.session');
89 obj.session = new auth.session(obj.controller.view);
91 if (typeof this.on_init == 'function') {
92 this.error.sdump('D_AUTH','auth.controller.on_init()\n');
97 'login' : function() {
101 this.error.sdump('D_AUTH','login with '
102 + this.controller.view.name_prompt.value + ' and '
103 + this.controller.view.password_prompt.value + ' at '
104 + this.controller.view.server_prompt.value + '\n'
106 this.controller.view.server_prompt.disabled = true;
107 this.controller.view.name_prompt.disabled = true;
108 this.controller.view.password_prompt.disabled = true;
109 this.controller.view.submit_button.disabled = true;
110 XML_HTTP_SERVER = this.controller.view.server_prompt.value;
114 if (typeof this.on_login == 'function') {
115 this.error.sdump('D_AUTH','auth.controller.session.on_init = ' +
116 'auth.controller.on_login\n');
117 this.session.on_init = this.on_login;
118 this.session.on_error = function() { obj.logoff(); };
124 var error = '!! ' + E + '\n';
125 this.error.sdump('D_ERROR',error);
128 if (E == 'open-ils.auth.authenticate.init returned false\n') {
129 this.controller.view.server_prompt.focus();
130 this.controller.view.server_prompt.select();
133 if (typeof this.on_login_error == 'function') {
134 this.error.sdump('D_AUTH','auth.controller.on_login_error()\n');
135 this.on_login_error(E);
140 'logoff' : function() {
142 this.error.sdump('D_AUTH','logoff' + this.w + '\n');
143 this.controller.view.progress_bar.value = 0;
144 this.controller.view.progress_bar.setAttribute('real','0.0');
145 this.controller.view.submit_button.disabled = false;
146 this.controller.view.password_prompt.disabled = false;
147 this.controller.view.password_prompt.value = '';
148 this.controller.view.name_prompt.disabled = false;
149 this.controller.view.name_prompt.focus();
150 this.controller.view.name_prompt.select();
151 this.controller.view.server_prompt.disabled = false;
153 var windowManager = Components.classes["@mozilla.org/appshell/window-mediator;1"].getService();
154 var windowManagerInterface = windowManager.QueryInterface(Components.interfaces.nsIWindowMediator);
155 var enumerator = windowManagerInterface.getEnumerator(null);
157 var w; // close all other windows
158 while ( w = enumerator.getNext() ) {
159 if (w != window) w.close();
162 this.session.close();
164 if (typeof this.on_logoff == 'function') {
165 this.error.sdump('D_AUTH','auth.controller.on_logoff()\n');
170 'close' : function() {
172 this.error.sdump('D_AUTH','close' + this.w + '\n');
174 //Basically, we want to close all the windows for this application (and in case we're running this as
175 //a firefox extension, we don't want to merely shutdown mozilla). I'll probably create an XPCOM for
176 //tracking the windows.
177 //for (var w in this.G.window.appshell_list) {
178 // this.G.window.appshell_list[w].close();
180 this.w.close(); /* Probably won't go any further */
182 if (typeof this.on_close == 'function') {
183 this.error.sdump('D_AUTH','auth.controller.on_close()\n');
190 dump('exiting auth/controller.js\n');