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();
38 'cmd_standalone_import' : [
41 obj.standalone_import();
44 'cmd_standalone_export' : [
47 obj.standalone_export();
53 obj.debug('clear_cache');
59 obj.debug('js_console');
74 'cmd_close_window' : [
95 function(e) { return function() {} }
99 function(e) { return function() {} }
103 function(e) { return function() {
108 function(e) { return function() {
110 JSAN.use('util.widgets'); util.widgets.remove_children(e);
111 var x = document.createElement('description');
114 && obj.data.ws_info[ obj.controller.view.server_prompt.value ]) {
115 var ws = obj.data.ws_info[ obj.controller.view.server_prompt.value ];
117 document.createTextNode(
118 ws.name + ' @ ' + ws.lib_shortname
123 document.createTextNode(
124 'Not yet configured for the specified server.'
135 function(e) { return function() {
142 obj.controller.view.name_prompt.focus();
144 function handle_keypress(ev) {
146 if (ev.keyCode && ev.keyCode == 13) {
148 case obj.controller.view.server_prompt:
150 obj.controller.view.name_prompt.focus(); obj.controller.view.name_prompt.select();
152 case obj.controller.view.name_prompt:
154 obj.controller.view.password_prompt.focus(); obj.controller.view.password_prompt.select();
156 case obj.controller.view.password_prompt:
158 obj.controller.view.submit_button.focus();
169 obj.controller.view.server_prompt.addEventListener(
172 obj.controller.render('ws_deck');
173 obj.test_server(ev.target.value);
178 // This talks to our ILS
179 JSAN.use('auth.session');
180 obj.session = new auth.session(obj.controller.view);
182 obj.controller.render();
183 obj.test_server( obj.controller.view.server_prompt.value );
185 if (typeof this.on_init == 'function') {
186 this.error.sdump('D_AUTH','auth.controller.on_init()\n');
191 'test_server' : function(url) {
193 obj.controller.view.submit_button.disabled = true;
194 obj.controller.view.server_prompt.disabled = true;
195 var s = document.getElementById('status');
196 s.setAttribute('value','Testing hostname...');
197 s.setAttribute('style','color: orange;');
198 document.getElementById('version').value = '';
200 s.setAttribute('value','Please enter a server hostname.');
201 s.setAttribute('style','color: red;');
202 obj.controller.view.server_prompt.disabled = false;
206 if ( ! url.match(/^http:\/\//) ) url = 'http://' + url;
207 var x = new XMLHttpRequest();
208 dump('server url = ' + url + '\n');
209 x.open("GET",url,true);
210 x.onreadystatechange = function() {
212 if (x.readyState != 4) return;
213 s.setAttribute('value',x.status + ' : ' + x.statusText);
214 if (x.status == 200) {
215 s.setAttribute('style','color: green;');
217 s.setAttribute('style','color: red;');
219 obj.test_version(url);
221 obj.controller.view.server_prompt.disabled = false;
222 s.setAttribute('value','There was an error testing this hostname.');
223 s.setAttribute('style','color: red;');
224 obj.error.sdump('D_ERROR',E);
229 s.setAttribute('value','There was an error testing this hostname.');
230 s.setAttribute('style','color: brown;');
231 obj.error.sdump('D_ERROR',E);
232 obj.controller.view.server_prompt.disabled = false;
236 'test_version' : function(url) {
238 var s = document.getElementById('version');
239 s.setAttribute('value','Testing version...');
240 s.setAttribute('style','color: orange;');
242 var x = new XMLHttpRequest();
243 var url2 = url + '/xul/server/';
244 dump('version url = ' + url2 + '\n');
245 x.open("GET",url2,true);
246 x.onreadystatechange = function() {
248 if (x.readyState != 4) return;
249 s.setAttribute('value',x.status + ' : ' + x.statusText);
250 if (x.status == 200) {
251 s.setAttribute('style','color: green;');
252 obj.controller.view.submit_button.disabled = false;
254 s.setAttribute('style','color: red;');
255 obj.test_upgrade_instructions(url);
257 obj.controller.view.server_prompt.disabled = false;
259 s.setAttribute('value','There was an error checking version support.');
260 s.setAttribute('style','color: red;');
261 obj.error.sdump('D_ERROR',E);
262 obj.controller.view.server_prompt.disabled = false;
267 s.setAttribute('value','There was an error checking version support.');
268 s.setAttribute('style','color: brown;');
269 obj.error.sdump('D_ERROR',E);
270 obj.controller.view.server_prompt.disabled = false;
274 'test_upgrade_instructions' : function(url) {
277 var x = new XMLHttpRequest();
278 var url2 = url + '/xul/versions.html';
279 dump('upgrade url = ' + url2 + '\n');
280 x.open("GET",url2,true);
281 x.onreadystatechange = function() {
283 if (x.readyState != 4) return;
284 if (x.status == 200) {
285 window.open('data:text/html,'+window.escape(x.responseText),'upgrade','chrome,resizable,modal,centered');
287 alert('This server does not support your version of the staff client. Please check with your system administrator.');
289 obj.controller.view.server_prompt.disabled = false;
291 obj.error.sdump('D_ERROR',E);
292 obj.controller.view.server_prompt.disabled = false;
297 obj.error.sdump('D_ERROR',E);
298 obj.controller.view.server_prompt.disabled = false;
302 'login' : function() {
306 this.error.sdump('D_AUTH','login with '
307 + this.controller.view.name_prompt.value + ' and '
308 + this.controller.view.password_prompt.value + ' at '
309 + this.controller.view.server_prompt.value + '\n'
311 this.controller.view.server_prompt.disabled = true;
312 this.controller.view.name_prompt.disabled = true;
313 this.controller.view.password_prompt.disabled = true;
314 this.controller.view.submit_button.disabled = true;
315 XML_HTTP_SERVER = this.controller.view.server_prompt.value;
319 if (typeof this.on_login == 'function') {
320 this.error.sdump('D_AUTH','auth.controller.session.on_init = ' +
321 'auth.controller.on_login\n');
322 this.session.on_init = this.on_login;
323 this.session.on_error = function() { obj.logoff(); };
329 var error = '!! ' + E + '\n';
330 this.error.sdump('D_ERROR',error);
333 if (E == 'open-ils.auth.authenticate.init returned false\n') {
334 this.controller.view.server_prompt.focus();
335 this.controller.view.server_prompt.select();
338 if (typeof this.on_login_error == 'function') {
339 this.error.sdump('D_AUTH','auth.controller.on_login_error()\n');
340 this.on_login_error(E);
346 'standalone' : function() {
349 if (typeof this.on_standalone == 'function') {
353 var error = '!! ' + E + '\n';
354 obj.error.sdump('D_ERROR',error);
359 'standalone_import' : function() {
362 if (typeof this.on_standalone_import == 'function') {
363 obj.on_standalone_import();
366 var error = '!! ' + E + '\n';
367 obj.error.sdump('D_ERROR',error);
372 'standalone_export' : function() {
375 if (typeof this.on_standalone_export == 'function') {
376 obj.on_standalone_export();
379 var error = '!! ' + E + '\n';
380 obj.error.sdump('D_ERROR',error);
385 'debug' : function(action) {
388 if (typeof this.on_debug == 'function') {
389 obj.on_debug(action);
392 var error = '!! ' + E + '\n';
393 obj.error.sdump('D_ERROR',error);
398 'logoff' : function() {
400 this.error.sdump('D_AUTH','logoff' + this.w + '\n');
401 this.controller.view.progress_bar.value = 0;
402 this.controller.view.progress_bar.setAttribute('real','0.0');
403 this.controller.view.submit_button.disabled = false;
404 this.controller.view.password_prompt.disabled = false;
405 this.controller.view.password_prompt.value = '';
406 this.controller.view.name_prompt.disabled = false;
407 this.controller.view.name_prompt.focus();
408 this.controller.view.name_prompt.select();
409 this.controller.view.server_prompt.disabled = false;
411 var windowManager = Components.classes["@mozilla.org/appshell/window-mediator;1"].getService();
412 var windowManagerInterface = windowManager.QueryInterface(Components.interfaces.nsIWindowMediator);
413 var enumerator = windowManagerInterface.getEnumerator(null);
415 var w; // close all other windows
416 while ( w = enumerator.getNext() ) {
417 if (w != window) w.close();
420 this.controller.render('ws_deck');
422 this.session.close();
424 /* FIXME - need some locking or object destruction for the async tests */
425 /* this.test_server( this.controller.view.server_prompt.value ); */
427 if (typeof this.on_logoff == 'function') {
428 this.error.sdump('D_AUTH','auth.controller.on_logoff()\n');
433 'close' : function() {
435 this.error.sdump('D_AUTH','close' + this.w + '\n');
437 //Basically, we want to close all the windows for this application (and in case we're running this as
438 //a firefox extension, we don't want to merely shutdown mozilla). I'll probably create an XPCOM for
439 //tracking the windows.
440 //for (var w in this.G.window.appshell_list) {
441 // this.G.window.appshell_list[w].close();
443 this.w.close(); /* Probably won't go any further */
445 if (typeof this.on_close == 'function') {
446 this.error.sdump('D_AUTH','auth.controller.on_close()\n');
453 dump('exiting auth/controller.js\n');