]> source.dussan.org Git - archiva.git/commitdiff
don't parse all the document for display element with karma needed
authorOlivier Lamy <olamy@apache.org>
Sat, 14 Jan 2012 22:33:41 +0000 (22:33 +0000)
committerOlivier Lamy <olamy@apache.org>
Sat, 14 Jan 2012 22:33:41 +0000 (22:33 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1231596 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/main.js

index 22599b379c0538b128855a8ab6f75e12534d04d8..706bc5c4194b80416e866230679fd0d1db6b83cf 100644 (file)
@@ -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();
 
-
-
 })
 });