From 3f4cbda9ef295a42fe2fe16b7bd7995fac8e174e Mon Sep 17 00:00:00 2001 From: Wojciech Sliwka Date: Wed, 5 Jun 2019 11:01:00 +0200 Subject: Validate ids Disable close button when policy id is duplicated Issue-ID: CLAMP-403 Signed-off-by: Wojciech Sliwka Change-Id: I47dee2e27ce4f7a5e2083a541458a04da8cf7bee --- .../portfolios/operational_policy_window.html | 7 +++--- .../designer/scripts/OperationalPolicyCtrl.js | 27 ++++++++++++++-------- 2 files changed, 22 insertions(+), 12 deletions(-) (limited to 'src/main/resources') diff --git a/src/main/resources/META-INF/resources/designer/partials/portfolios/operational_policy_window.html b/src/main/resources/META-INF/resources/designer/partials/portfolios/operational_policy_window.html index db127f7d2..7b13615a1 100644 --- a/src/main/resources/META-INF/resources/designer/partials/portfolios/operational_policy_window.html +++ b/src/main/resources/META-INF/resources/designer/partials/portfolios/operational_policy_window.html @@ -165,12 +165,12 @@ label {
-
- + ID must be unique
@@ -247,6 +247,7 @@ label { ng-options="policy for policy in policy_ids track by policy"> +
@@ -481,7 +482,7 @@ label {
diff --git a/src/main/resources/META-INF/resources/designer/scripts/OperationalPolicyCtrl.js b/src/main/resources/META-INF/resources/designer/scripts/OperationalPolicyCtrl.js index 0f9b62ffe..806cfea9d 100644 --- a/src/main/resources/META-INF/resources/designer/scripts/OperationalPolicyCtrl.js +++ b/src/main/resources/META-INF/resources/designer/scripts/OperationalPolicyCtrl.js @@ -39,6 +39,8 @@ app $scope.number = 0; $scope.clname = ""; $scope.guard_ids = []; + $scope.duplicated = false; + function getAllFormId() { return Array.from(document.getElementsByClassName("formId")); @@ -400,15 +402,22 @@ app $($("#formId" + formNum + " #actor")[1]).val($(event.target).val()); } // When we change the name of a policy - $scope.updateTabLabel = function(event) { - - // update policy id structure - var formNum = $(event.target).closest('.formId').attr('id').substring(6); - $scope.policy_ids.splice($scope.policy_ids.indexOf($("#formId" + formNum + " #id").val()), 1); - $scope.policy_ids.push($(event.target).val()); - // Update the tab now - $("#go_properties_tab" + formNum).text($(event.target).val()); - } + $scope.updateTabLabel = function (event) { + + // update policy id structure + var formNum = $(event.target).closest('.formId').attr('id').substring(6); + var policyId = $(event.target).val(); + if ($scope.policy_ids.includes(policyId)) { + console.log("Duplicated ID, cannot proceed"); + $scope.duplicated = true; + } else { + $scope.duplicated = false; + $scope.policy_ids.splice($scope.policy_ids.indexOf($("#formId" + formNum + " #id").val()), 1); + $scope.policy_ids.push($(event.target).val()); + // Update the tab now + $("#go_properties_tab" + formNum).text($(event.target).val()); + } + }; $scope.close = function() { console.log("close"); -- cgit 1.2.3-korg