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' : [
83 obj.test_server( obj.controller.view.server_prompt.value );
100 function(e) { return function() {} }
104 function(e) { return function() {} }
108 function(e) { return function() {
113 function(e) { return function() {
115 JSAN.use('util.widgets'); util.widgets.remove_children(e);
116 var x = document.createElement('description');
119 && obj.data.ws_info[ obj.controller.view.server_prompt.value ]) {
120 var ws = obj.data.ws_info[ obj.controller.view.server_prompt.value ];
122 document.createTextNode(
123 ws.name + ' @ ' + ws.lib_shortname
128 document.createTextNode(
129 'Not yet configured for the specified server.'
140 function(e) { return function() {
147 obj.controller.view.name_prompt.focus();
149 function handle_keypress(ev) {
151 if (ev.keyCode && ev.keyCode == 13) {
153 case obj.controller.view.server_prompt:
155 obj.controller.view.name_prompt.focus(); obj.controller.view.name_prompt.select();
157 case obj.controller.view.name_prompt:
159 obj.controller.view.password_prompt.focus(); obj.controller.view.password_prompt.select();
161 case obj.controller.view.password_prompt:
163 obj.controller.view.submit_button.focus();
174 obj.controller.view.server_prompt.addEventListener(
177 obj.controller.render('ws_deck');
178 obj.test_server(ev.target.value);
183 // This talks to our ILS
184 JSAN.use('auth.session');
185 obj.session = new auth.session(obj.controller.view);
187 obj.controller.render();
188 obj.test_server( obj.controller.view.server_prompt.value );
190 if (typeof this.on_init == 'function') {
191 this.error.sdump('D_AUTH','auth.controller.on_init()\n');
196 'test_server' : function(url) {
198 obj.controller.view.submit_button.disabled = true;
199 obj.controller.view.server_prompt.disabled = true;
200 var s = document.getElementById('status');
201 s.setAttribute('value','Testing hostname...');
202 s.setAttribute('style','color: orange;');
203 document.getElementById('version').value = '';
205 s.setAttribute('value','Please enter a server hostname.');
206 s.setAttribute('style','color: red;');
207 obj.controller.view.server_prompt.disabled = false;
211 if ( ! url.match(/^http:\/\//) ) url = 'http://' + url;
212 var x = new XMLHttpRequest();
213 dump('server url = ' + url + '\n');
214 x.open("GET",url,true);
215 x.onreadystatechange = function() {
217 if (x.readyState != 4) return;
218 s.setAttribute('value',x.status + ' : ' + x.statusText);
219 if (x.status == 200) {
220 s.setAttribute('style','color: green;');
222 s.setAttribute('style','color: red;');
224 obj.test_version(url);
226 obj.controller.view.server_prompt.disabled = false;
227 s.setAttribute('value','There was an error testing this hostname.');
228 s.setAttribute('style','color: red;');
229 obj.error.sdump('D_ERROR',E);
234 s.setAttribute('value','There was an error testing this hostname.');
235 s.setAttribute('style','color: brown;');
236 obj.error.sdump('D_ERROR',E);
237 obj.controller.view.server_prompt.disabled = false;
241 'test_version' : function(url) {
243 var s = document.getElementById('version');
244 s.setAttribute('value','Testing version...');
245 s.setAttribute('style','color: orange;');
247 var x = new XMLHttpRequest();
248 var url2 = url + '/xul/server/';
249 dump('version url = ' + url2 + '\n');
250 x.open("GET",url2,true);
251 x.onreadystatechange = function() {
253 if (x.readyState != 4) return;
254 s.setAttribute('value',x.status + ' : ' + x.statusText);
255 if (x.status == 200) {
256 s.setAttribute('style','color: green;');
257 obj.controller.view.submit_button.disabled = false;
259 s.setAttribute('style','color: red;');
260 obj.test_upgrade_instructions(url);
262 obj.controller.view.server_prompt.disabled = false;
264 s.setAttribute('value','There was an error checking version support.');
265 s.setAttribute('style','color: red;');
266 obj.error.sdump('D_ERROR',E);
267 obj.controller.view.server_prompt.disabled = false;
272 s.setAttribute('value','There was an error checking version support.');
273 s.setAttribute('style','color: brown;');
274 obj.error.sdump('D_ERROR',E);
275 obj.controller.view.server_prompt.disabled = false;
279 'test_upgrade_instructions' : function(url) {
282 var x = new XMLHttpRequest();
283 var url2 = url + '/xul/versions.html';
284 dump('upgrade url = ' + url2 + '\n');
285 x.open("GET",url2,true);
286 x.onreadystatechange = function() {
288 if (x.readyState != 4) return;
289 if (x.status == 200) {
290 window.open('data:text/html,'+window.escape(x.responseText),'upgrade','chrome,resizable,modal,centered');
292 alert('This server does not support your version of the staff client. Please check with your system administrator.');
294 obj.controller.view.server_prompt.disabled = false;
296 obj.error.sdump('D_ERROR',E);
297 obj.controller.view.server_prompt.disabled = false;
302 obj.error.sdump('D_ERROR',E);
303 obj.controller.view.server_prompt.disabled = false;
307 'login' : function() {
311 this.error.sdump('D_AUTH','login with '
312 + this.controller.view.name_prompt.value + ' and '
313 + this.controller.view.password_prompt.value + ' at '
314 + this.controller.view.server_prompt.value + '\n'
316 this.controller.view.server_prompt.disabled = true;
317 this.controller.view.name_prompt.disabled = true;
318 this.controller.view.password_prompt.disabled = true;
319 this.controller.view.submit_button.disabled = true;
320 XML_HTTP_SERVER = this.controller.view.server_prompt.value;
324 if (typeof this.on_login == 'function') {
325 this.error.sdump('D_AUTH','auth.controller.session.on_init = ' +
326 'auth.controller.on_login\n');
327 this.session.on_init = this.on_login;
328 this.session.on_error = function() { obj.logoff(); };
334 var error = '!! ' + E + '\n';
335 this.error.sdump('D_ERROR',error);
338 if (E == 'open-ils.auth.authenticate.init returned false\n') {
339 this.controller.view.server_prompt.focus();
340 this.controller.view.server_prompt.select();
343 if (typeof this.on_login_error == 'function') {
344 this.error.sdump('D_AUTH','auth.controller.on_login_error()\n');
345 this.on_login_error(E);
351 'standalone' : function() {
354 if (typeof this.on_standalone == 'function') {
358 var error = '!! ' + E + '\n';
359 obj.error.sdump('D_ERROR',error);
364 'standalone_import' : function() {
367 if (typeof this.on_standalone_import == 'function') {
368 obj.on_standalone_import();
371 var error = '!! ' + E + '\n';
372 obj.error.sdump('D_ERROR',error);
377 'standalone_export' : function() {
380 if (typeof this.on_standalone_export == 'function') {
381 obj.on_standalone_export();
384 var error = '!! ' + E + '\n';
385 obj.error.sdump('D_ERROR',error);
390 'debug' : function(action) {
393 if (typeof this.on_debug == 'function') {
394 obj.on_debug(action);
397 var error = '!! ' + E + '\n';
398 obj.error.sdump('D_ERROR',error);
403 'logoff' : function() {
405 this.error.sdump('D_AUTH','logoff' + this.w + '\n');
406 this.controller.view.progress_bar.value = 0;
407 this.controller.view.progress_bar.setAttribute('real','0.0');
408 this.controller.view.submit_button.disabled = false;
409 this.controller.view.password_prompt.disabled = false;
410 this.controller.view.password_prompt.value = '';
411 this.controller.view.name_prompt.disabled = false;
412 this.controller.view.name_prompt.focus();
413 this.controller.view.name_prompt.select();
414 this.controller.view.server_prompt.disabled = false;
416 var windowManager = Components.classes["@mozilla.org/appshell/window-mediator;1"].getService();
417 var windowManagerInterface = windowManager.QueryInterface(Components.interfaces.nsIWindowMediator);
418 var enumerator = windowManagerInterface.getEnumerator(null);
420 var w; // close all other windows
421 while ( w = enumerator.getNext() ) {
422 if (w != window) w.close();
425 this.controller.render('ws_deck');
427 this.session.close();
429 /* FIXME - need some locking or object destruction for the async tests */
430 /* this.test_server( this.controller.view.server_prompt.value ); */
432 if (typeof this.on_logoff == 'function') {
433 this.error.sdump('D_AUTH','auth.controller.on_logoff()\n');
438 'close' : function() {
440 this.error.sdump('D_AUTH','close' + this.w + '\n');
442 //Basically, we want to close all the windows for this application (and in case we're running this as
443 //a firefox extension, we don't want to merely shutdown mozilla). I'll probably create an XPCOM for
444 //tracking the windows.
445 //for (var w in this.G.window.appshell_list) {
446 // this.G.window.appshell_list[w].close();
448 this.w.close(); /* Probably won't go any further */
450 if (typeof this.on_close == 'function') {
451 this.error.sdump('D_AUTH','auth.controller.on_close()\n');
458 dump('exiting auth/controller.js\n');