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();
41 obj.debug('clear_cache');
47 obj.debug('js_console');
62 'cmd_close_window' : [
83 function(e) { return function() {} }
87 function(e) { return function() {} }
91 function(e) { return function() {
96 function(e) { return function() {
98 JSAN.use('util.widgets'); util.widgets.remove_children(e);
99 var x = document.createElement('description');
102 && obj.data.ws_info[ obj.controller.view.server_prompt.value ]) {
103 var ws = obj.data.ws_info[ obj.controller.view.server_prompt.value ];
105 document.createTextNode(
106 ws.name + ' @ ' + ws.lib_shortname
111 document.createTextNode(
112 'Not yet configured for the specified server.'
123 function(e) { return function() {
130 obj.controller.view.name_prompt.focus();
132 function handle_keypress(ev) {
134 if (ev.keyCode && ev.keyCode == 13) {
136 case obj.controller.view.server_prompt:
138 obj.controller.view.name_prompt.focus(); obj.controller.view.name_prompt.select();
140 case obj.controller.view.name_prompt:
142 obj.controller.view.password_prompt.focus(); obj.controller.view.password_prompt.select();
144 case obj.controller.view.password_prompt:
146 obj.controller.view.submit_button.focus();
157 obj.controller.view.server_prompt.addEventListener(
160 obj.controller.render('ws_deck');
161 obj.test_server(ev.target.value);
166 // This talks to our ILS
167 JSAN.use('auth.session');
168 obj.session = new auth.session(obj.controller.view);
170 obj.controller.render();
171 obj.test_server( obj.controller.view.server_prompt.value );
173 if (typeof this.on_init == 'function') {
174 this.error.sdump('D_AUTH','auth.controller.on_init()\n');
179 'test_server' : function(url) {
181 obj.controller.view.submit_button.disabled = true;
182 obj.controller.view.server_prompt.disabled = true;
183 var s = document.getElementById('status');
184 s.setAttribute('value','Testing hostname...');
185 s.setAttribute('style','color: orange;');
186 document.getElementById('version').value = '';
188 s.setAttribute('value','Please enter a server hostname.');
189 s.setAttribute('style','color: red;');
190 obj.controller.view.server_prompt.disabled = false;
194 if ( ! url.match(/^http:\/\//) ) url = 'http://' + url;
195 var x = new XMLHttpRequest();
196 dump('server url = ' + url + '\n');
197 x.open("GET",url,true);
198 x.onreadystatechange = function() {
200 if (x.readyState != 4) return;
201 s.setAttribute('value',x.status + ' : ' + x.statusText);
202 if (x.status == 200) {
203 s.setAttribute('style','color: green;');
205 s.setAttribute('style','color: red;');
207 obj.test_version(url);
209 obj.controller.view.server_prompt.disabled = false;
210 s.setAttribute('value','There was an error testing this hostname.');
211 s.setAttribute('style','color: red;');
212 obj.error.sdump('D_ERROR',E);
217 s.setAttribute('value','There was an error testing this hostname.');
218 s.setAttribute('style','color: brown;');
219 obj.error.sdump('D_ERROR',E);
220 obj.controller.view.server_prompt.disabled = false;
224 'test_version' : function(url) {
226 var s = document.getElementById('version');
227 s.setAttribute('value','Testing version...');
228 s.setAttribute('style','color: orange;');
230 var x = new XMLHttpRequest();
231 var url2 = url + '/xul/server/';
232 dump('version url = ' + url2 + '\n');
233 x.open("GET",url2,true);
234 x.onreadystatechange = function() {
236 if (x.readyState != 4) return;
237 s.setAttribute('value',x.status + ' : ' + x.statusText);
238 if (x.status == 200) {
239 s.setAttribute('style','color: green;');
240 obj.controller.view.submit_button.disabled = false;
242 s.setAttribute('style','color: red;');
243 obj.test_upgrade_instructions(url);
245 obj.controller.view.server_prompt.disabled = false;
247 s.setAttribute('value','There was an error checking version support.');
248 s.setAttribute('style','color: red;');
249 obj.error.sdump('D_ERROR',E);
250 obj.controller.view.server_prompt.disabled = false;
255 s.setAttribute('value','There was an error checking version support.');
256 s.setAttribute('style','color: brown;');
257 obj.error.sdump('D_ERROR',E);
258 obj.controller.view.server_prompt.disabled = false;
262 'test_upgrade_instructions' : function(url) {
265 var x = new XMLHttpRequest();
266 var url2 = url + '/xul/versions.html';
267 dump('upgrade url = ' + url2 + '\n');
268 x.open("GET",url2,true);
269 x.onreadystatechange = function() {
271 if (x.readyState != 4) return;
272 if (x.status == 200) {
273 window.open('data:text/html,'+window.escape(x.responseText),'upgrade','chrome,resizable,modal,centered');
275 alert('This server does not support your version of the staff client. Please check with your system administrator.');
277 obj.controller.view.server_prompt.disabled = false;
279 obj.error.sdump('D_ERROR',E);
280 obj.controller.view.server_prompt.disabled = false;
285 obj.error.sdump('D_ERROR',E);
286 obj.controller.view.server_prompt.disabled = false;
290 'login' : function() {
294 this.error.sdump('D_AUTH','login with '
295 + this.controller.view.name_prompt.value + ' and '
296 + this.controller.view.password_prompt.value + ' at '
297 + this.controller.view.server_prompt.value + '\n'
299 this.controller.view.server_prompt.disabled = true;
300 this.controller.view.name_prompt.disabled = true;
301 this.controller.view.password_prompt.disabled = true;
302 this.controller.view.submit_button.disabled = true;
303 XML_HTTP_SERVER = this.controller.view.server_prompt.value;
307 if (typeof this.on_login == 'function') {
308 this.error.sdump('D_AUTH','auth.controller.session.on_init = ' +
309 'auth.controller.on_login\n');
310 this.session.on_init = this.on_login;
311 this.session.on_error = function() { obj.logoff(); };
317 var error = '!! ' + E + '\n';
318 this.error.sdump('D_ERROR',error);
321 if (E == 'open-ils.auth.authenticate.init returned false\n') {
322 this.controller.view.server_prompt.focus();
323 this.controller.view.server_prompt.select();
326 if (typeof this.on_login_error == 'function') {
327 this.error.sdump('D_AUTH','auth.controller.on_login_error()\n');
328 this.on_login_error(E);
334 'standalone' : function() {
337 if (typeof this.on_standalone == 'function') {
341 var error = '!! ' + E + '\n';
342 obj.error.sdump('D_ERROR',error);
347 'debug' : function(action) {
350 if (typeof this.on_debug == 'function') {
351 obj.on_debug(action);
354 var error = '!! ' + E + '\n';
355 obj.error.sdump('D_ERROR',error);
360 'logoff' : function() {
362 this.error.sdump('D_AUTH','logoff' + this.w + '\n');
363 this.controller.view.progress_bar.value = 0;
364 this.controller.view.progress_bar.setAttribute('real','0.0');
365 this.controller.view.submit_button.disabled = false;
366 this.controller.view.password_prompt.disabled = false;
367 this.controller.view.password_prompt.value = '';
368 this.controller.view.name_prompt.disabled = false;
369 this.controller.view.name_prompt.focus();
370 this.controller.view.name_prompt.select();
371 this.controller.view.server_prompt.disabled = false;
373 var windowManager = Components.classes["@mozilla.org/appshell/window-mediator;1"].getService();
374 var windowManagerInterface = windowManager.QueryInterface(Components.interfaces.nsIWindowMediator);
375 var enumerator = windowManagerInterface.getEnumerator(null);
377 var w; // close all other windows
378 while ( w = enumerator.getNext() ) {
379 if (w != window) w.close();
382 this.controller.render('ws_deck');
384 this.session.close();
386 /* FIXME - need some locking or object destruction for the async tests */
387 /* this.test_server( this.controller.view.server_prompt.value ); */
389 if (typeof this.on_logoff == 'function') {
390 this.error.sdump('D_AUTH','auth.controller.on_logoff()\n');
395 'close' : function() {
397 this.error.sdump('D_AUTH','close' + this.w + '\n');
399 //Basically, we want to close all the windows for this application (and in case we're running this as
400 //a firefox extension, we don't want to merely shutdown mozilla). I'll probably create an XPCOM for
401 //tracking the windows.
402 //for (var w in this.G.window.appshell_list) {
403 // this.G.window.appshell_list[w].close();
405 this.w.close(); /* Probably won't go any further */
407 if (typeof this.on_close == 'function') {
408 this.error.sdump('D_AUTH','auth.controller.on_close()\n');
415 dump('exiting auth/controller.js\n');