Improve JS code (#1689)
This commit is contained in:
parent
5f8dcfb2b1
commit
33f8970a17
|
@ -3,42 +3,31 @@ LemonLDAP::NG Favorite Applications script
|
|||
###
|
||||
|
||||
# FavApps function (launched by "star" icon)
|
||||
FavApps = (star, appuri) ->
|
||||
FavApps = (star) ->
|
||||
$.ajax
|
||||
type: "POST"
|
||||
url: "#{portal}favapps"
|
||||
data:
|
||||
app: appuri
|
||||
logo: logo
|
||||
title: title
|
||||
app: star.attr 'appuri'
|
||||
logo: star.attr 'logo'
|
||||
desc: star.attr 'desc'
|
||||
title: star.attr 'title'
|
||||
dataType: 'json'
|
||||
#error: star.attr('src', 'static/common/icons/star0.png')
|
||||
success: (resp) ->
|
||||
if resp.error
|
||||
#console.log 'Error'
|
||||
#star.attr('src', 'static/common/icons/star0.png')
|
||||
switchStar star, '0'
|
||||
console.log 'Error'
|
||||
switchStar star, 0
|
||||
else if resp.result
|
||||
#console.log 'OK'
|
||||
#star.attr('src', 'static/common/icons/star1.png')
|
||||
switchStar star, '1'
|
||||
console.log 'App. registered'
|
||||
switchStar star, 1
|
||||
else
|
||||
#console.log 'NOK'
|
||||
#star.attr('src', 'static/common/icons/star0.png')
|
||||
switchStar star, '-1'
|
||||
console.log 'App. unregistered'
|
||||
switchStar star, 0
|
||||
#error: switchStar star, '0'
|
||||
|
||||
switchStar = (star, status) ->
|
||||
if status == '1'
|
||||
console.log 'OK'
|
||||
star.attr('src', 'static/common/icons/star1.png')
|
||||
else if status == '-1'
|
||||
console.log 'NOK'
|
||||
star.attr('src', 'static/common/icons/star0.png')
|
||||
else
|
||||
console.log 'Error'
|
||||
star.attr('src', 'static/common/icons/star0.png')
|
||||
star.attr('src', "#{window.staticPrefix}common/icons/star#{status}.png")
|
||||
|
||||
# Switch "star" events
|
||||
$(document).ready ->
|
||||
$('body').on 'click', '.star', () -> FavApps $(this), ( $(this).attr 'appuri' )
|
||||
$('body').on 'click', '.star', () -> FavApps $(this)
|
||||
|
|
|
@ -7,44 +7,39 @@ LemonLDAP::NG Favorite Applications script
|
|||
(function() {
|
||||
var FavApps, switchStar;
|
||||
|
||||
FavApps = function(star, appuri) {
|
||||
FavApps = function(star) {
|
||||
return $.ajax({
|
||||
type: "POST",
|
||||
url: portal + "favapps",
|
||||
data: {
|
||||
app: appuri,
|
||||
logo: logo,
|
||||
title: title
|
||||
app: star.attr('appuri'),
|
||||
logo: star.attr('logo'),
|
||||
desc: star.attr('desc'),
|
||||
title: star.attr('title')
|
||||
},
|
||||
dataType: 'json',
|
||||
success: function(resp) {
|
||||
if (resp.error) {
|
||||
return switchStar(star, '0');
|
||||
console.log('Error');
|
||||
return switchStar(star, 0);
|
||||
} else if (resp.result) {
|
||||
return switchStar(star, '1');
|
||||
console.log('App. registered');
|
||||
return switchStar(star, 1);
|
||||
} else {
|
||||
return switchStar(star, '-1');
|
||||
console.log('App. unregistered');
|
||||
return switchStar(star, 0);
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
switchStar = function(star, status) {
|
||||
if (status === '1') {
|
||||
console.log('OK');
|
||||
return star.attr('src', 'static/common/icons/star1.png');
|
||||
} else if (status === '-1') {
|
||||
console.log('NOK');
|
||||
return star.attr('src', 'static/common/icons/star0.png');
|
||||
} else {
|
||||
console.log('Error');
|
||||
return star.attr('src', 'static/common/icons/star0.png');
|
||||
}
|
||||
return star.attr('src', window.staticPrefix + "common/icons/star" + status + ".png");
|
||||
};
|
||||
|
||||
$(document).ready(function() {
|
||||
return $('body').on('click', '.star', function() {
|
||||
return FavApps($(this), $(this).attr('appuri'));
|
||||
return FavApps($(this));
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -1 +1 @@
|
|||
(function(){var FavApps,switchStar;FavApps=function(star,appuri){return $.ajax({type:"POST",url:portal+"favapps",data:{app:appuri,logo:logo,title:title},dataType:"json",success:function(resp){if(resp.error){return switchStar(star,"0")}else if(resp.result){return switchStar(star,"1")}else{return switchStar(star,"-1")}}})};switchStar=function(star,status){if(status==="1"){console.log("OK");return star.attr("src","static/common/icons/star1.png")}else if(status==="-1"){console.log("NOK");return star.attr("src","static/common/icons/star0.png")}else{console.log("Error");return star.attr("src","static/common/icons/star0.png")}};$(document).ready(function(){return $("body").on("click",".star",function(){return FavApps($(this),$(this).attr("appuri"))})})}).call(this);
|
||||
(function(){var FavApps,switchStar;FavApps=function(star){return $.ajax({type:"POST",url:portal+"favapps",data:{app:star.attr("appuri"),logo:star.attr("logo"),desc:star.attr("desc"),title:star.attr("title")},dataType:"json",success:function(resp){if(resp.error){console.log("Error");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)}}})};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);
|
||||
|
|
Loading…
Reference in New Issue