From: erickson Date: Wed, 6 Jul 2005 13:49:26 +0000 (+0000) Subject: popup box for logging in X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=2674050b1c045d25b4893ed924696bcc06ac776b;p=Evergreen.git popup box for logging in git-svn-id: svn://svn.open-ils.org/ILS/trunk@1071 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- diff --git a/Open-ILS/src/javascript/opac/LoginDialog.js b/Open-ILS/src/javascript/opac/LoginDialog.js new file mode 100644 index 0000000000..5e01be4be0 --- /dev/null +++ b/Open-ILS/src/javascript/opac/LoginDialog.js @@ -0,0 +1,98 @@ +/* node is where we attache the div */ +function LoginDialog(node, logged_in_callback) { + this.node = node; + this.callback = logged_in_callback; + this.connected = false; +} + +/* node is the element the dialog should popup under */ +LoginDialog.prototype.display = function(node) { + + if(UserSession.instance().verifySession()) { + if(this.callback) this.callback(UserSession.instance()); + return; + } + + this.div = elem("div",{id:"login_dialog"}); + var div = this.div; + if(IE) div.style.width = "200px"; /* just has to be done */ + + add_css_class(div,"login_dialog"); + var ut = elem("input", {id:"login_uname",type:"text",size:"16"}); + var pw = elem("input",{id:"login_passwd",type:"password",size:"16"}); + + var but = elem("input", + {style:"margin-right: 10px", type:"submit",value:"Login"}); + var cancel = elem("input", + {style:"margin-left: 10px;",type:"submit",value:"Cancel"}); + + + var obj = this; + var submitFunc = function() { + var uname = getById("login_uname").value; + var passwd = getById("login_passwd").value; + + if(uname == null || uname == "") { + alert("Please enter username"); + return; + } + + if(passwd == null || passwd == "") { + alert("Please enter password"); + return; + } + + var ses = UserSession.instance(); + if( ses.login(uname, passwd)) { + /* now grab the org_unit associated with this user */ + ses.grabOrgUnit(); + ses.fleshMe(true); /* flesh the user */ + obj.hideMe(); + if(obj.callback) obj.callback(ses); + } else { + alert("Password is incorrect"); + try{pw.focus();}catch(e){} + } + } + but.onclick = submitFunc; + ut.onkeyup = function(evt) { if(userPressedEnter(evt)) submitFunc(); } + pw.onkeyup = function(evt) { if(userPressedEnter(evt)) submitFunc(); } + cancel.onclick = function() { obj.hideMe(); } + + var A = getXYOffsets(node); + div.style.left = A[0]; + div.style.top = A[1]; + + div.appendChild(elem("br")); + div.appendChild(mktext("Username ")); + div.appendChild(ut); + div.appendChild(elem("br")); + div.appendChild(elem("br")); + div.appendChild(mktext("Password ")); + div.appendChild(pw); + div.appendChild(elem("br")); + div.appendChild(elem("br")); + + var bdiv = elem("div"); + add_css_class(bdiv, "holds_window_buttons"); + bdiv.appendChild(but); + bdiv.appendChild(cancel); + div.appendChild(bdiv); + + + div.appendChild(elem("br")); + this.node.appendChild(this.div); + + try{ut.focus();}catch(E){} +} + +function runLoginOnEnter(evt) { + var code = grabCharCode(evt); + if(code==13||code==3) { } +} + + + +LoginDialog.prototype.hideMe = function() { + this.node.removeChild(this.div); +}