lemonldap-ng/lemonldap-ng-portal/site/htdocs/static/common/js/portal.min.js
2020-05-06 15:31:10 +02:00

1 line
6.9 KiB
JavaScript

(function(){var D,e,I,_,M,N,R,U,t,A,p,i,J,s,z=[].indexOf||function(t){for(var e=0,n=this.length;e<n;e++)if(e in this&&this[e]===t)return e;return-1};s={},J=function(r){return $.getJSON(window.staticPrefix+"languages/"+r+".json",function(t){var e,n,a,o;for(e in s=t,n=window.datas.trOver.all)o=n[e],s[e]=o;if(window.datas.trOver[r])for(e in a=window.datas.trOver[r])o=a[e],s[e]=o;return $("[trspan]").each(function(){var t,e,n,a;for(t=$(this).attr("trspan").split(","),a=i(t.shift()),e=0,n=t.length;e<n;e++)o=t[e],a=a.replace(/%[sd]/,o);return $(this).html(a)}),$("[trmsg]").each(function(){if($(this).html(i("PE"+$(this).attr("trmsg"))),i("PE"+$(this).attr("trmsg")).match(/_hide_/))return $(this).parent().hide()}),$("[trplaceholder]").each(function(){return $(this).attr("placeholder",i($(this).attr("trplaceholder")))}),$("[localtime]").each(function(){var t;return t=new Date(1e3*$(this).attr("localtime")),$(this).text(t.toLocaleString())})})},i=function(t){return s[t]?s[t]:t},window.translate=i,_=function(){var a;return a={},$("script[type='application/init']").each(function(){var t,e,n;try{for(t in n=JSON.parse($(this).text()),e=[],n)e.push(a[t]=n[t]);return e}catch(t){return console.log("Parsing error",t),console.log("JSON",$(this).text())}}),console.log(a),a},p="#appslist",A=function(){return t("_appsListOrder",$(p).sortable("toArray").join())},N=function(t){return e("_oidcConsents",t,function(){return $("[partner='"+t+"']").hide()},function(t,e,n){return alert(e+" "+n)})},t=function(n,a,o,r){return $.ajax({type:"GET",url:D.scriptname+"/mysession/?gettoken",dataType:"json",error:r,success:function(t){var e;return(e={token:t.token})[n]=a,$.ajax({type:"PUT",url:D.scriptname+"/mysession/persistent",dataType:"json",data:e,success:o,error:r})}})},e=function(e,n,a,o){return $.ajax({type:"GET",url:D.scriptname+"/mysession/?gettoken",dataType:"json",error:o,success:function(t){return $.ajax({type:"DELETE",url:D.scriptname+"/mysession/persistent/"+e+"?sub="+n+"&token="+t.token,dataType:"json",success:a,error:o})}})},R=function(){var t,e,n,a,o,r,i,s,l,c,u,g,d;if(null==(c=$(p))||!D.appslistorder)return null;for(t=D.appslistorder.split(","),u=[],n=0,s=(r=c.sortable("toArray")).length;n<s;n++)u[d=r[n]]=d;for(i=0,l=t.length;i<l;i++)u[o=t[i]]&&(a=u[o],e=$(p+".ui-sortable").children("#"+a),g=$(p+".ui-sortable").children("#"+o),e.remove(),$(p+".ui-sortable").filter(":first").append(g));return 1},M=function(){return $.ajax({type:"POST",url:D.scriptname,data:{ping:1},dataType:"json",success:function(t){return null!=t.result&&1===t.result?setTimeout(M,D.pingInterval):location.reload(!0)},error:function(t,e,n){return location.reload(!0)}})},window.ping=M,I=function(t){var e,n,a,o,r;for(n=decodeURIComponent(document.cookie).split(";"),r=new RegExp("^ *"+t+"="),a=0,o=n.length;a<o;a++)if((e=n[a]).match(r))return e=e.replace(r,"");return""},U=function(t,e,n){var a;return(a=new Date).setTime(a.getTime()+864e5*n),document.cookie=t+"="+e+"; expires="+a.toUTCString()+"; path=/"},D={},$(window).on("load",function(){var t,e,n,a,o,r,i,s,l,c,u,g,d,p,h,f,w,m,v,b,y,x,L,k,T,O,S,j,P,C,E,G;if(D=_(),"datas"in window&&"choicetab"in window.datas&&(D.choicetab=window.datas.choicetab),window.datas=D,$("#appslist").sortable({axis:"y",cursor:"move",opacity:.5,revert:!0,items:"> div.category",update:function(){return A()}}),R(),$("div.message").fadeIn("slow"),$("input[name=timezone]").val(-(new Date).getTimezoneOffset()/60),b=$("#menu").tabs({active:0}),(v=$('#menu a[href="#'+D.displaytab+'"]').parent().index())<0&&(v=0),b.tabs("option","active",v),a=$("#authMenu").tabs({active:0}),(n=$('#authMenu a[href="#'+D.displaytab+'"]').parent().index())<0&&(n=0),a.tabs("option","active",n),D.choicetab&&a.tabs("option","active",$('#authMenu a[href="#'+D.choicetab+'"]').parent().index()),D.login?$("input[type=password]:first").focus():0===$("input[autofocus]").length&&$("input[type!=hidden]:first").focus(),D.newwindow&&$("#appslist a").attr("target","_blank"),$("p.removeOther").length&&(t=$("#form").attr("action"),y=$("#form").attr("method"),console.log("method=",y),r="",$("#form input[type=hidden]")&&(console.log("Parse hidden values"),$("#form input[type=hidden]").each(function(t){return console.log(" ->",$(this).attr("name"),$(this).val()),r+="&"+$(this).attr("name")+"="+$(this).val()})),o="",t&&(console.log("action=",t),-1!==t.indexOf("?")?t.substring(0,t.indexOf("?")):o=t+"?",o+=r,r=""),w=$("p.removeOther a").attr("href")+"&method="+y+r,o&&(w+="&url="+btoa(o)),$("p.removeOther a").attr("href",w)),(O=window.location.search)&&(console.log("Parsed queryString:",O),G=new URLSearchParams(O)),G&&((T=G.get("llnglanguage"))&&console.log("Get lang from parameter"),1===(E=G.get("setCookieLang"))&&console.log("Set lang cookie")),l||(l=I("llnglanguage"))&&!T&&console.log("Get lang from cookie"),l)z.call(window.availableLanguages,l)<0&&(l=window.availableLanguages[0],T||console.log("Lang not available -> Get default lang"));else if(navigator){for(u=[],g=[],k=[navigator.language],navigator.languages&&(k=navigator.languages),i=0,d=(j=window.availableLanguages).length;i<d;i++)e=j[i],c+='<img class="langicon" src="'+window.staticPrefix+"common/"+e+'.png" title="'+e+'" alt="['+e+']"> ';for(s=0,p=k.length;s<p;s++)for(L=k[s],console.log("Navigator lang",L),m=0,h=(P=window.availableLanguages).length;m<h;m++)e=P[m],console.log(" Available lang",e),S=new RegExp("^"+e+"-?"),L.match(S)?(console.log(" Matching lang =",e),u.push(e)):e.substring(0,1)===L.substring(0,1)&&g.push(e);(l=u[0]?u[0]:g[0]?g[0]:window.availableLanguages[0])&&!T&&console.log("Get lang from navigator")}else(l=window.availableLanguages[0])&&!T&&console.log("Get lang from window");for(T?(z.call(window.availableLanguages,T)<0&&(console.log("Lang not available -> Get default lang"),T=window.availableLanguages[0]),console.log("Selected lang ->",T),E&&(console.log("Set cookie lang ->",T),U("llnglanguage",T)),J(T)):(console.log("Selected lang ->",l),U("llnglanguage",l),J(l)),c="",x=0,f=(C=window.availableLanguages).length;x<f;x++)e=C[x],c+='<img class="langicon" src="'+window.staticPrefix+"common/"+e+'.png" title="'+e+'" alt="['+e+']"> ';return $("#languages").html(c),$(".langicon").on("click",function(){return l=$(this).attr("title"),U("llnglanguage",l),J(l)}),D.pingInterval&&0<D.pingInterval&&window.setTimeout(M,D.pingInterval),$(".localeDate").each(function(){var t;return t=new Date(1e3*$(this).attr("val")),$(this).text(t.toLocaleString())}),$(".oidcConsent").on("click",function(){return N($(this).attr("partner"))}),$("#show-hide-button").on("click",function(){return"password"===$("#newpassword").attr("type")?(console.log("Show passwords"),$("#newpassword").attr("type","input"),$("#confirmpassword").attr("type","input"),$("#show-hide-icon-button").removeClass("fa-eye"),$("#show-hide-icon-button").addClass("fa-eye-slash")):(console.log("Hide passwords"),$("#newpassword").attr("type","password"),$("#confirmpassword").attr("type","password"),$("#show-hide-icon-button").removeClass("fa-eye-slash"),$("#show-hide-icon-button").addClass("fa-eye"))})})}).call(this);