]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/javascript/opac/LoginDialog.js
removing old opac images and css
[working/Evergreen.git] / Open-ILS / src / javascript / opac / LoginDialog.js
1 var PopupBoxId = 0;
2
3
4 function LoginDialog(logged_in_callback) {
5         this.callback = logged_in_callback;
6         this.rand = PopupBoxId++;
7 }
8
9
10
11 /* node is the element the dialog should popup under */
12 LoginDialog.prototype.display = function(node) {
13
14         if(UserSession.instance().verifySession()) {
15                 if(this.callback) this.callback(UserSession.instance());
16                 return;
17         }
18
19         this.box = new PopupBox(node);
20         var box = this.box;
21         box.title("Login");
22
23         var ut = elem("input", {id:"login_uname_" + this.rand,type:"text",size:"16"});
24         var pw = elem("input",{id:"login_passwd_" + this.rand,type:"password",size:"16"});
25         ut.size = 16;
26         pw.size = 16;
27
28         var but = elem("input",
29                 {style:"margin-right: 10px", type:"submit",value:"Login"});
30         var cancel = elem("input",
31                 {style:"margin-left: 10px;",type:"submit",value:"Cancel"});
32
33
34         var obj = this;
35         var submitFunc = function() {
36                 var uname = getById("login_uname_" + obj.rand).value;
37                 var passwd = getById("login_passwd_" + obj.rand).value;
38
39                 if(uname == null || uname == "") {
40                         alert("Please enter username");
41                         return;
42                 }
43
44                 if(passwd == null || passwd == "") {
45                         alert("Please enter password");
46                         return;
47                 }
48
49                 var ses = UserSession.instance();
50                 if( ses.login(uname, passwd)) {
51                         /* now grab the org_unit associated with this user */
52                         ses.grabOrgUnit();
53                         ses.fleshMe(true); /* flesh the user */
54                         obj.hideMe();
55                         if(obj.callback) obj.callback(ses);
56                 } else {
57                         alert("Password is incorrect");
58                         try{pw.focus();}catch(e){}
59                 }
60         }
61
62         but.onclick = submitFunc;
63         ut.onkeyup = function(evt) { if(userPressedEnter(evt)) submitFunc(); }
64         pw.onkeyup = function(evt) { if(userPressedEnter(evt)) submitFunc(); }
65         cancel.onclick = function() { obj.hideMe(); }
66
67         box.addText("Username ");
68         box.addNode(ut);
69         box.lines();
70         box.addText("Passwod ");
71         box.addNode(pw);
72         box.lines();
73         box.makeGroup([but, cancel]);
74         
75         box.show();
76         try{ut.focus();}catch(E){}
77
78 }
79
80 function runLoginOnEnter(evt) {
81         var code = grabCharCode(evt); 
82         if(code==13||code==3) {  }
83 }
84
85
86 LoginDialog.prototype.hideMe = function() {
87         this.box.hide();
88 }
89
90