]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/xul/staff_client/chrome/content/evergreen/auth/controller.js
Don't feed big G to the objects hanging off of G if we don't have to. But can I...
[Evergreen.git] / Open-ILS / xul / staff_client / chrome / content / evergreen / auth / controller.js
1 dump('entering auth/controller.js\n');
2
3 if (typeof auth == 'undefined') auth = {};
4 auth.controller = function (w) {
5         JSAN.use('util.error'); this.error = new util.error();
6         this.w = w;
7
8         return this;
9 };
10
11 auth.controller.prototype = {
12
13         'init' : function () {
14
15                 var obj = this;  // so the 'this' in event handlers don't confuse us
16                 var w = obj.w;
17
18                 // This talks to our ILS
19                 JSAN.use('auth.session');
20                 obj.session = new auth.session(obj);
21
22                 // Attach this object to the XUL through event listeners
23
24                 var cmd_login = w.document.getElementById('cmd_login');
25                         if (cmd_login) 
26                                 cmd_login.addEventListener('command',function () { obj.login(); },false);
27
28                 var cmd_logoff = w.document.getElementById('cmd_logoff');
29                         if (cmd_logoff) 
30                                 cmd_logoff.addEventListener('command',function () { obj.logoff(); },false);
31
32                 var cmd_close_window = w.document.getElementById('cmd_close_window');
33                         if (cmd_close_window) 
34                                 cmd_close_window.addEventListener('command',function () { obj.close(); },false);
35
36                 obj.view.name_prompt = w.document.getElementById('name_prompt');
37                         if (obj.view.name_prompt) {
38                                 obj.view.name_prompt.addEventListener('keypress',handle_keypress,false);
39                                 obj.view.name_prompt.focus();
40                         }
41
42                 obj.view.password_prompt = w.document.getElementById('password_prompt');
43                         if (obj.view.password_prompt)
44                                 obj.view.password_prompt.addEventListener('keypress',handle_keypress,false);
45         
46                 obj.view.submit_button = w.document.getElementById('submit_button');
47         
48                 obj.view.progress_bar = w.document.getElementById('auth_meter');
49
50                 function handle_keypress(ev) {
51                         if (ev.keyCode && ev.keyCode == 13) {
52                                 switch(this) {
53                                         case obj.name_prompt:
54                                                 ev.preventDefault();
55                                                 obj.view.password_prompt.focus(); obj.view.password_prompt.select();
56                                         break;
57                                         case obj.view.password_prompt:
58                                                 ev.preventDefault();
59                                                 obj.view.submit_button.focus(); 
60                                                 obj.login();
61                                         break;
62                                         default: break;
63                                 }
64                         }
65                 }
66
67                 if (typeof this.on_init == 'function') {
68                         this.error.sdump('D_AUTH','auth.controller.on_init()\n');
69                         this.on_init();
70                 }
71         },
72
73         'view' : {},
74
75         'login' : function() { 
76
77                 this.error.sdump('D_AUTH','login with ' + this.view.name_prompt.value + ' and ' + this.view.password_prompt.value + '\n'); 
78                 this.view.name_prompt.disabled = true;
79                 this.view.password_prompt.disabled = true;
80                 this.view.submit_button.disabled = true;
81
82                 try {
83
84                         if (typeof this.on_login == 'function') {
85                                 this.error.sdump('D_AUTH','auth.controller.session.on_init = ' +
86                                         'auth.controller.on_login\n');
87                                 this.session.on_init = this.on_login;
88                         }
89                         
90                         this.session.init();
91
92                 } catch(E) {
93                         var error = '!! ' + E + '\n';
94                         this.error.sdump('D_ERROR',error); 
95                         alert(error);
96                         this.logoff();
97
98                         if (typeof this.on_login_error == 'function') {
99                                 this.error.sdump('D_AUTH','auth.controller.on_login_error()\n');
100                                 this.on_login_error(E);
101                         }
102                 }
103
104         },
105         'logoff' : function() { 
106         
107                 this.error.sdump('D_AUTH','logoff' + this.w + '\n'); 
108                 this.view.progress_bar.value = 0; this.view.progress_bar.setAttribute('real','0.0');
109                 this.view.submit_button.disabled = false;
110                 this.view.password_prompt.disabled = false;
111                 this.view.password_prompt.value = '';
112                 this.view.name_prompt.disabled = false;
113                 this.view.name_prompt.focus(); this.view.name_prompt.select();
114
115                 this.session.close();
116
117                 if (typeof this.on_logoff == 'function') {
118                         this.error.sdump('D_AUTH','auth.controller.on_logoff()\n');
119                         this.on_logoff();
120                 }
121                 
122         },
123         'close' : function() { 
124         
125                 this.error.sdump('D_AUTH','close' + this.w + '\n');
126                 this.logoff();
127                 for (var w in this.G.window.appshell_list) {
128                         this.G.window.appshell_list[w].close();
129                 }
130                 this.w.close(); /* Probably won't go any further */
131
132                 if (typeof this.on_close == 'function') {
133                         this.error.sdump('D_AUTH','auth.controller.on_close()\n');
134                         this.on_close();
135                 }
136                 
137         }
138 }
139
140 dump('exiting auth/controller.js\n');