From: Olivier Lamy Date: Sat, 14 Jan 2012 22:33:41 +0000 (+0000) Subject: don't parse all the document for display element with karma needed X-Git-Tag: archiva-1.4-M3~1588 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=589139854ab397c2ece4efae2b7e8ddf7387d3c6;p=archiva.git don't parse all the document for display element with karma needed git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1231596 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/main.js b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/main.js index 22599b379..706bc5c41 100644 --- a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/main.js +++ b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/main.js @@ -68,41 +68,48 @@ $(function() { } decorateMenuWithKarma=function(user) { - var username = user.username; - // we can receive an observable user so take if it's a function or not - if ($.isFunction(username)){ - username = user.username(); + var username = user.username; + // we can receive an observable user so take if it's a function or not + if ($.isFunction(username)){ + username = user.username(); + } + var url = 'restServices/redbackServices/userService/getCurrentUserOperations'; + $.ajax({ + url: url, + success: function(data){ + var mappedOperations = $.map(data.operation, function(item) { + return mapOperation(item); + }); + window.redbackModel.operatioNames = $.map(mappedOperations, function(item){ + return item.name(); + }); + + $("#topbar-menu-container [redback-permissions]").each(function(element){ + checkElementKarma(this); + }); + $("#sidebar-content [redback-permissions]").each(function(element){ + checkElementKarma(this); + }); } - var url = 'restServices/redbackServices/userService/getCurrentUserOperations'; - $.ajax({ - url: url, - success: function(data){ - var mappedOperations = $.map(data.operation, function(item) { - return mapOperation(item); - }); - window.redbackModel.operatioNames = $.map(mappedOperations, function(item){ - return item.name(); - }); - - $("[redback-permissions]").each(function(element){ - var bindingValue = $(this).attr("redback-permissions"); - $(this).hide(); - var neededKarmas = $(eval(bindingValue)).toArray(); - var karmaOk = false; - $(neededKarmas).each(function(value){ - if ($.inArray(neededKarmas[value],window.redbackModel.operatioNames)>=0) { - karmaOk = true; - } - }); - if (karmaOk == false) { - $(this).hide(); - } else { - $(this).show(); - } - }); - } - }); + }); + } + + checkElementKarma=function(element){ + var bindingValue = $(element).attr("redback-permissions"); + $(element).hide(); + var neededKarmas = $(eval(bindingValue)).toArray(); + var karmaOk = false; + $(neededKarmas).each(function(value){ + if ($.inArray(neededKarmas[value],window.redbackModel.operatioNames)>=0) { + karmaOk = true; + } + }); + if (karmaOk == false) { + $(element).hide(); + } else { + $(element).show(); } + } hideElementWithKarma=function(){ $("#topbar-menu-container [redback-permissions]").each(function(element){ @@ -166,8 +173,6 @@ $(function() { hideElementWithKarma(); checkSecurityLinks(); - - }) });