]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/javascript/opac/LoginPage.js
c080033af95418b0afc68b6877e057542ceb6631
[working/Evergreen.git] / Open-ILS / src / javascript / opac / LoginPage.js
1 LoginPage.prototype                                     = new Page();
2 LoginPage.prototype.constructor = LoginPage;
3 LoginPage.baseClass                                     = Page.constructor;
4
5 // ---------------------------------------------------------------------------------
6 // login
7 // ---------------------------------------------------------------------------------
8
9 var globalLoginPage = null;
10
11 function LoginPage() {
12
13         if(globalLoginPage != null) { 
14                 globalLoginPage.init();
15                 return globalLoginPage; 
16         }
17
18         this.searchBarForm      = new SearchBarFormChunk();
19         this.searchBar                  = new SearchBarChunk();
20
21         globalLoginPage = this;
22 }
23
24 LoginPage.prototype.init = function() {
25         this.searchBar.reset();
26         this.login_button               = getById("login_button");
27
28         this.login_button.onclick = loginShuffle;
29
30         this.username           = getById("login_username");
31         this.password           = getById("login_password");
32         this.result_field = getById("login_result_text");
33
34         this.session = UserSession.instance();
35         this.draw();
36
37 }
38
39
40 LoginPage.prototype.draw = function() {
41         try {this.username.focus();} catch(E) {}
42
43
44         if(IE) {
45
46                 this.username.onkeyup = "window.event.cancelBubble = true"; 
47
48                 this.password.onkeyup = 
49                         function() {
50                                 getAppWindow().event.cancelBubble = true; 
51                                 loginOnEnter; return true; 
52                         };
53
54         } else {
55                 this.username.onkeyup = function(){};
56                 this.password.onkeyup = loginOnEnter;
57         }
58         
59         this.login_success_msg = null;
60         this.login_failure_msg = null;
61 }
62
63
64 function loginShuffle() {
65         var obj = globalLoginPage;
66         var ses = UserSession.instance();
67         if( ses.login( obj.username.value, obj.password.value )) {
68                 /* now grab the org_unit associated with this user */
69                 ses.grabOrgUnit();
70                 url_redirect( [ "target", "my_opac" ] ); /* redirect to the my opac page */
71                 /*
72                 obj.result_field.innerHTML = obj.login_success_msg;
73                 obj.searchBar.reset();
74                 */
75         } else {
76                 obj.result_field.innerHTML = obj.login_failure_msg;
77         }
78 }
79
80 function loginOnEnter(evt) {
81         var code = grabCharCode(evt); 
82         if(code==13||code==3) { loginShuffle(); }
83 }
84
85
86