- // load recipes for a chosen policy
- function disperseConfig(policyObj, id) {
-
- console.log("disperseConfig with id:" + id);
- parent_policy = {};
- // remove old gui forms
- for (var i = 1; i < ($(".formId").length + 1); i++) {
- $("#go_properties_tab" + i).parent().remove();
- }
- $(".formId").remove();
- if (policyObj !== undefined && policyObj[id] !== undefined) {
- var el = policyObj[id][3]['policyConfigurations']
- for (var i = 0; i < el.length; i++) {
- loadingId = true;
- var num = add_one_more();
- console.log("number is=:" + num);
- loadingId = false;
- for (var j = 0; j < el[i].length; j++) {
- console.log("attr:" + el[i][j].name + "; value is:" + el[i][j].value);
- if (el[i][j].hasOwnProperty("name")) {
- $("#formId" + num + " #" + el[i][j].name).val(el[i][j].value);
- if (el[i][j].name === "_id") {
- console.log("formId num:" + num + "; value is:" + el[i][j].value);
- policy_ids["#formId" + num] = el[i][j].value
- }
- if (el[i][j].name === 'parentPolicy')
- 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
- $("#formId" + num + " #targetResourceId").append(
- $('<option></option>').val($("#formId" + num + " #targetResourceIdOther").val()).html(
- $("#formId" + num + " #targetResourceIdOther").val()));
- $("#formId" + num + " #targetResourceId").val(
- $("#formId" + num + " #targetResourceIdOther").val());
- }
- $scope.changeGuardPolicyType();
- }
- }
- }
- // Adding all the ids for parent policy options
- for (var i = 1; i <= $(".formId").length; i++) {
- for (k in policy_ids) {
- if ($("#formId" + i + " #_id").val() !== policy_ids[k].toString()
- && $(k + " #recipe").val() !== undefined && $(k + " #recipe").val() !== "") {
- $("#formId" + i + " #parentPolicy").append(
- "<option value=\"" + policy_ids[k] + "\">" + $(k + " #recipe").val() + "</option>");
- }
- }
- }
- for (k in parent_policy) {
- $("#formId" + k + " #parentPolicy").val(parent_policy[k]);
- if ($("#formId" + k + " #parentPolicy").val() == "") {
- $("#formId" + k + " #parentPolicyConditions").multiselect("disable");
- } else {
- $("#formId" + k + " #parentPolicyConditions").multiselect("enable");
- }
- // force the change event
- $("#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 (readMOnly) {
- $('select[multiple] option').each(function() {
-
- var input = $('input[value="' + $(this).val() + '"]');
- input.prop('disabled', true);
- input.parent('li').addClass('disabled');
- });
- $('input[value="multiselect-all"]').prop('disabled', true).parent('li').addClass('disabled');
- }
- }
- function addSelectListen(count) {
-
- var onSelectChange = function() {
-
- var opselected = this.selectedOptions[0].text;
- if (this.id == "recipe") {
- if (opselected !== "") {
- var polCount = $(this).closest("[id^='formId']").attr("id").substring(6);
- $(this).closest(".policyPanel").find("#go_properties_tab" + polCount).text(opselected);
- } else {
- $(this).closest("[id^='go_properties_tab']").text("Policy");
- }
- }
- if (this.id == "parentPolicy") {
- var ppCond = $(this).closest("[id^='formId']").find("#parentPolicyConditions");
- if (opselected == "") {
- ppCond.multiselect("clearSelection");
- ppCond.multiselect("disable");
- } else {
- ppCond.multiselect("enable");
- }
- }
- };
- $("#formId" + count + " select").each(function() {
-
- this.change = onSelectChange;
- });
- }
- // This is ensure there are no repeated keys in the map
- function noRepeats(form) {
-
- // triggered per policy.
- var select = {};
- for (var i = 0; i < form.length; i++) {
- if (select[form[i].name] === undefined)
- select[form[i].name] = []
- select[form[i].name].push(form[i].value);
- }
- var arr = []
- for (s in select) {
- var f = {}
- f.name = s
- f.value = select[s]
- arr.push(f)
- }
- return arr
- }