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, hasAnkieta: false, initA: function(showRestoreDetails, qStr, sKey, usercid, ankieta){ this.usercid = usercid; this.modeA = true; this.modeASkey = sKey; this.ankieta = ankieta; this.hasAnkieta = !!ankieta; this.init(showRestoreDetails, qStr, false); }, /*initializates parameters and references to objects*/ init: function(showRestoreDetails, qStr, uPassEnc, getSerStat){ jsonrpc = new JSONRpcClient("jrpc2.jsp"); this.getSerStat = getSerStat; 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 this.domObjts=this.modeA ? (this.hasAnkieta ? ["serviceSel","restTR","restDIV","infoTR","progressTR","restTR","restDIV","anErr","fooF"] : ["restTR","restDIV","infoTR","progressTR","restTR","restDIV","anErr","fooF"]): ["serviceSel","user","pass","chgUser","newPass2","newPass","fooF", "progressTR","chgPassTR","loginTR","logBut","anErr","taskTxt","restTR","restDIV"]; //checking if all required objects exists on page and creates this.step2Cnt = 0; this.initStep2(); }, initStep2: function(){ this.step2Cnt++; var notFound = ""; this.domObjts.each(function(o){ var oo = $(o); if (!oo){ notFound += "\"" + o + "\"; " } else { this[o] = oo; } }.bind(this)); if (notFound==""){ //page ok go further this.initStep3(); } else { if (this.step2Cnt > 3){ alert(notFound + " missing on the page!"); } else { //alert("remove me message " + notFound + " missing on the page!"); window.setTimeout(this.initStep2.bind(this),2000); } } }, initStep3: function(){ //alert("PAGE OK"); if (this.modeA ){ if (!this.hasAnkieta){ this.openA(); } } else { this.logBut.disabled=false; 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(); this.pingInit(); } } }, openA: function(){ if (this.modeA){ //this.modeASkey this.wait(true,"otwieranie serwisu..."); if (this.hasAnkieta){ jsonrpc.lCtrl.doOpenA(this.ac_login.bind(this),this.usercid, this.modeASkey, getMW(), getMH(), queryStr, this.ankieta); } else { jsonrpc.lCtrl.doOpenA(this.ac_login.bind(this),this.usercid, this.modeASkey, getMW(), getMH(), queryStr); } } }, pingInit: function(){ this.cyclePing = new PeriodicalExecuter(this.ping.bind(this),(this.getSerStat ? 8 : 60)); //setInterval(this.ping.bind(this),50); }, ping: function(){ if (this.getSerStat){ jsonrpc.lCtrl.lCping2(this.ac_ping.bind(this)); } else { jsonrpc.lCtrl.lCping(this.ac_ping.bind(this)); } }, ac_ping: function(ret,ex){ if(!ex) { //this.cyclePing.stop(); // this.pingInit(); //} else { if (this.getSerStat && ret && ret.list){ ret.list.each(function(si){ if ($("imPrg_" + si.key)){ var im = $("imPrg_" + si.key); var imgsrc = "g/proj_not_parsed.gif"; var tit = ""; var state = si.state; var pInfo = si.projInfo; var pPrg = si.prg; var lTime = si.lastTime; if (state == 3){ imgsrc = "g/proj_ready.gif"; tit = "Serwis gotowy, " + pInfo + " (" + lTime + "s)"; } else if (state == 2) { imgsrc = "g/wait-parsing.gif"; tit = "Serwis w trakcie uruchamiania ... \n " + pInfo + "\n " + pPrg + "% (" + lTime + "s)"; } else if ( state == 4){ imgsrc = "g/wait-error.gif"; tit = "Serwis odtwarzany po błędzie ... \n " + pInfo + "\n " + pPrg + "% (" + lTime + "s)"; } else if (state == 1){ imgsrc = "g/proj_not_parsed.gif"; tit = "Serwis oczekuje na uruchomienie"; } else { tit = "Nieznany stan serwisu"; } im.src = imgsrc; im.title = tit; } }); } } }, //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, queryStr); } else { this.wait(true,"logowanie..."); jsonrpc.lCtrl.doLogin( this.ac_login.bind(this), false, sKey, user, pass, enc, passSave, queryStr); } } else alert("hasło nie może być puste!"); } else alert("wprowadź nazwę użytkownika!"); } else { alert("projekt nie został wybrany!"); } }, //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() + "\""); if (this.hasAnkieta){ jsonrpc.lCtrl.doOpen(this.ac_open.bind(this), this.getSerKey(), getMW(), getMH(), queryStr, this.ankieta); } else { 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.tagName == 'SELECT') { if (this.serviceSel && this.serviceSel.selectedIndex >= 0){ var o = this.serviceSel.options[this.serviceSel.selectedIndex]; return keyOrName ? o.value : o.text; } } else { if (this.serviceSel.tagName == 'UL'){ var group = document.getElementsByName("serviceSelName"); for (var i=0; i < group.length; i++) { if (group[i].checked) { var oKey = group[i]; var oName = document.getElementById("sp-"+oKey.value+""); return keyOrName ? oKey.value : oName.innerHTML; } } } } 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"); } } } } };