Fix issue in operational policy UI
[clamp.git] / src / main / resources / META-INF / resources / designer / partials / portfolios / PolicyWindow_properties.html
index 00e1675..7f4dafd 100644 (file)
@@ -2,7 +2,7 @@
   ============LICENSE_START=======================================================
   ONAP CLAMP
   ================================================================================
-  Copyright (C) 2017 AT&T Intellectual Property. All rights
+  Copyright (C) 2017-2018 AT&T Intellectual Property. All rights
                               reserved.
   ================================================================================
   Licensed under the Apache License, Version 2.0 (the "License"); 
@@ -18,7 +18,7 @@
   limitations under the License.
   ============LICENSE_END============================================
   ===================================================================
-  ECOMP is a trademark and service mark of AT&T Intellectual Property.
+  
   -->
 
 
@@ -286,9 +286,13 @@ label {
                                                        <label for="targetResourceId" class="col-sm-4 control-label">
                                                                Target ResourceId</label>
                                                        <div class="col-sm-8">
-                                                               <input type="text" class="form-control" id="targetResourceId"
-                                                                       name="targetResourceId"> </input>
+                                                               <select class="form-control" name="targetResourceId" id="targetResourceId" enableFilter="true" onchange="changeTargetResourceIdOther();" >
+                                                                       <option value=""></option>
+                                                                       <option value="Other:">Other:</option>
+                                                               </select>
                                                        </div>
+                                                       <input type="text" style="display:none" class="form-control" id="targetResourceIdOther"
+                                                               name="targetResourceIdOther" value=""></input>
                                                </div>
                                        </div>
                                </form>
@@ -304,6 +308,22 @@ label {
        </div>
 
        <script>
+       
+       function initTargetResourceId() {
+               // Set all the Resource Invariant UUID in the target resource ID list (+Empty and other) 
+               Object.keys(vf_Services["shared"]["byVf"]).forEach(function(key){
+                       $('#targetResourceId').append($('<option></option>').val(key).html(key));
+               });
+       }
+       
+       function changeTargetResourceIdOther() {
+               if ($("#targetResourceId").val()==="Other:") {
+                       $("#targetResourceIdOther").show();
+               } else {
+                       $("#targetResourceIdOther").hide();
+                       $("#targetResourceIdOther").val("");
+               }
+       }
                //Basically this method will add a new form. All forms share the same class. When you want one form to show(active form) the other forms get the 
                // css attribute display:none
                $("#add_one_more").click(function(event) {
@@ -334,7 +354,7 @@ label {
                        }
                }
                $("#pname").val('');            
-               
+
                //load recipes for a chosen policy
                function disperseConfig(policyObj, id){
                        parent_policy={};
@@ -360,7 +380,13 @@ label {
                                                                parent_policy[num]=el[i][j].value 
                                                        if(el[i][j].name==='recipe' && el[i][j].value.toString()!==''){
                                                                $("#go_properties_tab"+num).text(el[i][j].value)
-                                                       }       
+                                                       }
+                                                       if(el[i][j].name==="targetResourceIdOther" && el[i][j].value.toString()!=='') {
+                                                               // Add the entry and set it
+                                                               $('#targetResourceId').append($('<option></option>').val($('#targetResourceIdOther').val()).html($('#targetResourceIdOther').val()));
+                                                               $('#targetResourceId').val($('#targetResourceIdOther').val());
+                                                       }
+                                                       
                                                }
                                        }
                                }
@@ -385,16 +411,17 @@ label {
                                        $("#formId"+k+" #parentPolicy").change();
                                }
                                
+                               // Now load all component with the right value defined in policyObj JSON
                                for (headInd in policyObj[id]){
                                        if (!(policyObj[id][headInd].hasOwnProperty("policyConfigurations"))){
                                                $("#" + policyObj[id][headInd].name).val(policyObj[id][headInd].value);
                                        }
                                }
                        }
-                       
+
                        setMultiSelect();
                        
-                       if (readOnly||readMOnly){
+                       if (readMOnly){
                                $('select[multiple] option').each(function() {
                          var input = $('input[value="' + $(this).val() + '"]');
                          input.prop('disabled', true);
@@ -454,6 +481,10 @@ label {
                }
                
                $("#savePropsBtn").click(function(event) {
+                       if($("#targetResourceIdOther").is(":visible")) {
+                               $('#targetResourceId').append($('<option></option>').val($("#targetResourceIdOther").val()).html($("#targetResourceIdOther").val()))
+                               $("#targetResourceId").val($("#targetResourceIdOther").val());
+                       }
                        $(".idError").hide();
                        if ($("#policyTable .highlight td").html() !== $("#pname").val()){
                                //repeated name
@@ -483,7 +514,7 @@ label {
                                        finalSaveList[tableVal] = allPolicies[tableVal];
                                }
                        });
-                       
+
                        saveProperties(finalSaveList);
                        $("#close_button").click();
                })              
@@ -746,7 +777,7 @@ label {
                                $("#newIdError").show();
                                return;
                        }
-                       if (!(readOnly||readMOnly)){
+                       if (!(readMOnly)){
                                startNextItem();
                        } else {
                                if ($("#policyTable .highlight").length == 0){
@@ -822,7 +853,7 @@ label {
                }
                
                setASDCFields();
-               
+               initTargetResourceId();
                //load metrics dropdown
                if (elementMap["global"]){
                        for (var i = 0; i < (elementMap["global"].length); i++){
@@ -837,15 +868,6 @@ label {
                                            });
                                                }
                                                break;
-                                       } else if (asSel == "enbRecipe"){
-                                               if (vf_Services["policy"][asSel]){
-                                                       $.each((vf_Services["policy"][asSel]), function(val, text) {
-                                               $('#recipe').append(
-                                                   $('<option></option>').val(val).html(text)
-                                               );
-                                           });
-                                               }
-                                               break;
                                        }
                                };
                        };