String.prototype.tr = function(){return this.replace(/(^\s*)|(\s*$)/g, "");}; var jsonrpc=null; var queryStr = ""; /*returns width of browser window*/ function getMW() { var w=window.innerWidth; if (w==null) w=document.body.clientWidth; return w; } /*returns height of browser window*/ function getMH() { var h=window.innerHeight; if (h==null) h=document.body.clientHeight; return h; } /*lCtrl object contains functions and states to process RPC login and switch to start.jsp page*/ var lCtrl = { debugMode: false, /*anonymous mode*/ modeA: false, initA: function(showRestoreDetails, qStr, sKey, usercid){ this.usercid = usercid; this.modeA = true; this.modeASkey = sKey; this.init(showRestoreDetails, qStr, false); }, /*initializates parameters and references to objects*/ init: function(showRestoreDetails, qStr, uPassEnc){ jsonrpc = new JSONRpcClient("jrpc2.jsp"); if (!jsonrpc.lCtrl){ //probably coockies are not enabled $("fooF").action="nocookie.jsp"; $("fooF").submit(); return; } this.uPassEnc = uPassEnc; queryStr = qStr; //shows details of restoring process this.showRestoreDetails = showRestoreDetails; //flag indicates if we have login step or pasword changing step this.logOrPass = true; //ids of "forms" used in interface this.frms= this.modeA ? ["infoTR", "restTR"] : ["chgPassTR", "loginTR", "restTR"]; //ids of dom object required in interface var domObjts=this.modeA ? ["restTR","restDIV","infoTR","progressTR","restTR","restDIV","anErr","fooF"] : ["serviceSel","user","pass","chgUser","newPass2","newPass","fooF", "progressTR","chgPassTR","loginTR","logBut","anErr","taskTxt","restTR","restDIV"]; var notFound = ""; //checking if all required objects exists on page and creates domObjts.each(function(o){ var oo = $(o); if (!oo){ notFound += "\"" + o + "\"; " allFound = false; } else { this[o] = oo; } }.bind(this)); if (notFound==""){ if (this.modeA){ this.openA(); } else { if (this.uPassEnc && this.getDObjVal("user").length > 0 && this.getDObjVal("pass").length > 0){ //if user and password exists then autologin this.login(); } else { this.visFrm("loginTR"); this.logBut.focus(); } //alert("PAGE OK"); } } else { alert(notFound + "missing on the page!"); } }, openA: function(){ if (this.modeA){ //this.modeASkey this.wait(true,"otwieranie serwisu..."); jsonrpc.lCtrl.doOpenA(this.ac_login.bind(this),this.usercid, this.modeASkey, getMW(), getMH(), queryStr); } }, //show only one of forms in interface visFrm: function(fName){ this.frms.each(function(f){ var o = $(f); if (o) Element.hide(o); }); var o = $(fName); if (o) Element.show(o); }, //starts login process login: function(passSave){ this.logOrPass = true; this.doLogin(false,this.getSerKey(),this.getDObjVal("user"), this.getDObjVal("pass"), this.uPassEnc, passSave); }, //returns trimed value of given object getDObjVal: function(o){ if (this[o]){ var v = this[o].value; v = v.tr(); this[o].value = v; return v; } else { alert("Object " + o + " not exists!"); } return ""; }, //starts changing password process chgPass: function(passSave){ this.logOrPass = false; //trimming ... var nPass = this.getDObjVal("newPass"); var nPass2 = this.getDObjVal("newPass2"); if (nPass.length > 0){ if (nPass2.length > 0){ if (nPass2==nPass){ this.doLogin(true, this.getSerKey(), this.chgUser.value, nPass, this.uPassEnc, passSave); } else { alert("hasła nie są pasują!"); } } else { alert("hasło powtórzone jest puste!"); } } else { alert("hasło jest puste!"); } }, //asynchronous call; loging or change password process doLogin: function(chgPass,sKey,user,pass,enc,passSave){ passSave = !!passSave; this.anErr.innerHTML = " "; if (sKey!=null){ if (user!=null && user.length >0){ if (pass!=null && pass.length >0){ if (chgPass){ this.wait(true,"zmiana hasła..."); jsonrpc.lCtrl.doLogin(this.ac_login.bind(this), true, sKey, user, pass, enc, passSave); } else { this.wait(true,"logowanie..."); jsonrpc.lCtrl.doLogin( this.ac_login.bind(this), false, sKey, user, pass, enc, passSave); } } else alert("hasło nie może być puste!"); } else alert("wprowadź nazwę użytkownika!"); } else { alert("wprowadź nazwę użytkownika!"); } }, //asynch login response function ac_login: function(ret,ex) { if(ex) { this.exHandler(ex); return; } this.wait(false,""); if (ret) this.doResp(ret); }, //asynch open response function ac_open: function(ret,ex) { if(ex) { this.exHandler(ex); return; } this.wait(false,""); if (ret){ $("fooF").submit(); } else { alert("Nieoczekiwany błąd!"); } }, //process login response, shows appropriate form and messages doResp: function(r){ //prompt("",toJSON(r)); this.anErr.innerHTML = r.error ? r.error : " "; if (r.restSerStatus!=null){ //restoring service var t = this.getRestoringTxt(r.restSerStatus); this.restDIV.innerHTML = t; this.visFrm("restTR"); window.setTimeout(function(){ if (this.modeA){ this.openA(); } else { if (this.logOrPass) { this.login(); } else { this.chgPass(); } } }.bind(this), 1000); } else { if (r.anonymous){ if (r.connected){ $("fooF").submit(); } else { window.setTimeout(function(){this.openA();}.bind(this), 2000); } } else { if (r.connected){ if (r.expireTime > -1 ){ var warnS = r.expireTime == 0 ? "Hasło właśnie wygasło! \nPrzy następnym logowaniu będziesz zmuszona(y) zmienić hasło. \nMożesz też zrobić to teraz.\nCzy chcesz zmienić teraz hasło ?" : ("Hasło wygaśnie za dni : " + r.expireTime + "!.\n Czy chcesz zmienić hasło już teraz ?"); if (confirm(warnS)){ this.chgUser.value = this.user.value; this.visFrm("chgPassTR"); } else { //go further this.wait(true,"otwieranie projektu \"" + this.getSerName() + "\""); jsonrpc.lCtrl.doOpen(this.ac_open.bind(this), this.getSerKey(), getMW(), getMH(), queryStr); } } else { //go further this.wait(true,"otwieranie projektu \"" + this.getSerName() + "\""); jsonrpc.lCtrl.doOpen(this.ac_open.bind(this), this.getSerKey(), getMW(), getMH(), queryStr); } } else { if (r.expired){ //paswor expired //"oldPass" "chgUser" "newPass" "errChgUserPass" lCtrl.chgPass(); this.chgUser.value = this.user.value; this.visFrm("chgPassTR"); } } } } }, wait: function(onOff,msg){ if (this.taskTxt) this.taskTxt.innerHTML = msg ? msg : " "; document.body.style.cursor= onOff ? "wait" : "default"; this.progressTR.style.visibility = onOff ? "visible" : "hidden"; }, getSerKey: function(){ return this.getSer(true);}, getSerName: function(){ return this.getSer(false);}, getSer: function(keyOrName){ if (this.serviceSel && this.serviceSel.selectedIndex >= 0){ var o = this.serviceSel.options[this.serviceSel.selectedIndex]; return keyOrName ? o.value : o.text; } return null; }, //returns restoring info tekst based on restoring object returned login process getRestoringTxt: function(s){ var rTxt = "

Uruchamienie serwisu ...



" + "

Postęp: poziom " + s.curStep + "z " + s.maxSteps + "

" + "

Liczba prób w danym poziomie :" + s.stepTryCnt + "

" + (this.showRestoreDetails ? "" : "") + "

Ta strona przekieruje Cię do serwisu gdy tylko będzie on dostępny !

" return rTxt; }, //default RPC errorhandler exHandler: function(ex) { if (ex){ if (ex.code == JSONRpcClient.Exception.CODE_ERR_NOMETHOD){ alert("Problem z połączeniem do serwisu!"); } else { if (this.debugMode){ alert("RPC error " + " \"" + this.exHandler.caller + "\" : \n" + " --name : " + ex.name + "\n" + " --code : " + ex.code + "\n" + " --message : " + ex.message + "\n" + " --javaStack : " + ex.javaStack ); } else { alert("Error: " + " \"" + this.exHandler.caller + "\" : \n" + " --name : " + ex.name + "\n" + " --code : " + ex.code + "\n"); } } } } };