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 var x = document.createElement('description');
84 && obj.data.ws_info[ obj.controller.view.server_prompt.value ]) {
85 var ws = obj.data.ws_info[ obj.controller.view.server_prompt.value ];
87 document.createTextNode(
88 ws.name + ' @ ' + ws.lib_shortname
93 document.createTextNode(
94 'Not yet configured for the specified server.'
105 function(e) { return function() {
112 obj.controller.view.name_prompt.focus();
114 function handle_keypress(ev) {
116 if (ev.keyCode && ev.keyCode == 13) {
118 case obj.controller.view.server_prompt:
120 obj.controller.view.name_prompt.focus(); obj.controller.view.name_prompt.select();
122 case obj.controller.view.name_prompt:
124 obj.controller.view.password_prompt.focus(); obj.controller.view.password_prompt.select();
126 case obj.controller.view.password_prompt:
128 obj.controller.view.submit_button.focus();
139 obj.controller.view.server_prompt.addEventListener(
142 obj.controller.render('ws_deck');
143 obj.test_server(ev.target.value);
148 // This talks to our ILS
149 JSAN.use('auth.session');
150 obj.session = new auth.session(obj.controller.view);
152 obj.controller.render();
153 obj.test_server( obj.controller.view.server_prompt.value );
155 if (typeof this.on_init == 'function') {
156 this.error.sdump('D_AUTH','auth.controller.on_init()\n');
161 'test_server' : function(url) {
163 obj.controller.view.submit_button.disabled = true;
164 obj.controller.view.server_prompt.disabled = true;
165 var s = document.getElementById('status');
166 s.setAttribute('value','Testing hostname...');
167 s.setAttribute('style','color: orange;');
168 document.getElementById('version').value = '';
170 s.setAttribute('value','Please enter a server hostname.');
171 s.setAttribute('style','color: red;');
172 obj.controller.view.server_prompt.disabled = false;
176 if ( ! url.match(/^http:\/\//) ) url = 'http://' + url;
177 var x = new XMLHttpRequest();
178 dump('server url = ' + url + '\n');
179 x.open("GET",url,true);
180 x.onreadystatechange = function() {
182 if (x.readyState != 4) return;
183 s.setAttribute('value',x.status + ' : ' + x.statusText);
184 if (x.status == 200) {
185 s.setAttribute('style','color: green;');
187 s.setAttribute('style','color: red;');
189 obj.test_version(url);
191 s.setAttribute('value','There was an error testing this hostname.');
192 s.setAttribute('style','color: red;');
193 obj.error.sdump('D_ERROR',E);
198 s.setAttribute('value','There was an error testing this hostname.');
199 s.setAttribute('style','color: brown;');
200 obj.error.sdump('D_ERROR',E);
204 'test_version' : function(url) {
206 var s = document.getElementById('version');
207 s.setAttribute('value','Testing version...');
208 s.setAttribute('style','color: orange;');
210 var x = new XMLHttpRequest();
211 var url2 = url + '/xul/server/';
212 dump('version url = ' + url2 + '\n');
213 x.open("GET",url2,true);
214 x.onreadystatechange = function() {
216 if (x.readyState != 4) return;
217 s.setAttribute('value',x.status + ' : ' + x.statusText);
218 if (x.status == 200) {
219 s.setAttribute('style','color: green;');
220 obj.controller.view.submit_button.disabled = false;
222 s.setAttribute('style','color: red;');
223 obj.test_upgrade_instructions(url);
225 obj.controller.view.server_prompt.disabled = false;
227 s.setAttribute('value','There was an error checking version support.');
228 s.setAttribute('style','color: red;');
229 obj.error.sdump('D_ERROR',E);
234 s.setAttribute('value','There was an error checking version support.');
235 s.setAttribute('style','color: brown;');
236 obj.error.sdump('D_ERROR',E);
240 'test_upgrade_instructions' : function(url) {
243 var x = new XMLHttpRequest();
244 var url2 = url + '/xul/versions.html';
245 dump('upgrade url = ' + url2 + '\n');
246 x.open("GET",url2,true);
247 x.onreadystatechange = function() {
249 if (x.readyState != 4) return;
250 if (x.status == 200) {
251 window.open('data:text/html,'+window.escape(x.responseText),'upgrade','chrome,resizable,modal,centered');
253 alert('This server does not support your version of the staff client. Please check with your system administrator.');
256 obj.error.sdump('D_ERROR',E);
261 obj.error.sdump('D_ERROR',E);
265 'login' : function() {
269 this.error.sdump('D_AUTH','login with '
270 + this.controller.view.name_prompt.value + ' and '
271 + this.controller.view.password_prompt.value + ' at '
272 + this.controller.view.server_prompt.value + '\n'
274 this.controller.view.server_prompt.disabled = true;
275 this.controller.view.name_prompt.disabled = true;
276 this.controller.view.password_prompt.disabled = true;
277 this.controller.view.submit_button.disabled = true;
278 XML_HTTP_SERVER = this.controller.view.server_prompt.value;
282 if (typeof this.on_login == 'function') {
283 this.error.sdump('D_AUTH','auth.controller.session.on_init = ' +
284 'auth.controller.on_login\n');
285 this.session.on_init = this.on_login;
286 this.session.on_error = function() { obj.logoff(); };
292 var error = '!! ' + E + '\n';
293 this.error.sdump('D_ERROR',error);
296 if (E == 'open-ils.auth.authenticate.init returned false\n') {
297 this.controller.view.server_prompt.focus();
298 this.controller.view.server_prompt.select();
301 if (typeof this.on_login_error == 'function') {
302 this.error.sdump('D_AUTH','auth.controller.on_login_error()\n');
303 this.on_login_error(E);
309 'logoff' : function() {
311 this.error.sdump('D_AUTH','logoff' + this.w + '\n');
312 this.controller.view.progress_bar.value = 0;
313 this.controller.view.progress_bar.setAttribute('real','0.0');
314 this.controller.view.submit_button.disabled = false;
315 this.controller.view.password_prompt.disabled = false;
316 this.controller.view.password_prompt.value = '';
317 this.controller.view.name_prompt.disabled = false;
318 this.controller.view.name_prompt.focus();
319 this.controller.view.name_prompt.select();
320 this.controller.view.server_prompt.disabled = false;
322 var windowManager = Components.classes["@mozilla.org/appshell/window-mediator;1"].getService();
323 var windowManagerInterface = windowManager.QueryInterface(Components.interfaces.nsIWindowMediator);
324 var enumerator = windowManagerInterface.getEnumerator(null);
326 var w; // close all other windows
327 while ( w = enumerator.getNext() ) {
328 if (w != window) w.close();
331 this.controller.render('ws_deck');
333 this.session.close();
335 /* FIXME - need some locking or object destruction for the async tests */
336 /* this.test_server( this.controller.view.server_prompt.value ); */
338 if (typeof this.on_logoff == 'function') {
339 this.error.sdump('D_AUTH','auth.controller.on_logoff()\n');
344 'close' : function() {
346 this.error.sdump('D_AUTH','close' + this.w + '\n');
348 //Basically, we want to close all the windows for this application (and in case we're running this as
349 //a firefox extension, we don't want to merely shutdown mozilla). I'll probably create an XPCOM for
350 //tracking the windows.
351 //for (var w in this.G.window.appshell_list) {
352 // this.G.window.appshell_list[w].close();
354 this.w.close(); /* Probably won't go any further */
356 if (typeof this.on_close == 'function') {
357 this.error.sdump('D_AUTH','auth.controller.on_close()\n');
364 dump('exiting auth/controller.js\n');