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();
38 dump('cmd_register handler\n');
48 'cmd_close_window' : [
74 function(e) { return function() {} }
78 function(e) { return function() {} }
82 function(e) { return function() {} }
86 function(e) { return function() {
91 function(e) { return function() {
96 function(e) { return function() {
103 obj.controller.view.name_prompt.focus();
105 function handle_keypress(ev) {
107 if (ev.keyCode && ev.keyCode == 13) {
109 case obj.controller.view.server_prompt:
111 obj.controller.view.name_prompt.focus(); obj.controller.view.name_prompt.select();
113 case obj.controller.view.name_prompt:
115 obj.controller.view.password_prompt.focus(); obj.controller.view.password_prompt.select();
117 case obj.controller.view.password_prompt:
119 obj.controller.view.submit_button.focus();
122 case obj.controller.view.wsid_prompt:
124 obj.controller.view.register_button.focus();
135 // This talks to our ILS
136 JSAN.use('auth.session');
137 obj.session = new auth.session(obj.controller.view);
139 obj.controller.render();
141 if (typeof this.on_init == 'function') {
142 this.error.sdump('D_AUTH','auth.controller.on_init()\n');
147 'login' : function() {
151 this.error.sdump('D_AUTH','login with '
152 + this.controller.view.name_prompt.value + ' and '
153 + this.controller.view.password_prompt.value + ' at '
154 + this.controller.view.server_prompt.value + '\n'
156 this.controller.view.server_prompt.disabled = true;
157 this.controller.view.name_prompt.disabled = true;
158 this.controller.view.password_prompt.disabled = true;
159 this.controller.view.submit_button.disabled = true;
160 XML_HTTP_SERVER = this.controller.view.server_prompt.value;
164 if (typeof this.on_login == 'function') {
165 this.error.sdump('D_AUTH','auth.controller.session.on_init = ' +
166 'auth.controller.on_login\n');
167 this.session.on_init = this.on_login;
168 this.session.on_error = function() { obj.logoff(); };
174 var error = '!! ' + E + '\n';
175 this.error.sdump('D_ERROR',error);
178 if (E == 'open-ils.auth.authenticate.init returned false\n') {
179 this.controller.view.server_prompt.focus();
180 this.controller.view.server_prompt.select();
183 if (typeof this.on_login_error == 'function') {
184 this.error.sdump('D_AUTH','auth.controller.on_login_error()\n');
185 this.on_login_error(E);
191 'register' : function() {
193 dump('register code\n');
196 var orgid = obj.controller.view.menu_spot.firstChild.value;
197 var wsname = obj.controller.view.wsid_prompt.value;
199 obj.error.sdump('D_AUTH','register workstation with ' + orgid + ' and ' + wsname + '\n');
201 obj.controller.view.menu_spot.firstChild.disabled = true;
202 obj.controller.view.wsid_prompt.disabled = true;
206 var server = obj.controller.view.server_prompt.value;
208 if (typeof obj.on_register == 'function') {
209 dump('calling on_register\n');
210 obj.on_register(obj.session.key,server,orgid,wsname);
215 var error = '!! ' + E + '\n';
216 this.error.sdump('D_ERROR',error);
218 this.controller.view.menu_spot.firstChild.disabled = false;
219 this.controller.view.wsid_prompt.disabled = false;
227 'logoff' : function() {
229 this.error.sdump('D_AUTH','logoff' + this.w + '\n');
230 this.controller.view.progress_bar.value = 0;
231 this.controller.view.progress_bar.setAttribute('real','0.0');
232 this.controller.view.submit_button.disabled = false;
233 this.controller.view.password_prompt.disabled = false;
234 this.controller.view.password_prompt.value = '';
235 this.controller.view.name_prompt.disabled = false;
236 this.controller.view.name_prompt.focus();
237 this.controller.view.name_prompt.select();
238 this.controller.view.server_prompt.disabled = false;
240 var windowManager = Components.classes["@mozilla.org/appshell/window-mediator;1"].getService();
241 var windowManagerInterface = windowManager.QueryInterface(Components.interfaces.nsIWindowMediator);
242 var enumerator = windowManagerInterface.getEnumerator(null);
244 var w; // close all other windows
245 while ( w = enumerator.getNext() ) {
246 if (w != window) w.close();
249 this.session.close();
251 if (typeof this.on_logoff == 'function') {
252 this.error.sdump('D_AUTH','auth.controller.on_logoff()\n');
257 'close' : function() {
259 this.error.sdump('D_AUTH','close' + this.w + '\n');
261 //Basically, we want to close all the windows for this application (and in case we're running this as
262 //a firefox extension, we don't want to merely shutdown mozilla). I'll probably create an XPCOM for
263 //tracking the windows.
264 //for (var w in this.G.window.appshell_list) {
265 // this.G.window.appshell_list[w].close();
267 this.w.close(); /* Probably won't go any further */
269 if (typeof this.on_close == 'function') {
270 this.error.sdump('D_AUTH','auth.controller.on_close()\n');
277 dump('exiting auth/controller.js\n');