Adapt appsListOrder from 1.9 (#595)

This commit is contained in:
Xavier Guimard 2017-03-19 07:00:10 +00:00
parent a6c2d72065
commit 97fa806052
4 changed files with 37 additions and 8 deletions

View File

@ -30,8 +30,12 @@
# where <type> is the session type ("global" for SSO session)
#
# - Authorizations for connected users (always):
# * GET /mysession/?whoami : get "my" uid
# * GET /mysession/?authorizationfor=<base64-encoded-url>: ask if url is
# authorizated
# * PUT /mysession/<type> : update some
# persistent datas
# (restricted)
#
# There is no conflict with SOAP server, they can be used together
@ -143,6 +147,10 @@ sub init {
mysession => { '*' => 'mysession' },
[ 'GET', 'POST' ]
);
$self->addAuthRoute(
mysession => { ':sessionType' => 'updateMySession' },
['PUT']
);
extends @parents if ($add);
$self->setTypes( $self->conf ) if ( $self->conf->{restSessionServer} );
return 1;
@ -299,7 +307,8 @@ sub mysession {
# Split URL
my ( $host, $uri ) = ( $req->urldc =~ m#^https?://([^/]+)(/.*)?$# );
$uri ||= '/';
return $self->p->sendError( $req, "Bad URL $req->{urldc}", 400 ) unless ($host);
return $self->p->sendError( $req, "Bad URL $req->{urldc}", 400 )
unless ($host);
$self->logger->debug("Looking for authorization for $url");
@ -323,4 +332,24 @@ sub getMyKey {
);
}
sub updateMySession {
my ( $self, $req ) = @_;
my $res = 0;
my $mKeys = [];
if ( $req->param('sessionType') eq 'persistent' ) {
foreach my $key (qw(_appsListOrder)) {
if ( my $v = $req->param($key) ) {
$res++;
push @$mKeys, $key;
$self->p->updatePersistentSession( $req, { $key => $v } );
}
}
}
unless ($res) {
return $self->p->sendError( $req, 'Modification refused', 403 );
}
return $self->p->sendJSONresponse( $req,
{ result => 1, count => $res, modifiedKeys => $mKeys } );
}
1;

View File

@ -50,10 +50,10 @@ setSelector = "#appslist"
# function that writes the list order to session
getOrder = ->
$.ajax
type: "POST"
url: datas['scriptname']
type: "PUT"
url: datas['scriptname'] + '/mysession/persistent'
data:
storeAppsListOrder: $(setSelector).sortable("toArray").join()
_appsListOrder: $(setSelector).sortable("toArray").join()
dataType: 'json'
# function that restores the list order from session

View File

@ -72,10 +72,10 @@ LemonLDAP::NG Portal jQuery scripts
getOrder = function() {
return $.ajax({
type: "POST",
url: datas['scriptname'],
type: "PUT",
url: datas['scriptname'] + '/mysession/persistent',
data: {
storeAppsListOrder: $(setSelector).sortable("toArray").join()
_appsListOrder: $(setSelector).sortable("toArray").join()
},
dataType: 'json'
});

View File

@ -1 +1 @@
(function(){var e,g,j,d,a,k,i,m,f,b,l,c,h=[].indexOf||function(p){for(var o=0,n=this.length;o<n;o++){if(o in this&&this[o]===p){return o}}return -1};c={};l=function(n){return $.getJSON(window.staticPrefix+"languages/"+n+".json",function(o){c=o;$("[trspan]").each(function(){var s,t,q,p,r;s=$(this).attr("trspan").split(",");p=b(s.shift());for(t=0,q=s.length;t<q;t++){r=s[t];p.replace(/%[ds]/,r)}return $(this).text(p)});$("[trmsg]").each(function(){return $(this).text(b("PE"+($(this).attr("trmsg"))))});$("[trplaceholder]").each(function(){return $(this).attr("placeholder",b($(this).attr("trplaceholder")))});return $("[localtime]").each(function(){var p;p=new Date($(this).attr("localtime")*1000);return $(this).text(p.toLocaleString())})})};b=function(n){if(c[n]){return c[n]}else{return n}};window.translate=b;d=function(){var n;n={};$("script[type='application/init']").each(function(){var s,p,o,r,q;try{q=JSON.parse($(this).text());r=[];for(o in q){r.push(n[o]=q[o])}return r}catch(p){s=p;console.log("Parsing error",s);return console.log("JSON",$(this).text())}});return n};f="#appslist";j=function(){return $.ajax({type:"POST",url:e.scriptname,data:{storeAppsListOrder:$(f).sortable("toArray").join()},dataType:"json"})};i=function(){var p,o,s,A,n,x,q,t,r,w,y,u,z;w=$(f);if(!((w!=null)&&e.appslistorder)){return null}p=e.appslistorder.split(",");x=w.sortable("toArray");y=[];for(s=0,t=x.length;s<t;s++){z=x[s];y[z]=z}for(q=0,r=p.length;q<r;q++){n=p[q];if(h.call(y,n)>=0){A=y[n];o=$(f+".ui-sortable").children("#"+A);u=$(f+".ui-sortable").children("#"+n);o.remove();$(f+".ui-sortable").filter(":first").append(u)}}return 1};a=function(n){return $("#lmhidden_"+n).length};k=function(){return $.ajax({type:"POST",url:e.scriptname,data:{ping:1},dataType:"json",success:function(n){if((n.result!=null)&&n.result===1){return setTimeout(k,e.pingInterval)}else{return location.reload(true)}},error:function(n,o,p){return location.reload(true)}})};window.ping=k;g=function(q){var t,o,r,n,p,s;p=q+"=";o=decodeURIComponent(document.cookie).split(";");s=new RegExp("^ *"+q+"=");for(r=0,n=o.length;r<n;r++){t=o[r];if(t.match(s)){t=t.replace(s,"");return t}}return""};m=function(n,p,o){var q;q=new Date();q.setTime(q.getTime()+o*86400000);return document.cookie=n+"="+p+"; expires="+(q.toUTCString())+"; path=/"};e={};$(document).ready(function(){var E,D,F,C,G,B,I,y,x,w,H,u,t,s,z,A,q,p,o,n,r,v;e=d();window.datas=e;if(e.antiframe&&top!==self){top.location.href=location.href}$("#appslist").sortable({axis:"y",cursor:"move",opacity:0.5,revert:true,items:"> div.category",update:function(){return j()}});i();$("div.message").fadeIn("slow");$("input[name=timezone]").val(-(new Date().getTimezoneOffset()/60));q=$("#menu").tabs({active:0});A=$('#menu a[href="#'+e.displaytab+'"]').parent().index();if(A<0){A=0}q.tabs("option","active",A);F=$("#authMenu").tabs({active:0});if(e.choicetab){F.tabs("option","active",$('#authMenu a[href="#'+e.choicetab+'"]').parent().index())}if(e.login){$("input[type=password]:first").focus()}else{$("input[type!=hidden]:first").focus()}if(e.newwindow){$("#appslist a").attr("target","_blank")}if($("p.removeOther").length){E=$("form.login").attr("action");p=$("form.login").attr("method");C="";if(E.indexOf("?")!==-1){E.substring(0,E.indexOf("?"))+"?"}else{C=E+"?"}$("form.login input[type=hidden]").each(function(J){return C+="&"+$(this).attr("name")+"="+$(this).val()});s=$("p.removeOther a").attr("href")+"&method="+p+"&url="+btoa(C);$("p.removeOther a").attr("href",s)}I=g("llnglanguage");if(!I){if(navigator){x=[];w=[];n=[navigator.language];if(navigator.languages){n=navigator.languages}r=window.availableLanguages;for(G=0,H=r.length;G<H;G++){D=r[G];y+='<img class="langicon" src="'+window.staticPrefix+"common/"+D+'.png" title="'+D+'"> ';for(B=0,u=n.length;B<u;B++){o=n[B];if(D===o){x.push(D)}else{if(D.substring(0,1)===o.substring(0,1)){w.push(D)}}}}I=x[0]?x[0]:w[0]?w[0]:"en"}else{I="en"}}m("llnglanguage",I);l(I);y="";v=window.availableLanguages;for(z=0,t=v.length;z<t;z++){D=v[z];y+='<img class="langicon" src="'+window.staticPrefix+"common/"+D+'.png" title="'+D+'"> '}$("#languages").html(y);$(".langicon").on("click",function(){I=$(this).attr("title");m("llnglanguage",I);return l(I)});if(e.pingInterval&&e.pingInterval>0){window.setTimeout(k,e.pingInterval)}return $(".localeDate").each(function(){var J;J=new Date($(this).attr("val")*1000);return $(this).text(J.toLocaleString())})})}).call(this);
(function(){var e,g,j,d,a,k,i,m,f,b,l,c,h=[].indexOf||function(p){for(var o=0,n=this.length;o<n;o++){if(o in this&&this[o]===p){return o}}return -1};c={};l=function(n){return $.getJSON(window.staticPrefix+"languages/"+n+".json",function(o){c=o;$("[trspan]").each(function(){var s,t,q,p,r;s=$(this).attr("trspan").split(",");p=b(s.shift());for(t=0,q=s.length;t<q;t++){r=s[t];p.replace(/%[ds]/,r)}return $(this).text(p)});$("[trmsg]").each(function(){return $(this).text(b("PE"+($(this).attr("trmsg"))))});$("[trplaceholder]").each(function(){return $(this).attr("placeholder",b($(this).attr("trplaceholder")))});return $("[localtime]").each(function(){var p;p=new Date($(this).attr("localtime")*1000);return $(this).text(p.toLocaleString())})})};b=function(n){if(c[n]){return c[n]}else{return n}};window.translate=b;d=function(){var n;n={};$("script[type='application/init']").each(function(){var s,p,o,r,q;try{q=JSON.parse($(this).text());r=[];for(o in q){r.push(n[o]=q[o])}return r}catch(p){s=p;console.log("Parsing error",s);return console.log("JSON",$(this).text())}});return n};f="#appslist";j=function(){return $.ajax({type:"PUT",url:e.scriptname+"/mysession/persistent",data:{_appsListOrder:$(f).sortable("toArray").join()},dataType:"json"})};i=function(){var p,o,s,A,n,x,q,t,r,w,y,u,z;w=$(f);if(!((w!=null)&&e.appslistorder)){return null}p=e.appslistorder.split(",");x=w.sortable("toArray");y=[];for(s=0,t=x.length;s<t;s++){z=x[s];y[z]=z}for(q=0,r=p.length;q<r;q++){n=p[q];if(h.call(y,n)>=0){A=y[n];o=$(f+".ui-sortable").children("#"+A);u=$(f+".ui-sortable").children("#"+n);o.remove();$(f+".ui-sortable").filter(":first").append(u)}}return 1};a=function(n){return $("#lmhidden_"+n).length};k=function(){return $.ajax({type:"POST",url:e.scriptname,data:{ping:1},dataType:"json",success:function(n){if((n.result!=null)&&n.result===1){return setTimeout(k,e.pingInterval)}else{return location.reload(true)}},error:function(n,o,p){return location.reload(true)}})};window.ping=k;g=function(q){var t,o,r,n,p,s;p=q+"=";o=decodeURIComponent(document.cookie).split(";");s=new RegExp("^ *"+q+"=");for(r=0,n=o.length;r<n;r++){t=o[r];if(t.match(s)){t=t.replace(s,"");return t}}return""};m=function(n,p,o){var q;q=new Date();q.setTime(q.getTime()+o*86400000);return document.cookie=n+"="+p+"; expires="+(q.toUTCString())+"; path=/"};e={};$(document).ready(function(){var E,D,F,C,G,B,I,y,x,w,H,u,t,s,z,A,q,p,o,n,r,v;e=d();window.datas=e;if(e.antiframe&&top!==self){top.location.href=location.href}$("#appslist").sortable({axis:"y",cursor:"move",opacity:0.5,revert:true,items:"> div.category",update:function(){return j()}});i();$("div.message").fadeIn("slow");$("input[name=timezone]").val(-(new Date().getTimezoneOffset()/60));q=$("#menu").tabs({active:0});A=$('#menu a[href="#'+e.displaytab+'"]').parent().index();if(A<0){A=0}q.tabs("option","active",A);F=$("#authMenu").tabs({active:0});if(e.choicetab){F.tabs("option","active",$('#authMenu a[href="#'+e.choicetab+'"]').parent().index())}if(e.login){$("input[type=password]:first").focus()}else{$("input[type!=hidden]:first").focus()}if(e.newwindow){$("#appslist a").attr("target","_blank")}if($("p.removeOther").length){E=$("form.login").attr("action");p=$("form.login").attr("method");C="";if(E.indexOf("?")!==-1){E.substring(0,E.indexOf("?"))+"?"}else{C=E+"?"}$("form.login input[type=hidden]").each(function(J){return C+="&"+$(this).attr("name")+"="+$(this).val()});s=$("p.removeOther a").attr("href")+"&method="+p+"&url="+btoa(C);$("p.removeOther a").attr("href",s)}I=g("llnglanguage");if(!I){if(navigator){x=[];w=[];n=[navigator.language];if(navigator.languages){n=navigator.languages}r=window.availableLanguages;for(G=0,H=r.length;G<H;G++){D=r[G];y+='<img class="langicon" src="'+window.staticPrefix+"common/"+D+'.png" title="'+D+'"> ';for(B=0,u=n.length;B<u;B++){o=n[B];if(D===o){x.push(D)}else{if(D.substring(0,1)===o.substring(0,1)){w.push(D)}}}}I=x[0]?x[0]:w[0]?w[0]:"en"}else{I="en"}}m("llnglanguage",I);l(I);y="";v=window.availableLanguages;for(z=0,t=v.length;z<t;z++){D=v[z];y+='<img class="langicon" src="'+window.staticPrefix+"common/"+D+'.png" title="'+D+'"> '}$("#languages").html(y);$(".langicon").on("click",function(){I=$(this).attr("title");m("llnglanguage",I);return l(I)});if(e.pingInterval&&e.pingInterval>0){window.setTimeout(k,e.pingInterval)}return $(".localeDate").each(function(){var J;J=new Date($(this).attr("val")*1000);return $(this).text(J.toLocaleString())})})}).call(this);