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*/
126 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
127 JSAN.use('util.file'); var file = new util.file('last_ws_server');
128 file.set_object(obj.controller.view.server_prompt.value);
132 document.createTextNode(
133 'Not yet configured for the specified server.'
144 function(e) { return function() {
151 obj.controller.view.name_prompt.focus();
153 function handle_keypress(ev) {
155 if (ev.keyCode && ev.keyCode == 13) {
157 case obj.controller.view.server_prompt:
159 obj.controller.view.name_prompt.focus(); obj.controller.view.name_prompt.select();
161 case obj.controller.view.name_prompt:
163 obj.controller.view.password_prompt.focus(); obj.controller.view.password_prompt.select();
165 case obj.controller.view.password_prompt:
167 obj.controller.view.submit_button.focus();
178 obj.controller.view.server_prompt.addEventListener(
181 obj.test_server(ev.target.value);
182 obj.controller.render('ws_deck');
187 // This talks to our ILS
188 JSAN.use('auth.session');
189 obj.session = new auth.session(obj.controller.view);
191 obj.controller.render();
192 obj.test_server( obj.controller.view.server_prompt.value );
193 obj.controller.render('ws_deck');
195 if (typeof this.on_init == 'function') {
196 this.error.sdump('D_AUTH','auth.controller.on_init()\n');
201 'test_server' : function(url) {
204 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
205 JSAN.use('util.file'); var file = new util.file('last_ws_server');
206 if (file._file.exists()) {
207 url = file.get_object(); file.close();
208 obj.controller.view.server_prompt.value = url;
211 obj.controller.view.submit_button.disabled = true;
212 obj.controller.view.server_prompt.disabled = true;
213 var s = document.getElementById('status');
214 s.setAttribute('value','Testing hostname...');
215 s.setAttribute('style','color: orange;');
216 document.getElementById('version').value = '';
218 s.setAttribute('value','Please enter a server hostname.');
219 s.setAttribute('style','color: red;');
220 obj.controller.view.server_prompt.disabled = false;
221 obj.controller.view.server_prompt.focus();
225 if ( ! url.match(/^http:\/\//) ) url = 'http://' + url;
226 var x = new XMLHttpRequest();
227 dump('server url = ' + url + '\n');
228 x.open("GET",url,true);
229 x.onreadystatechange = function() {
231 if (x.readyState != 4) return;
232 s.setAttribute('value',x.status + ' : ' + x.statusText);
233 if (x.status == 200) {
234 s.setAttribute('style','color: green;');
236 s.setAttribute('style','color: red;');
238 obj.test_version(url);
240 obj.controller.view.server_prompt.disabled = false;
241 obj.controller.view.server_prompt.focus();
242 s.setAttribute('value','There was an error testing this hostname.');
243 s.setAttribute('style','color: red;');
244 obj.error.sdump('D_ERROR',E);
249 s.setAttribute('value','There was an error testing this hostname.');
250 s.setAttribute('style','color: brown;');
251 obj.error.sdump('D_ERROR',E);
252 obj.controller.view.server_prompt.disabled = false;
253 obj.controller.view.server_prompt.focus();
257 'test_version' : function(url) {
259 var s = document.getElementById('version');
260 s.setAttribute('value','Testing version...');
261 s.setAttribute('style','color: orange;');
263 var x = new XMLHttpRequest();
264 var url2 = url + '/xul/server/';
265 dump('version url = ' + url2 + '\n');
266 x.open("GET",url2,true);
267 x.onreadystatechange = function() {
269 if (x.readyState != 4) return;
270 s.setAttribute('value',x.status + ' : ' + x.statusText);
271 if (x.status == 200) {
272 s.setAttribute('style','color: green;');
273 obj.controller.view.submit_button.disabled = false;
275 s.setAttribute('style','color: red;');
276 obj.test_upgrade_instructions(url);
278 obj.controller.view.server_prompt.disabled = false;
280 s.setAttribute('value','There was an error checking version support.');
281 s.setAttribute('style','color: red;');
282 obj.error.sdump('D_ERROR',E);
283 obj.controller.view.server_prompt.disabled = false;
288 s.setAttribute('value','There was an error checking version support.');
289 s.setAttribute('style','color: brown;');
290 obj.error.sdump('D_ERROR',E);
291 obj.controller.view.server_prompt.disabled = false;
295 'test_upgrade_instructions' : function(url) {
298 var x = new XMLHttpRequest();
299 var url2 = url + '/xul/versions.html';
300 dump('upgrade url = ' + url2 + '\n');
301 x.open("GET",url2,true);
302 x.onreadystatechange = function() {
304 if (x.readyState != 4) return;
305 if (x.status == 200) {
306 window.open('data:text/html,'+window.escape(x.responseText),'upgrade','chrome,resizable,modal,centered');
308 alert('This server does not support your version of the staff client. Please check with your system administrator.');
310 obj.controller.view.server_prompt.disabled = false;
312 obj.error.sdump('D_ERROR',E);
313 obj.controller.view.server_prompt.disabled = false;
318 obj.error.sdump('D_ERROR',E);
319 obj.controller.view.server_prompt.disabled = false;
323 'login' : function() {
327 this.error.sdump('D_AUTH','login with '
328 + this.controller.view.name_prompt.value + ' and '
329 + this.controller.view.password_prompt.value + ' at '
330 + this.controller.view.server_prompt.value + '\n'
332 this.controller.view.server_prompt.disabled = true;
333 this.controller.view.name_prompt.disabled = true;
334 this.controller.view.password_prompt.disabled = true;
335 this.controller.view.submit_button.disabled = true;
336 XML_HTTP_SERVER = this.controller.view.server_prompt.value;
340 if (typeof this.on_login == 'function') {
341 this.error.sdump('D_AUTH','auth.controller.session.on_init = ' +
342 'auth.controller.on_login\n');
343 this.session.on_init = this.on_login;
344 this.session.on_error = function() { obj.logoff(); };
350 var error = '!! ' + E + '\n';
351 this.error.sdump('D_ERROR',error);
354 if (E == 'open-ils.auth.authenticate.init returned false\n') {
355 this.controller.view.server_prompt.focus();
356 this.controller.view.server_prompt.select();
359 if (typeof this.on_login_error == 'function') {
360 this.error.sdump('D_AUTH','auth.controller.on_login_error()\n');
361 this.on_login_error(E);
367 'standalone' : function() {
370 if (typeof this.on_standalone == 'function') {
374 var error = '!! ' + E + '\n';
375 obj.error.sdump('D_ERROR',error);
380 'standalone_import' : function() {
383 if (typeof this.on_standalone_import == 'function') {
384 obj.on_standalone_import();
387 var error = '!! ' + E + '\n';
388 obj.error.sdump('D_ERROR',error);
393 'standalone_export' : function() {
396 if (typeof this.on_standalone_export == 'function') {
397 obj.on_standalone_export();
400 var error = '!! ' + E + '\n';
401 obj.error.sdump('D_ERROR',error);
406 'debug' : function(action) {
409 if (typeof this.on_debug == 'function') {
410 obj.on_debug(action);
413 var error = '!! ' + E + '\n';
414 obj.error.sdump('D_ERROR',error);
419 'logoff' : function() {
421 this.error.sdump('D_AUTH','logoff' + this.w + '\n');
422 this.controller.view.progress_bar.value = 0;
423 this.controller.view.progress_bar.setAttribute('real','0.0');
424 this.controller.view.submit_button.disabled = false;
425 this.controller.view.password_prompt.disabled = false;
426 this.controller.view.password_prompt.value = '';
427 this.controller.view.name_prompt.disabled = false;
428 this.controller.view.name_prompt.focus();
429 this.controller.view.name_prompt.select();
430 this.controller.view.server_prompt.disabled = false;
432 var windowManager = Components.classes["@mozilla.org/appshell/window-mediator;1"].getService();
433 var windowManagerInterface = windowManager.QueryInterface(Components.interfaces.nsIWindowMediator);
434 var enumerator = windowManagerInterface.getEnumerator(null);
436 var w; // close all other windows
437 while ( w = enumerator.getNext() ) {
438 if (w != window) w.close();
441 this.controller.render('ws_deck');
443 this.session.close();
445 /* FIXME - need some locking or object destruction for the async tests */
446 /* this.test_server( this.controller.view.server_prompt.value ); */
448 if (typeof this.on_logoff == 'function') {
449 this.error.sdump('D_AUTH','auth.controller.on_logoff()\n');
454 'close' : function() {
456 this.error.sdump('D_AUTH','close' + this.w + '\n');
458 //Basically, we want to close all the windows for this application (and in case we're running this as
459 //a firefox extension, we don't want to merely shutdown mozilla). I'll probably create an XPCOM for
460 //tracking the windows.
461 //for (var w in this.G.window.appshell_list) {
462 // this.G.window.appshell_list[w].close();
464 this.w.close(); /* Probably won't go any further */
466 if (typeof this.on_close == 'function') {
467 this.error.sdump('D_AUTH','auth.controller.on_close()\n');
474 dump('exiting auth/controller.js\n');