Fix targetResourceId issue 65/87665/3
authorxg353y <xg353y@intl.att.com>
Tue, 14 May 2019 11:17:54 +0000 (13:17 +0200)
committerxg353y <xg353y@intl.att.com>
Tue, 14 May 2019 13:11:35 +0000 (15:11 +0200)
Initialize targertResourceId options, before loading values from DB,
otherwise the value shown in the UI will be blank.

Issue-ID: CLAMP-382
Change-Id: Ie3fecab521272c5f5373161ed8070f9370fc219d
Signed-off-by: xg353y <xg353y@intl.att.com>
src/main/resources/META-INF/resources/designer/scripts/OperationalPolicyCtrl.js

index f5a93cb..f474cf4 100644 (file)
@@ -190,11 +190,15 @@ app
                                    $("#formId" + formNum + " .policyProperties").find("#" + opPolicyPropValue.id).val(
                                    allPolicies['operational_policy']['policies'][opPolicyElemIndex][opPolicyPropValue.id]);
                            });
+
+                           // Initial TargetResourceId options
+                           initTargetResourceIdOptions(allPolicies['operational_policy']['policies'][opPolicyElemIndex]['target']['type'], formNum);
                            $.each($('.policyTarget').find('.form-control'), function(opPolicyTargetPropIndex, opPolicyTargetPropValue) {
 
                                    $("#formId" + formNum + " .policyTarget").find("#" + opPolicyTargetPropValue.id).val(
                                    allPolicies['operational_policy']['policies'][opPolicyElemIndex]['target'][opPolicyTargetPropValue.id]);
                            });
+
                            // update the current tab label
                            $("#go_properties_tab" + formNum).text(
                            allPolicies['operational_policy']['policies'][opPolicyElemIndex]['id']);
@@ -216,30 +220,20 @@ app
                            });
                    });
            }
-           $scope.initTargetResourceId = function(event) {
-               var formNum = $(event.target).closest('.formId').attr('id').substring(6);
-               
-                   var type = $(event.target).val();
+           function initTargetResourceIdOptions (targetType, formNum) {
                    var recipe = $("#formId" + formNum + "#recipe").val();
-                   $("#formId" + formNum + " #modelName").val("");
-                   $("#formId" + formNum + " #modelInvariantId").val("");
-                   $("#formId" + formNum + " #modelVersionId").val("");
-                   $("#formId" + formNum + " #modelVersion").val("");
-                   $("#formId" + formNum + " #modelCustomizationId").val("");
                    $("#formId" + formNum + " #resourceId").empty();
                    $("#formId" + formNum + " #resourceId").append($('<option></option>').val("").html("-- choose an option --"));
-                   if (type == "VM" || type == "" || type == "VNF") {
-                           $("#formId" + formNum + " #metadata *").prop('disabled', true);
-                   }
+
                    var resourceVnf = getResourceDetailsVfProperty();
-                   if (type == "VNF" && (null !== resourceVnf || undefined !== resourceVnf)) {
+                   if (targetType == "VNF" && (null !== resourceVnf || undefined !== resourceVnf)) {
                            for ( var prop in resourceVnf) {
                                    var name = resourceVnf[prop]["name"];
                                    $("#formId" + formNum + " #resourceId").append($('<option></option>').val(name).html(name));
                            }
                    }
                    var resourceVFModule = getResourceDetailsVfModuleProperty();
-                   if (type == "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) {
@@ -253,13 +247,26 @@ app
                            }
                    }
            }
+
+           function initTargetModelAttributes (formNum) {
+                   $("#formId" + formNum + " #modelName").val("");
+                   $("#formId" + formNum + " #modelInvariantId").val("");
+                   $("#formId" + formNum + " #modelVersionId").val("");
+                   $("#formId" + formNum + " #modelVersion").val("");
+                   $("#formId" + formNum + " #modelCustomizationId").val("");
+           }
+
+           $scope.initTargetResourceId = function(event) {
+               var formNum = $(event.target).closest('.formId').attr('id').substring(6);
+               initTargetModelAttributes(formNum);
+                   var type = $(event.target).val();
+                   initTargetResourceIdOptions(type, formNum);
+           }
+
            $scope.changeTargetResourceId = function(event) {
                    var formNum = $(event.target).closest('.formId').attr('id').substring(6);
-                   $("#formId" + formNum +" #modelName").val("");
-                   $("#formId" + formNum +" #modelInvariantId").val("");
-                   $("#formId" + formNum +" #modelVersionId").val("");
-                   $("#formId" + formNum +" #modelVersion").val("");
-                   $("#formId" + formNum +" #modelCustomizationId").val("");
+                   initTargetModelAttributes(formNum);
+
                    var resourceVFModule = getResourceDetailsVfModuleProperty();
                    var type = $("#formId" + formNum +" #type").val();
                    var recipe = $("#formId" + formNum +" #recipe").val();