Validate ids 35/89335/1
authorWojciech Sliwka <wojciech.sliwka@nokia.com>
Wed, 5 Jun 2019 09:01:00 +0000 (11:01 +0200)
committerWojciech Sliwka <wojciech.sliwka@nokia.com>
Wed, 5 Jun 2019 09:01:00 +0000 (11:01 +0200)
Disable close button when policy id is duplicated

Issue-ID: CLAMP-403
Signed-off-by: Wojciech Sliwka <wojciech.sliwka@nokia.com>
Change-Id: I47dee2e27ce4f7a5e2083a541458a04da8cf7bee

src/main/resources/META-INF/resources/designer/partials/portfolios/operational_policy_window.html
src/main/resources/META-INF/resources/designer/scripts/OperationalPolicyCtrl.js

index db127f7..7b13615 100644 (file)
@@ -165,12 +165,12 @@ label {
                                <form class="policyProperties" class="form-horizontal"
                                        style="border: 2px dotted gray;"
                                        title="Operational Policy Properties">
-
                                        <div class="form-group clearfix">
                                                <label class="col-sm-4 control-label" for="id">ID</label>
                                                <div class="col-sm-8">
-                                                       <input type="text" class="form-control" name="id" id="id"
+                                                       <input type="text" class="form-control"  name="id" id="id" ng-model="duplicated" ng-init="duplicated = false"
                                                                ng-keyup="updateTabLabel($event)" />
+                                                       <span >ID must be unique</span>
                                                </div>
                                        </div>
                                        <div class="form-group clearfix">
@@ -247,6 +247,7 @@ label {
                                                                ng-options="policy for policy in policy_ids track by policy">
                                                                <option value="">-- choose an option --</option>
                                                                </select>
+
                                                </div>
                                        </div>
                                        <div class="form-group clearfix">
@@ -481,7 +482,7 @@ label {
        </div>
 
        <div attribute-test="policywindowpropertiesf" class="modal-footer">
-               <button id="savePropsBtn" class="btn btn-primary">Close</button>
+               <button id="savePropsBtn" class="btn btn-primary" ng-disabled="duplicated">Close</button>
                <button ng-click="close(true)" id="close_button"
                        class="btn btn-primary">Cancel</button>
        </div>
index 0f9b62f..806cfea 100644 (file)
@@ -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");