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
18 JSAN.use('OpenILS.data');
19 obj.data = new OpenILS.data(); obj.data.init({'via':'stash'});
22 JSAN.use('util.controller'); obj.controller = new util.controller();
44 'cmd_close_window' : [
65 function(e) { return function() {} }
69 function(e) { return function() {} }
73 function(e) { return function() {
78 function(e) { return function() {
80 JSAN.use('util.widgets'); util.widgets.remove_children(e);
81 if (obj.data.ws_info && obj.data.ws_info[ obj.controller.view.server_prompt.value ]) {
82 var ws = obj.data.ws_info[ obj.controller.view.server_prompt.value ];
83 var x = document.createElement('description');
86 document.createTextNode(
87 ws.name + ' @ ' + ws.lib_shortname
98 function(e) { return function() {
105 obj.controller.view.name_prompt.focus();
107 function handle_keypress(ev) {
109 if (ev.keyCode && ev.keyCode == 13) {
111 case obj.controller.view.server_prompt:
113 obj.controller.view.name_prompt.focus(); obj.controller.view.name_prompt.select();
115 case obj.controller.view.name_prompt:
117 obj.controller.view.password_prompt.focus(); obj.controller.view.password_prompt.select();
119 case obj.controller.view.password_prompt:
121 obj.controller.view.submit_button.focus();
132 obj.controller.view.server_prompt.addEventListener(
134 function () { obj.controller.render('ws_deck'); },
138 // This talks to our ILS
139 JSAN.use('auth.session');
140 obj.session = new auth.session(obj.controller.view);
142 obj.controller.render();
144 if (typeof this.on_init == 'function') {
145 this.error.sdump('D_AUTH','auth.controller.on_init()\n');
150 'login' : function() {
154 this.error.sdump('D_AUTH','login with '
155 + this.controller.view.name_prompt.value + ' and '
156 + this.controller.view.password_prompt.value + ' at '
157 + this.controller.view.server_prompt.value + '\n'
159 this.controller.view.server_prompt.disabled = true;
160 this.controller.view.name_prompt.disabled = true;
161 this.controller.view.password_prompt.disabled = true;
162 this.controller.view.submit_button.disabled = true;
163 XML_HTTP_SERVER = this.controller.view.server_prompt.value;
167 if (typeof this.on_login == 'function') {
168 this.error.sdump('D_AUTH','auth.controller.session.on_init = ' +
169 'auth.controller.on_login\n');
170 this.session.on_init = this.on_login;
171 this.session.on_error = function() { obj.logoff(); };
177 var error = '!! ' + E + '\n';
178 this.error.sdump('D_ERROR',error);
181 if (E == 'open-ils.auth.authenticate.init returned false\n') {
182 this.controller.view.server_prompt.focus();
183 this.controller.view.server_prompt.select();
186 if (typeof this.on_login_error == 'function') {
187 this.error.sdump('D_AUTH','auth.controller.on_login_error()\n');
188 this.on_login_error(E);
194 'logoff' : function() {
196 this.error.sdump('D_AUTH','logoff' + this.w + '\n');
197 this.controller.view.progress_bar.value = 0;
198 this.controller.view.progress_bar.setAttribute('real','0.0');
199 this.controller.view.submit_button.disabled = false;
200 this.controller.view.password_prompt.disabled = false;
201 this.controller.view.password_prompt.value = '';
202 this.controller.view.name_prompt.disabled = false;
203 this.controller.view.name_prompt.focus();
204 this.controller.view.name_prompt.select();
205 this.controller.view.server_prompt.disabled = false;
207 var windowManager = Components.classes["@mozilla.org/appshell/window-mediator;1"].getService();
208 var windowManagerInterface = windowManager.QueryInterface(Components.interfaces.nsIWindowMediator);
209 var enumerator = windowManagerInterface.getEnumerator(null);
211 var w; // close all other windows
212 while ( w = enumerator.getNext() ) {
213 if (w != window) w.close();
216 this.controller.render('ws_deck');
218 this.session.close();
220 if (typeof this.on_logoff == 'function') {
221 this.error.sdump('D_AUTH','auth.controller.on_logoff()\n');
226 'close' : function() {
228 this.error.sdump('D_AUTH','close' + this.w + '\n');
230 //Basically, we want to close all the windows for this application (and in case we're running this as
231 //a firefox extension, we don't want to merely shutdown mozilla). I'll probably create an XPCOM for
232 //tracking the windows.
233 //for (var w in this.G.window.appshell_list) {
234 // this.G.window.appshell_list[w].close();
236 this.w.close(); /* Probably won't go any further */
238 if (typeof this.on_close == 'function') {
239 this.error.sdump('D_AUTH','auth.controller.on_close()\n');
246 dump('exiting auth/controller.js\n');