1 dump('entering auth/controller.js\n');
4 if (typeof auth == 'undefined') auth = {};
5 auth.controller = function (params) {
6 JSAN.use('util.error'); this.error = new util.error();
7 this.w = params.window;
12 auth.controller.prototype = {
14 'init' : function () {
16 var obj = this; // so the 'this' in event handlers don't confuse us
19 JSAN.use('OpenILS.data');
20 obj.data = new OpenILS.data(); obj.data.init({'via':'stash'});
23 JSAN.use('util.controller'); obj.controller = new util.controller();
39 'cmd_standalone_import' : [
42 obj.standalone_import();
45 'cmd_standalone_export' : [
48 obj.standalone_export();
54 obj.debug('clear_cache');
60 obj.debug('js_console');
75 'cmd_close_window' : [
84 obj.test_server( obj.controller.view.server_prompt.value );
101 function(e) { return function() {} }
105 function(e) { return function() {} }
109 function(e) { return function() {
114 function(e) { return function() {
116 JSAN.use('util.widgets'); util.widgets.remove_children(e);
117 var x = document.createElement('description');
120 && obj.data.ws_info[ obj.controller.view.server_prompt.value ]) {
121 var ws = obj.data.ws_info[ obj.controller.view.server_prompt.value ];
123 document.createTextNode(
124 ws.name /*+ ' @ ' + ws.lib_shortname*/
127 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
128 JSAN.use('util.file'); var file = new util.file('last_ws_server');
129 file.set_object(obj.controller.view.server_prompt.value);
133 document.createTextNode(
134 document.getElementById('authStrings').getString('staff.auth.controller.not_configured')
145 function(e) { return function() {
152 obj.controller.view.name_prompt.focus();
154 function handle_keypress(ev) {
156 if (ev.keyCode && ev.keyCode == 13) {
158 case obj.controller.view.server_prompt:
160 obj.controller.view.name_prompt.focus(); obj.controller.view.name_prompt.select();
162 case obj.controller.view.name_prompt:
164 obj.controller.view.password_prompt.focus(); obj.controller.view.password_prompt.select();
166 case obj.controller.view.password_prompt:
168 obj.controller.view.submit_button.focus();
179 obj.controller.view.server_prompt.addEventListener(
182 obj.test_server(ev.target.value);
183 obj.controller.render('ws_deck');
188 // This talks to our ILS
189 JSAN.use('auth.session');
190 obj.session = new auth.session(obj.controller.view);
192 obj.controller.render();
193 obj.test_server( obj.controller.view.server_prompt.value );
194 obj.controller.render('ws_deck');
196 if (typeof this.on_init == 'function') {
197 this.error.sdump('D_AUTH','auth.controller.on_init()\n');
202 'test_server' : function(url) {
205 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
206 JSAN.use('util.file'); var file = new util.file('last_ws_server');
207 if (file._file.exists()) {
208 url = file.get_object(); file.close();
209 obj.controller.view.server_prompt.value = url;
212 obj.controller.view.submit_button.disabled = true;
213 obj.controller.view.server_prompt.disabled = true;
214 var s = document.getElementById('status');
215 s.setAttribute('value', document.getElementById('authStrings').getString('staff.auth.controller.testing_hostname'));
216 s.setAttribute('style','color: orange;');
217 document.getElementById('version').value = '';
219 s.setAttribute('value', document.getElementById('authStrings').getString('staff.auth.controller.prompt_hostname'));
220 s.setAttribute('style','color: red;');
221 obj.controller.view.server_prompt.disabled = false;
222 obj.controller.view.server_prompt.focus();
226 if ( ! url.match(/^http:\/\//) ) url = 'http://' + url;
227 var x = new XMLHttpRequest();
228 dump('server url = ' + url + '\n');
229 x.open("GET",url,true);
230 x.onreadystatechange = function() {
232 if (x.readyState != 4) return;
233 s.setAttribute('value', document.getElementById('authStrings').getFormattedString('staff.auth.controller.status', [x.status, x.statusText]));
234 if (x.status == 200) {
235 s.setAttribute('style','color: green;');
237 s.setAttribute('style','color: red;');
239 obj.test_version(url);
241 obj.controller.view.server_prompt.disabled = false;
242 obj.controller.view.server_prompt.focus();
243 s.setAttribute('value', document.getElementById('authStrings').getString('staff.auth.controller.error_hostname'));
244 s.setAttribute('style','color: red;');
245 obj.error.sdump('D_ERROR',E);
250 s.setAttribute('value', document.getElementById('authStrings').getString('staff.auth.controller.error_hostname'));
251 s.setAttribute('style','color: brown;');
252 obj.error.sdump('D_ERROR',E);
253 obj.controller.view.server_prompt.disabled = false;
254 obj.controller.view.server_prompt.focus();
258 'test_version' : function(url) {
260 var s = document.getElementById('version');
261 s.setAttribute('value', document.getElementById('authStrings').getString('staff.auth.controller.testing_version'));
262 s.setAttribute('style','color: orange;');
264 var x = new XMLHttpRequest();
265 var url2 = url + '/xul/server/';
266 dump('version url = ' + url2 + '\n');
267 x.open("GET",url2,true);
268 x.onreadystatechange = function() {
270 if (x.readyState != 4) return;
271 s.setAttribute('value', document.getElementById('authStrings').getFormattedString('staff.auth.controller.status', [x.status, x.statusText]));
272 if (x.status == 200) {
273 s.setAttribute('style','color: green;');
274 obj.controller.view.submit_button.disabled = false;
276 s.setAttribute('style','color: red;');
277 obj.test_upgrade_instructions(url);
279 obj.controller.view.server_prompt.disabled = false;
281 s.setAttribute('value', document.getElementById('authStrings').getString('staff.auth.controller.error_version'));
282 s.setAttribute('style','color: red;');
283 obj.error.sdump('D_ERROR',E);
284 obj.controller.view.server_prompt.disabled = false;
289 s.setAttribute('value', document.getElementById('authStrings').getString('staff.auth.controller.error_version'));
290 s.setAttribute('style','color: brown;');
291 obj.error.sdump('D_ERROR',E);
292 obj.controller.view.server_prompt.disabled = false;
296 'test_upgrade_instructions' : function(url) {
299 var x = new XMLHttpRequest();
300 var url2 = url + '/xul/versions.html';
301 dump('upgrade url = ' + url2 + '\n');
302 x.open("GET",url2,true);
303 x.onreadystatechange = function() {
305 if (x.readyState != 4) return;
306 if (x.status == 200) {
307 window.open('data:text/html,'+window.escape(x.responseText),'upgrade','chrome,resizable,modal,centered');
309 alert(document.getElementById('authStrings').getString('staff.auth.controller.version_mismatch'));
311 obj.controller.view.server_prompt.disabled = false;
313 obj.error.sdump('D_ERROR',E);
314 obj.controller.view.server_prompt.disabled = false;
319 obj.error.sdump('D_ERROR',E);
320 obj.controller.view.server_prompt.disabled = false;
324 'login' : function() {
328 this.error.sdump('D_AUTH',
329 document.getElementById('authStrings').getFormattedString(
330 'staff.auth.controller.error_login', [
331 this.controller.view.name_prompt.value,
332 this.controller.view.password_prompt.value,
333 this.controller.view.server_prompt.value
337 this.controller.view.server_prompt.disabled = true;
338 this.controller.view.name_prompt.disabled = true;
339 this.controller.view.password_prompt.disabled = true;
340 this.controller.view.submit_button.disabled = true;
341 XML_HTTP_SERVER = this.controller.view.server_prompt.value;
345 if (typeof this.on_login == 'function') {
346 this.error.sdump('D_AUTH','auth.controller.session.on_init = ' +
347 'auth.controller.on_login\n');
348 this.session.on_init = this.on_login;
349 this.session.on_error = function() { obj.logoff(); };
355 var error = '!! ' + E + '\n';
356 this.error.sdump('D_ERROR',error);
359 if (E == 'open-ils.auth.authenticate.init returned false\n') {
360 this.controller.view.server_prompt.focus();
361 this.controller.view.server_prompt.select();
364 if (typeof this.on_login_error == 'function') {
365 this.error.sdump('D_AUTH','auth.controller.on_login_error()\n');
366 this.on_login_error(E);
372 'standalone' : function() {
375 if (typeof this.on_standalone == 'function') {
379 var error = '!! ' + E + '\n';
380 obj.error.sdump('D_ERROR',error);
385 'standalone_import' : function() {
388 if (typeof this.on_standalone_import == 'function') {
389 obj.on_standalone_import();
392 var error = '!! ' + E + '\n';
393 obj.error.sdump('D_ERROR',error);
398 'standalone_export' : function() {
401 if (typeof this.on_standalone_export == 'function') {
402 obj.on_standalone_export();
405 var error = '!! ' + E + '\n';
406 obj.error.sdump('D_ERROR',error);
411 'debug' : function(action) {
414 if (typeof this.on_debug == 'function') {
415 obj.on_debug(action);
418 var error = '!! ' + E + '\n';
419 obj.error.sdump('D_ERROR',error);
424 'logoff' : function() {
426 this.error.sdump('D_AUTH','logoff' + this.w + '\n');
427 this.controller.view.progress_bar.value = 0;
428 this.controller.view.progress_bar.setAttribute('real','0.0');
429 this.controller.view.submit_button.disabled = false;
430 this.controller.view.password_prompt.disabled = false;
431 this.controller.view.password_prompt.value = '';
432 this.controller.view.name_prompt.disabled = false;
433 this.controller.view.name_prompt.focus();
434 this.controller.view.name_prompt.select();
435 this.controller.view.server_prompt.disabled = false;
437 var windowManager = Components.classes["@mozilla.org/appshell/window-mediator;1"].getService();
438 var windowManagerInterface = windowManager.QueryInterface(Components.interfaces.nsIWindowMediator);
439 var enumerator = windowManagerInterface.getEnumerator(null);
441 var w; // close all other windows
442 while ( w = enumerator.getNext() ) {
443 if (w != window) w.close();
446 this.controller.render('ws_deck');
448 this.session.close();
450 /* FIXME - need some locking or object destruction for the async tests */
451 /* this.test_server( this.controller.view.server_prompt.value ); */
453 if (typeof this.on_logoff == 'function') {
454 this.error.sdump('D_AUTH','auth.controller.on_logoff()\n');
459 'close' : function() {
461 this.error.sdump('D_AUTH','close' + this.w + '\n');
463 if (window.confirm(document.getElementById('authStrings').getString('staff.auth.controller.confirm_close'))) {
465 this.w.close(); /* Probably won't go any further */
467 if (typeof this.on_close == 'function') {
468 this.error.sdump('D_AUTH','auth.controller.on_close()\n');
476 dump('exiting auth/controller.js\n');