Validate ids
[clamp.git] / src / main / resources / META-INF / resources / designer / scripts / OperationalPolicyCtrl.js
index 55db5e7..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"));
@@ -245,7 +247,7 @@ app
                            }
                    }
                    var resourceVFModule = getResourceDetailsVfModuleProperty();
-                   if (targetType == "VFModule" && (null !== resourceVFModule || undefined !== resourceVFModule)) {
+                   if (targetType == "VFMODULE" && (null !== resourceVFModule || undefined !== resourceVFModule)) {
                            if (recipe == 'VF Module Create' || recipe == 'VF Module Delete') {
                                    for ( var prop in resourceVFModule) {
                                            if (resourceVFModule[prop]["isBase"] == false) {
@@ -306,7 +308,7 @@ app
                    var resourceVFModule = getResourceDetailsVfModuleProperty();
                    var type = $("#formId" + formNum +" #type").val();
                    var recipe = $("#formId" + formNum +" #recipe").val();
-                   if (type == "VFModule" && (null !== resourceVFModule || undefined !== resourceVFModule)
+                   if (type == "VFMODULE" && (null !== resourceVFModule || undefined !== resourceVFModule)
                    && (recipe == 'VF Module Create' || recipe == 'VF Module Delete')) {
                            for ( var prop in resourceVFModule) {
                                    if (prop ==  $(event.target).val()) {
@@ -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");