diff --git a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Plugins/FavApps.pm b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Plugins/FavApps.pm index d51fbdd11..7adcaeada 100644 --- a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Plugins/FavApps.pm +++ b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Plugins/FavApps.pm @@ -17,6 +17,7 @@ sub init { $self->addAuthRoute( favapps => 'register', ['POST'] ); $self->addAuthRoute( favapps => 'read', ['GET'] ); + $self->addAuthRoute( favapps => 'reset', ['DELETE'] ); # Parse activation rule $self->logger->debug( @@ -159,6 +160,22 @@ sub read { ]; } +sub reset { + my ( $self, $req ) = @_; + my $user = $req->userData->{ $self->conf->{whatToTrace} }; + $self->p->updatePersistentSession( $req, { _favApps => '' } ); + $self->userLogger->notice("$user favorite Apps. RESET"); + + return [ + 200, + [ + 'Content-Type' => 'application/json', + 'Content-Length' => 12, + ], + ['{"result":1}'] + ]; +} + sub _isFavApp { my ( $self, $_favApps, $uri ) = @_; my $test = 0; diff --git a/lemonldap-ng-portal/site/coffee/favapps.coffee b/lemonldap-ng-portal/site/coffee/favapps.coffee index 58aab2ee8..615ce718e 100644 --- a/lemonldap-ng-portal/site/coffee/favapps.coffee +++ b/lemonldap-ng-portal/site/coffee/favapps.coffee @@ -4,35 +4,47 @@ LemonLDAP::NG Favorite Applications script # FavApps function (launched by "star" icon) FavApps = (star) -> - $.ajax - type: "POST" - url: "#{portal}favapps" - data: - id: star.attr 'aid' - uri: star.attr 'uri' - name: star.attr 'name' - logo: star.attr 'logo' - desc: star.attr 'desc' - dataType: 'json' - success: (resp) -> - if resp.error - console.log 'Max number reached' + $.ajax + type: "POST" + url: "#{portal}favapps" + data: + id: star.attr 'aid' + uri: star.attr 'uri' + name: star.attr 'name' + logo: star.attr 'logo' + desc: star.attr 'desc' + dataType: 'json' + success: (resp) -> + if resp.error + console.log 'Max number reached' + switchStar star, 0 + else if resp.error == 0 + console.log 'Not authorized' switchStar star, 0 - else if resp.error == 0 - console.log 'Not authorized' + else if resp.result + console.log 'App. registered' + switchStar star, 1 + else + console.log 'App. unregistered' switchStar star, 0 - else if resp.result - console.log 'App. registered' - switchStar star, 1 - else - console.log 'App. unregistered' - switchStar star, 0 - error: switchStar star, '0' + error: switchStar star, '0' + +ResetFavApps = -> + $.ajax + type: "DELETE" + url: "#{portal}favapps" + success: (resp) -> + if resp.result + console.log 'Favorite Apps. reset' + window.location.reload() + else + console.log 'Error' switchStar = (star, status) -> star.attr('src', "#{window.staticPrefix}common/icons/star#{status}.png") #window.location.reload() -# Switch "star" events +# Switch "star" ans Reset events $(document).ready -> $('body').on 'click', '.star', () -> FavApps $(this) + $('#reset').on 'click', () -> ResetFavApps() diff --git a/lemonldap-ng-portal/site/htdocs/static/common/js/favapps.js b/lemonldap-ng-portal/site/htdocs/static/common/js/favapps.js index 5cfbe5f80..501fef0b0 100644 --- a/lemonldap-ng-portal/site/htdocs/static/common/js/favapps.js +++ b/lemonldap-ng-portal/site/htdocs/static/common/js/favapps.js @@ -5,7 +5,7 @@ LemonLDAP::NG Favorite Applications script */ (function() { - var FavApps, switchStar; + var FavApps, ResetFavApps, switchStar; FavApps = function(star) { return $.ajax({ @@ -38,14 +38,32 @@ LemonLDAP::NG Favorite Applications script }); }; + ResetFavApps = function() { + return $.ajax({ + type: "DELETE", + url: portal + "favapps", + success: function(resp) { + if (resp.result) { + console.log('Favorite Apps. reset'); + return window.location.reload(); + } else { + return console.log('Error'); + } + } + }); + }; + switchStar = function(star, status) { return star.attr('src', window.staticPrefix + "common/icons/star" + status + ".png"); }; $(document).ready(function() { - return $('body').on('click', '.star', function() { + $('body').on('click', '.star', function() { return FavApps($(this)); }); + return $('#reset').on('click', function() { + return ResetFavApps(); + }); }); }).call(this); diff --git a/lemonldap-ng-portal/site/htdocs/static/common/js/favapps.min.js b/lemonldap-ng-portal/site/htdocs/static/common/js/favapps.min.js index c5de0fdae..9c5b3ff0c 100644 --- a/lemonldap-ng-portal/site/htdocs/static/common/js/favapps.min.js +++ b/lemonldap-ng-portal/site/htdocs/static/common/js/favapps.min.js @@ -1 +1 @@ -(function(){var FavApps,switchStar;FavApps=function(star){return $.ajax({type:"POST",url:portal+"favapps",data:{id:star.attr("aid"),uri:star.attr("uri"),name:star.attr("name"),logo:star.attr("logo"),desc:star.attr("desc")},dataType:"json",success:function(resp){if(resp.error){console.log("Max number reached");return switchStar(star,0)}else if(resp.error===0){console.log("Not authorized");return switchStar(star,0)}else if(resp.result){console.log("App. registered");return switchStar(star,1)}else{console.log("App. unregistered");return switchStar(star,0)}},error:switchStar(star,"0")})};switchStar=function(star,status){return star.attr("src",window.staticPrefix+"common/icons/star"+status+".png")};$(document).ready(function(){return $("body").on("click",".star",function(){return FavApps($(this))})})}).call(this); +(function(){var FavApps,ResetFavApps,switchStar;FavApps=function(star){return $.ajax({type:"POST",url:portal+"favapps",data:{id:star.attr("aid"),uri:star.attr("uri"),name:star.attr("name"),logo:star.attr("logo"),desc:star.attr("desc")},dataType:"json",success:function(resp){if(resp.error){console.log("Max number reached");return switchStar(star,0)}else if(resp.error===0){console.log("Not authorized");return switchStar(star,0)}else if(resp.result){console.log("App. registered");return switchStar(star,1)}else{console.log("App. unregistered");return switchStar(star,0)}},error:switchStar(star,"0")})};ResetFavApps=function(){return $.ajax({type:"DELETE",url:portal+"favapps",success:function(resp){if(resp.result){console.log("Favorite Apps. reset");return window.location.reload()}else{return console.log("Error")}}})};switchStar=function(star,status){return star.attr("src",window.staticPrefix+"common/icons/star"+status+".png")};$(document).ready(function(){$("body").on("click",".star",function(){return FavApps($(this))});return $("#reset").on("click",function(){return ResetFavApps()})})}).call(this); diff --git a/lemonldap-ng-portal/site/templates/bootstrap/menu.tpl b/lemonldap-ng-portal/site/templates/bootstrap/menu.tpl index cd6813d23..aeb615fc2 100644 --- a/lemonldap-ng-portal/site/templates/bootstrap/menu.tpl +++ b/lemonldap-ng-portal/site/templates/bootstrap/menu.tpl @@ -138,6 +138,13 @@ +
+ + + Reset my favorite Apps. + +
+