]> source.dussan.org Git - archiva.git/commitdiff
do not ask ldap informations if ldap is not activated
authorOlivier Lamy <olamy@apache.org>
Mon, 18 Feb 2013 11:21:58 +0000 (11:21 +0000)
committerOlivier Lamy <olamy@apache.org>
Mon, 18 Feb 2013 11:21:58 +0000 (11:21 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1447203 13f79535-47bb-0310-9956-ffa450edef68

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

index 571345276b9cfacf012307842db91b0736a616bd..d40b6e6636f8d88655c997a0943ab8fc852c571b 100644 (file)
@@ -1714,69 +1714,42 @@ define("archiva.general-admin",["jquery","i18n","utils","jquery.tmpl","knockout"
           var useLdap = $.inArray("ldap",redbackRuntimeConfiguration.usedUserManagerImpls)>0
                   ||$.inArray("ldap",redbackRuntimeConfiguration.rbacManagerImpls)>0;
           $.log("useLdap:"+useLdap);
-          // load ldap roles
-          $.ajax("restServices/redbackServices/ldapGroupMappingService/ldapGroups", {
-            type: "GET",
-            dataType: 'json',
-            success: function(data){
-              groups = mapStringList(data);
-              $.log("groups number:"+groups.length);
-              redbackRuntimeConfiguration.ldapGroups=ko.observableArray(groups);
-            }
-          } )
+          if(useLdap){
+            // load ldap roles
+            $.ajax("restServices/redbackServices/ldapGroupMappingService/ldapGroups", {
+              type: "GET",
+              dataType: 'json',
+              success: function(data){
+                groups = mapStringList(data);
+                $.log("groups number:"+groups.length);
+                redbackRuntimeConfiguration.ldapGroups=ko.observableArray(groups);
+              }
+            } )
             .always(
-                  function() {
-                    $.log("complete");
+              function() {
+                $.log("complete");
+
+                // load ldap group mappings if any
+                $.ajax("restServices/redbackServices/ldapGroupMappingService", {
+                  type: "GET",
+                  dataType: 'json',
+                  success: function(data) {
+                    var groupMappings=mapLdapGroupMappings(data,redbackRuntimeConfigurationViewModel.modifyLdapGroupMapping);
 
-                    // load ldap group mappings if any
-                    $.ajax("restServices/redbackServices/ldapGroupMappingService", {
+                    $.ajax("restServices/redbackServices/roleManagementService/allRoles", {
                       type: "GET",
                       dataType: 'json',
                       success: function(data) {
-                        var groupMappings=mapLdapGroupMappings(data,redbackRuntimeConfigurationViewModel.modifyLdapGroupMapping);
-
-                        $.ajax("restServices/redbackServices/roleManagementService/allRoles", {
-                          type: "GET",
-                          dataType: 'json',
-                          success: function(data) {
-
-                            var allRoleNames = $.map(data, function(item) {
-                              return item.name;
-                            });
-
-                            redbackRuntimeConfigurationViewModel.allRoleNames=allRoleNames;
-                            if (redbackRuntimeConfiguration.ldapConfiguration().useRoleNameAsGroup()) {
-                              // if using groups == roles add all as mapping except already mapped
-                              $.each(groups,function(idx,item){
-                                var exists=false;
-                                // avoid duplicate if mapping really exists !
-                                $.each(groupMappings,function(idx2,groupMapping){
-                                  if(groupMapping.group()==item){
-                                    exists=true;
-                                  }
-                                });
-                                if(!exists){
-                                  groupMappings.push(new LdapGroupMapping(item,[item],true,redbackRuntimeConfigurationViewModel.modifyLdapGroupMapping));
-                                }
-
-                              });
-                            }
-                            redbackRuntimeConfiguration.ldapGroupMappings=ko.observableArray(groupMappings);
-                            redbackRuntimeConfiguration.modified(false);
-
-                            mainContent.html( $("#redback-runtime-configuration-main" ).tmpl() );
-                            ko.applyBindings(redbackRuntimeConfigurationViewModel,$("#redback-runtime-configuration-content" ).get(0));
-                            activateRedbackRuntimeGeneralFormValidation();
-                            activateLdapConfigurationFormValidation();
-                            $("#ldap-group-mappings-div select" ).select2({width: "element"});
-
-                          }
-                        });
+                        displayRuntimeConfigurationScreen(redbackRuntimeConfigurationViewModel,data,groupMappings,groups);
                       }
                     });
                   }
-                );
-
+                });
+              }
+            );
+          } else {
+            displayRuntimeConfigurationScreen(redbackRuntimeConfigurationViewModel,null,null);
+          }
         }
       });
 
@@ -1785,6 +1758,38 @@ define("archiva.general-admin",["jquery","i18n","utils","jquery.tmpl","knockout"
 
   }
 
+  displayRuntimeConfigurationScreen=function(redbackRuntimeConfigurationViewModel,allRoles,groupMappings,groups){
+    var allRoleNames = $.map(allRoles?allRoles:[], function(item) {
+      return item.name;
+    });
+
+    redbackRuntimeConfigurationViewModel.allRoleNames=allRoleNames;
+    if (redbackRuntimeConfigurationViewModel.redbackRuntimeConfiguration().ldapConfiguration().useRoleNameAsGroup()) {
+      // if using groups == roles add all as mapping except already mapped
+      $.each(groups,function(idx,item){
+        var exists=false;
+        // avoid duplicate if mapping really exists !
+        $.each(groupMappings,function(idx2,groupMapping){
+          if(groupMapping.group()==item){
+            exists=true;
+          }
+        });
+        if(!exists){
+          groupMappings.push(new LdapGroupMapping(item,[item],true,redbackRuntimeConfigurationViewModel.modifyLdapGroupMapping));
+        }
+
+      });
+    }
+    redbackRuntimeConfigurationViewModel.redbackRuntimeConfiguration().ldapGroupMappings=ko.observableArray(groupMappings?groupMappings:[]);
+    redbackRuntimeConfigurationViewModel.redbackRuntimeConfiguration().modified(false);
+
+    $("#main-content").html( $("#redback-runtime-configuration-main" ).tmpl() );
+    ko.applyBindings(redbackRuntimeConfigurationViewModel,$("#redback-runtime-configuration-content" ).get(0));
+    activateRedbackRuntimeGeneralFormValidation();
+    activateLdapConfigurationFormValidation();
+    $("#ldap-group-mappings-div select" ).select2({width: "element"});
+  }
+
   LdapGroupMapping=function(group,roleNames,automatic,subscribeFn){
     var self=this;
     this.modified=ko.observable(false);