Fix LDAP service update error

When a service is enabled, it must be disabled prior
to changing the service type, e.g change from OpenLDAP
to ActiveDirectory.

- Add check to determine if a service is already enabled
- Make two calls if service is already enabled. First to
  disable existing service. Second to enable updated
  service
- Remove toast message for ssl check and replace with
  error message which also keeps submit button disabled
  if the regex pattern is not met

Tested:
- Edge
- Safari
- Firefox
- Chrome
- IE 11

Signed-off-by: Derick Montague <derick.montague@ibm.com>
Change-Id: I195eeb7d1cd3621681c18f4dd9aa4414eb079c09
diff --git a/app/common/directives/ldap-user-roles.js b/app/common/directives/ldap-user-roles.js
index afe30c5..0074170 100644
--- a/app/common/directives/ldap-user-roles.js
+++ b/app/common/directives/ldap-user-roles.js
@@ -41,22 +41,19 @@
             };
 
             $scope.addRoleGroup = () => {
+              $scope.loading = true;
+
               const newGroup = {};
               newGroup.RemoteGroup = $scope.newGroup.RemoteGroup;
               newGroup.LocalRole = $scope.newGroup.LocalRole;
 
-              $scope.loading = true;
               const data = {};
-
-              if ($scope.roleGroupType == 'ldap') {
-                data.LDAP = {};
-                data.LDAP.RemoteRoleMapping = $scope.roleGroups;
-                data.LDAP.RemoteRoleMapping.push(newGroup);
-              } else {
-                data.ActiveDirectory = {};
-                data.ActiveDirectory.RemoteRoleMapping = $scope.roleGroups;
-                data.ActiveDirectory.RemoteRoleMapping.push(newGroup);
-              }
+              const roleGroups = $scope.roleGroups;
+              const roleGroupType = $scope.roleGroupType;
+              data[roleGroupType] = {};
+              data[roleGroupType]['RemoteRoleMapping'] = roleGroups;
+              data[roleGroupType]['RemoteRoleMapping'][roleGroups.length] =
+                  newGroup;
 
               APIUtils.saveLdapProperties(data)
                   .then(
@@ -82,19 +79,14 @@
             $scope.editRoleGroup = () => {
               $scope.loading = true;
               const data = {};
-
-              if ($scope.roleGroupType == 'ldap') {
-                data.LDAP = {};
-                data.LDAP.RemoteRoleMapping = $scope.roleGroups;
-                data.LDAP.RemoteRoleMapping[$scope.selectedGroupIndex]
-                    .LocalRole = $scope.newGroup.LocalRole;
-              } else {
-                data.ActiveDirectory = {};
-                data.ActiveDirectory.RemoteRoleMapping = $scope.roleGroups;
-                data.ActiveDirectory
-                    .RemoteRoleMapping[$scope.selectedGroupIndex]
-                    .LocalRole = $scope.newGroup.LocalRole;
-              }
+              const roleGroupType = $scope.roleGroupType;
+              const roleGroups = $scope.roleGroups;
+              const localRole = $scope.newGroup.LocalRole;
+              const selectedIndex = $scope.selectedGroupIndex;
+              data[roleGroupType] = {};
+              data[roleGroupType]['RemoteRoleMapping'] = roleGroups;
+              data[roleGroupType]['RemoteRoleMapping'][selectedIndex]['LocalRole'] =
+                  localRole;
 
               APIUtils.saveLdapProperties(data)
                   .then(
@@ -111,29 +103,21 @@
               $scope.editGroup = false;
             };
 
-            $scope.removeGroupFn = (index) => {
+            $scope.removeGroupFn = index => {
               $scope.removeGroup = true;
               $scope.selectedGroupIndex = index;
             };
 
             $scope.removeRoleGroup = () => {
               $scope.loading = true;
+              const roleGroupType = $scope.roleGroupType;
+              const roleGroups = $scope.roleGroups;
+              const selectedGroupIndex = $scope.selectedGroupIndex;
               const data = {};
-
-              if ($scope.roleGroupType == 'ldap') {
-                data.LDAP = {};
-                data.LDAP.RemoteRoleMapping = $scope.roleGroups;
-                data.LDAP.RemoteRoleMapping[$scope.selectedGroupIndex] =
-                    $scope.newGroup;
-              } else {
-                data.ActiveDirectory = {};
-                data.ActiveDirectory.RemoteRoleMapping = $scope.roleGroups;
-                data.ActiveDirectory
-                    .RemoteRoleMapping[$scope.selectedGroupIndex] =
-                    $scope.newGroup;
-              }
-
-              $scope.roleGroups[$scope.selectedGroupIndex] = null;
+              data[roleGroupType] = {};
+              data[roleGroupType]['RemoteRoleMapping'] = roleGroups;
+              data[roleGroupType]['RemoteRoleMapping'][selectedGroupIndex] =
+                  null;
 
               APIUtils.saveLdapProperties(data)
                   .then(
@@ -158,7 +142,7 @@
             $scope.roleGroupIsSelectedChanged = () => {
               let groupSelected = false;
               $scope.roleGroups.forEach(group => {
-                if (group['isSelected']) {
+                if (group && group['isSelected']) {
                   groupSelected = true;
                 }
               });
@@ -167,28 +151,18 @@
 
             $scope.removeMultipleRoleGroups = () => {
               $scope.loading = true;
+              const roleGroupType = $scope.roleGroupType;
+              const roleGroups = $scope.roleGroups;
               const data = {};
-
-              if ($scope.roleGroupType == 'ldap') {
-                data.LDAP = {};
-                data.LDAP.RemoteRoleMapping = $scope.roleGroups.map((group) => {
-                  if (group['isSelected']) {
-                    return null;
-                  } else {
-                    return group;
-                  }
-                });
-              } else {
-                data.ActiveDirectory = {};
-                data.ActiveDirectory.RemoteRoleMapping =
-                    $scope.roleGroups.map((group) => {
-                      if (group['isSelected']) {
-                        return null;
-                      } else {
-                        return group;
-                      }
-                    });
-              }
+              data[roleGroupType] = {};
+              data[roleGroupType]['RemoteRoleMapping'] =
+                  roleGroups.map((group) => {
+                    if (group['isSelected']) {
+                      return null;
+                    } else {
+                      return group;
+                    }
+                  });
 
               APIUtils.saveLdapProperties(data)
                   .then(