diff --git a/src/sunstone/public/app/tabs/templates-tab/form-panels/create-common.js b/src/sunstone/public/app/tabs/templates-tab/form-panels/create-common.js index f57cf89e02..1fa615cc9e 100644 --- a/src/sunstone/public/app/tabs/templates-tab/form-panels/create-common.js +++ b/src/sunstone/public/app/tabs/templates-tab/form-panels/create-common.js @@ -166,17 +166,15 @@ define(function(require) { var templateJSON = {}; $.each(this.wizardTabs, function(index, wizardTab) { $.extend(true, templateJSON, wizardTab.retrieve($("#" + wizardTab.wizardTabId, context))); - var a = templateJSON; }); - if(templateJSON["TOPOLOGY"] && templateJSON["TOPOLOGY"]["DELETE"]){ delete templateJSON["TOPOLOGY"]; } if( templateJSON["TOPOLOGY"] && - (templateJSON["TOPOLOGY"]["HUGEPAGE_SIZE"] === undefined || + (templateJSON["TOPOLOGY"]["HUGEPAGE_SIZE"] === undefined || templateJSON["TOPOLOGY"]["HUGEPAGE_SIZE"] === null || templateJSON["TOPOLOGY"]["HUGEPAGE_SIZE"].length<=0) ){ @@ -185,7 +183,7 @@ define(function(require) { if( templateJSON["TOPOLOGY"] && - (templateJSON["TOPOLOGY"]["MEMORY_ACCESS"] === undefined || + (templateJSON["TOPOLOGY"]["MEMORY_ACCESS"] === undefined || templateJSON["TOPOLOGY"]["MEMORY_ACCESS"] === null || templateJSON["TOPOLOGY"]["MEMORY_ACCESS"].length<=0) ){ @@ -233,7 +231,7 @@ define(function(require) { delete templateJSON["NIC_PCI"]; } - + return templateJSON; } @@ -244,8 +242,8 @@ define(function(require) { if( this && - this.resourceId && - cachedTemplate && + this.resourceId && + cachedTemplate && cachedTemplate.data && Array.isArray(cachedTemplate.data) ){ @@ -253,10 +251,10 @@ define(function(require) { var currentTemplate = cachedTemplate.data.filter(function(vmtemplate) { var rtn = false; if( - vmtemplate && - vmtemplate.VMTEMPLATE && - vmtemplate.VMTEMPLATE.TEMPLATE && - vmtemplate.VMTEMPLATE.ID && + vmtemplate && + vmtemplate.VMTEMPLATE && + vmtemplate.VMTEMPLATE.TEMPLATE && + vmtemplate.VMTEMPLATE.ID && vmtemplate.VMTEMPLATE.ID === id ){ return vmtemplate.VMTEMPLATE.TEMPLATE; @@ -266,7 +264,7 @@ define(function(require) { if( currentTemplate && currentTemplate[0] && - currentTemplate[0].VMTEMPLATE && + currentTemplate[0].VMTEMPLATE && currentTemplate[0].VMTEMPLATE.TEMPLATE ){ current = currentTemplate[0].VMTEMPLATE.TEMPLATE; @@ -286,7 +284,7 @@ define(function(require) { this.create_title, this.update_title) ) return false; - + if (this.action == "create") { Sunstone.runAction(this.resource+".create", {"vmtemplate": templateJSON}); return false; @@ -329,7 +327,7 @@ define(function(require) { delete disk.OPENNEBULA_MANAGED; } } - + disks.push(disk); }); templateJSON.DISK = disks; diff --git a/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/context.js b/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/context.js index 91bdc4701c..67ffb9f3fc 100644 --- a/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/context.js +++ b/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/context.js @@ -19,48 +19,50 @@ define(function(require) { DEPENDENCIES */ - var Config = require('sunstone-config'); - var Locale = require('utils/locale'); - var Tips = require('utils/tips'); - var WizardFields = require('utils/wizard-fields'); - var TemplateUtils = require('utils/template-utils'); - var CustomTagsTable = require('utils/custom-tags-table'); - var FilesTable = require('tabs/files-tab/datatable') - var OpenNebulaHost = require('opennebula/host'); - var UserInputs = require('utils/user-inputs'); - var UniqueId = require('utils/unique-id'); - var OpenNebula = require('opennebula'); + var Config = require("sunstone-config"); + var Locale = require("utils/locale"); + var Tips = require("utils/tips"); + var WizardFields = require("utils/wizard-fields"); + var TemplateUtils = require("utils/template-utils"); + var CustomTagsTable = require("utils/custom-tags-table"); + var FilesTable = require("tabs/files-tab/datatable"); + var OpenNebulaHost = require("opennebula/host"); + var UserInputs = require("utils/user-inputs"); + var UniqueId = require("utils/unique-id"); + var OpenNebula = require("opennebula"); /* TEMPLATES */ - var TemplateHTML = require('hbs!./context/html'); + var TemplateHTML = require("hbs!./context/html"); /* CONSTANTS */ - var WIZARD_TAB_ID = require('./context/wizardTabId'); + var WIZARD_TAB_ID = require("./context/wizardTabId"); /* CONSTRUCTOR */ function WizardTab(opts) { - if (!Config.isTemplateCreationTabEnabled(opts.tabId, 'context')) { + if (!Config.isTemplateCreationTabEnabled(opts.tabId, "context")) { throw "Wizard Tab not enabled"; } this.wizardTabId = WIZARD_TAB_ID + UniqueId.id(); - this.icon = 'fa-folder'; + this.icon = "fa-folder"; this.title = Locale.tr("Context"); this.classes = "hypervisor"; + this.templateVcenterCustomizationSpec = ""; + this.customizations = []; - this.contextFilesTable = new FilesTable('ContextTable' + UniqueId.id(), { - 'select': true, - 'selectOptions': { - 'multiple_choice': true, + this.contextFilesTable = new FilesTable("ContextTable" + UniqueId.id(), { + "select": true, + "selectOptions": { + "multiple_choice": true, "filter_fn": function(file) { return file.TYPE == 5; } // CONTEXT }}); } @@ -82,10 +84,10 @@ define(function(require) { function _html() { CustomTagsTable.reset(); return TemplateHTML({ - 'uniqueId': UniqueId.id(), - 'userInputsHTML': UserInputs.html(), - 'customTagsTableHTML': CustomTagsTable.html(), - 'contextFilesTableHTML': this.contextFilesTable.dataTableHTML + "uniqueId": UniqueId.id(), + "userInputsHTML": UserInputs.html(), + "customTagsTableHTML": CustomTagsTable.html(), + "contextFilesTableHTML": this.contextFilesTable.dataTableHTML }); } @@ -114,41 +116,42 @@ define(function(require) { var option = $("option:selected", this); if (option.attr("custom") == "true"){ - $('input.vcenter_customizations_value', context).show(); + $("input.vcenter_customizations_value", context).show(); } else { - $('input.vcenter_customizations_value', context).hide(); + $("input.vcenter_customizations_value", context).hide(); } - $('input.vcenter_customizations_value', context).val( $(this).val() ); + $("input.vcenter_customizations_value", context).val( $(this).val() ); }); - $('input.vcenter_customizations_value', context).hide(); + $("input.vcenter_customizations_value", context).hide(); OpenNebulaHost.vcenterCustomizations({ data : {}, timeout: true, success: function (request, customizations){ - _fillCustomizations(context, customizations); + that.customizations = customizations; + _fillCustomizations(context, that); }, error: function(request, error_json){ console.error("There was an error requesting the vCenter customizations: "+ error_json.error.message); - - _fillCustomizations(context, []); + that.customizations = []; + _fillCustomizations(context, that); } }); context.on("change", "input.vcenter_customizations_value", function(){ var opt = - $('option'+ - '[value="'+$('input.vcenter_customizations_value', context).val()+'"]', context); + $("option"+ + "[value=\""+$("input.vcenter_customizations_value", context).val()+"\"]", context); if (opt.size() == 0){ - opt = $('option[custom="true"]', context); - $('input.vcenter_customizations_value', context).show(); + opt = $("option[custom=\"true\"]", context); + $("input.vcenter_customizations_value", context).show(); } - opt.attr('selected', 'selected'); + opt.attr("selected", "selected"); }); UserInputs.setup(context); @@ -156,41 +159,49 @@ define(function(require) { CustomTagsTable.setup(context, true); var selectOptions = { - 'selectOptions': { - 'select_callback': function(aData, options) { - that.generateContextFiles(context) + "selectOptions": { + "select_callback": function(aData, options) { + that.generateContextFiles(context); }, - 'unselect_callback': function(aData, options) { - that.generateContextFiles(context) + "unselect_callback": function(aData, options) { + that.generateContextFiles(context); } } - } + }; that.contextFilesTable.initialize(selectOptions); that.contextFilesTable.refreshResourceTableSelect(); } - function _fillCustomizations(context, customizations) { + function _fillCustomizations(context, that) { + var customizations = that.customizations; + var selectedCustom = true; var html = "'; - + html += ""; + if(Array.isArray(customizations)){ + customizations.forEach(customization => { + var selected = ""; + if(that.templateVcenterCustomizationSpec && customization.toLowerCase() === that.templateVcenterCustomizationSpec.toLowerCase()){ + selectedCustom = false; + selected = "selected"; + } + html += ""; + }); + } + var selected = selectedCustom && that.templateVcenterCustomizationSpec? "selected" : ""; + html += ""; + html += ""; $(".vcenter_customizations", context).html(html); + if(selected){ + $(".vcenter_customizations_value").val(that.templateVcenterCustomizationSpec || "").show(); + } } function _retrieve(context) { var templateJSON = {}; if($("input[name='context_type']:checked", context).val() == "context_type_vcenter"){ - var customization = WizardFields.retrieveInput($('input.vcenter_customizations_value', context)); + var customization = WizardFields.retrieveInput($("input.vcenter_customizations_value", context)); if (customization) { templateJSON = { @@ -206,7 +217,7 @@ define(function(require) { if (public_key) { contextJSON["SSH_PUBLIC_KEY"] = public_key; } else { - contextJSON["SSH_PUBLIC_KEY"] = '$USER[SSH_PUBLIC_KEY]'; + contextJSON["SSH_PUBLIC_KEY"] = "$USER[SSH_PUBLIC_KEY]"; } } @@ -240,9 +251,9 @@ define(function(require) { } } - if (!$.isEmptyObject(contextJSON)) { templateJSON['CONTEXT'] = contextJSON; }; - if (!$.isEmptyObject(userInputsJSON)) { templateJSON['USER_INPUTS'] = userInputsJSON; }; - templateJSON['INPUTS_ORDER'] = userInputsOrder; + if (!$.isEmptyObject(contextJSON)) { templateJSON["CONTEXT"] = contextJSON; }; + if (!$.isEmptyObject(userInputsJSON)) { templateJSON["USER_INPUTS"] = userInputsJSON; }; + templateJSON["INPUTS_ORDER"] = userInputsOrder; } return templateJSON; @@ -251,8 +262,10 @@ define(function(require) { function _fill(context, templateJSON) { var that = this; - var contextJSON = templateJSON['CONTEXT']; - var userInputsJSON = templateJSON['USER_INPUTS']; + that.templateVcenterCustomizationSpec = templateJSON && templateJSON.VCENTER_CUSTOMIZATION_SPEC; + _fillCustomizations(context, that); + var contextJSON = templateJSON["CONTEXT"]; + var userInputsJSON = templateJSON["USER_INPUTS"]; var publicClouds = templateJSON["PUBLIC_CLOUD"]; if (publicClouds != undefined) { @@ -265,7 +278,7 @@ define(function(require) { $("input#context_type_vcenter", context).click(); if(this["VCENTER_CUSTOMIZATION_SPEC"]){ - WizardFields.fillInput($('input.vcenter_customizations_value', context), this["VCENTER_CUSTOMIZATION_SPEC"]); + WizardFields.fillInput($("input.vcenter_customizations_value", context), this["VCENTER_CUSTOMIZATION_SPEC"]); } else if(userInputsJSON || contextJSON) { $("input#context_type_opennebula", context).click(); } @@ -275,8 +288,8 @@ define(function(require) { }); } - $(".ssh_context", context).removeAttr('checked'); - $(".network_context", context).removeAttr('checked'); + $(".ssh_context", context).removeAttr("checked"); + $(".network_context", context).removeAttr("checked"); if (userInputsJSON) { UserInputs.fill(context, templateJSON); @@ -287,8 +300,8 @@ define(function(require) { }); } - delete templateJSON['USER_INPUTS']; - delete templateJSON['INPUTS_ORDER']; + delete templateJSON["USER_INPUTS"]; + delete templateJSON["INPUTS_ORDER"]; } if (contextJSON) { @@ -305,21 +318,21 @@ define(function(require) { var customTagsJSON = {}; $.each(contextJSON, function(key, value) { if (ssh_regexp.test(key)) { - $(".ssh_context", context).prop('checked', 'checked'); + $(".ssh_context", context).prop("checked", "checked"); if (!publickey_regexp.test(value)) { WizardFields.fillInput($("#ssh_public_key", context), value); } } else if (token_regexp.test(key) && yes_value.test(value)) { - $(".token_context", context).prop('checked', 'checked'); + $(".token_context", context).prop("checked", "checked"); } else if (report_ready_regexp.test(key) && yes_value.test(value)) { - $(".report_ready_context", context).prop('checked', 'checked'); + $(".report_ready_context", context).prop("checked", "checked"); } else if (net_regexp.test(key) && yes_value.test(value)) { - $(".network_context", context).prop('checked', 'checked'); + $(".network_context", context).prop("checked", "checked"); } else if ("INIT_SCRIPTS" == key) { WizardFields.fillInput($("input.INIT_SCRIPTS", context), value); } else if ("FILES_DS" == key) { - WizardFields.fillInput($('.FILES_DS', context), contextJSON["FILES_DS"]); + WizardFields.fillInput($(".FILES_DS", context), contextJSON["FILES_DS"]); var files = []; OpenNebula.Image.list({ timeout: true, @@ -335,13 +348,13 @@ define(function(require) { } var selectedResources = { ids : files - } + }; that.contextFilesTable.selectResourceTableSelect(selectedResources); } }); } else if ("START_SCRIPT_BASE64" == key) { - $(".ENCODE_START_SCRIPT", context).prop('checked', 'checked'); + $(".ENCODE_START_SCRIPT", context).prop("checked", "checked"); $(".START_SCRIPT", context).val(decodeURIComponent(escape(window.atob(value)))); } else if ("START_SCRIPT" == key) { WizardFields.fillInput($(".START_SCRIPT", context), value); @@ -352,7 +365,7 @@ define(function(require) { CustomTagsTable.fill(context, customTagsJSON); - delete templateJSON['CONTEXT']; + delete templateJSON["CONTEXT"]; } } @@ -367,13 +380,13 @@ define(function(require) { id: fileId }, success: function(request, obj_file){ - req_string.push("$FILE[IMAGE=" + '"' + obj_file.IMAGE.NAME + '"' + ", IMAGE_UNAME=" + '"' + obj_file.IMAGE.UNAME + '"]'); - $('.FILES_DS', context).val(req_string.join(" ")); + req_string.push("$FILE[IMAGE=" + "\"" + obj_file.IMAGE.NAME + "\"" + ", IMAGE_UNAME=" + "\"" + obj_file.IMAGE.UNAME + "\"]"); + $(".FILES_DS", context).val(req_string.join(" ")); } }); }); } else { - $('.FILES_DS', context).val(""); + $(".FILES_DS", context).val(""); } }; }); diff --git a/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/other.js b/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/other.js index 418ef0fa7a..fc1a3b212a 100644 --- a/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/other.js +++ b/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/other.js @@ -19,38 +19,38 @@ define(function(require) { DEPENDENCIES */ - var Config = require('sunstone-config'); - var Locale = require('utils/locale'); - var Tips = require('utils/tips'); - var WizardFields = require('utils/wizard-fields'); - var TemplateUtils = require('utils/template-utils'); - var CustomTagsTable = require('utils/custom-tags-table'); - var OpenNebulaHost = require('opennebula/host'); - var UniqueId = require('utils/unique-id'); + var Config = require("sunstone-config"); + var Locale = require("utils/locale"); + var Tips = require("utils/tips"); + var WizardFields = require("utils/wizard-fields"); + var TemplateUtils = require("utils/template-utils"); + var CustomTagsTable = require("utils/custom-tags-table"); + var OpenNebulaHost = require("opennebula/host"); + var UniqueId = require("utils/unique-id"); /* TEMPLATES */ - var TemplateHTML = require('hbs!./other/html'); + var TemplateHTML = require("hbs!./other/html"); /* CONSTANTS */ - var WIZARD_TAB_ID = require('./other/wizardTabId'); + var WIZARD_TAB_ID = require("./other/wizardTabId"); /* CONSTRUCTOR */ function WizardTab(opts) { - if (!Config.isTemplateCreationTabEnabled(opts.tabId, 'other')) { + if (!Config.isTemplateCreationTabEnabled(opts.tabId, "other")) { throw "Wizard Tab not enabled"; } this.wizardTabId = WIZARD_TAB_ID + UniqueId.id(); - this.icon = 'fa-tag'; + this.icon = "fa-tag"; this.title = Locale.tr("Tags"); } @@ -69,7 +69,7 @@ define(function(require) { function _html() { return TemplateHTML({ - 'customTagsTableHTML': CustomTagsTable.html() + "customTagsTableHTML": CustomTagsTable.html() }); } @@ -84,19 +84,19 @@ define(function(require) { var templateJSON = CustomTagsTable.retrieve(context); var rawJSON = {}; - var rawData = WizardFields.retrieveInput($('.raw_data', context)); + var rawData = WizardFields.retrieveInput($(".raw_data", context)); if (rawData != "") { - rawJSON['DATA'] = rawData; + rawJSON["DATA"] = rawData; - var rawType = $('.raw_type', context).val(); + var rawType = $(".raw_type", context).val(); if (rawType != undefined) { - rawJSON['TYPE'] = rawType; + rawJSON["TYPE"] = rawType; } - rawJSON['VALIDATE'] = $("#raw_validate", context).is(":checked") ? 'YES' : 'NO'; + rawJSON["VALIDATE"] = $("#raw_validate", context).is(":checked") ? "YES" : "NO"; } - if (!$.isEmptyObject(rawJSON)) { templateJSON['RAW'] = rawJSON; }; + if (!$.isEmptyObject(rawJSON)) { templateJSON["RAW"] = rawJSON; }; return templateJSON; } @@ -104,18 +104,17 @@ define(function(require) { function _fill(context, templateJSON) { var rawJSON = templateJSON.RAW; if (rawJSON) { - $('.raw_type', context).val(rawJSON['TYPE']); - $('.raw_type', context).change(); + $(".raw_type", context).val(rawJSON["TYPE"]); + $(".raw_type", context).change(); - WizardFields.fillInput($('.raw_data', context), rawJSON['DATA']); + WizardFields.fillInput($(".raw_data", context), rawJSON["DATA"]); - if (['yes', 'YES'].includes(rawJSON['VALIDATE'])) { - $("#raw_validate", context).prop('checked', 'checked'); + if (["yes", "YES"].includes(rawJSON["VALIDATE"])) { + $("#raw_validate", context).prop("checked", "checked"); } delete templateJSON.RAW; } - CustomTagsTable.fill(context, templateJSON); } }); diff --git a/src/sunstone/public/app/utils/common-actions.js b/src/sunstone/public/app/utils/common-actions.js index 106cba4539..deb79da178 100644 --- a/src/sunstone/public/app/utils/common-actions.js +++ b/src/sunstone/public/app/utils/common-actions.js @@ -197,6 +197,7 @@ define(function(require) { function(formPanelInstance, context) { if (that.xmlRoot) { formPanelInstance.fill(context, response[that.xmlRoot]); + } else { formPanelInstance.fill(context, response); } diff --git a/src/sunstone/public/app/utils/custom-tags-table.js b/src/sunstone/public/app/utils/custom-tags-table.js index 366a72faf6..8ad187ef25 100644 --- a/src/sunstone/public/app/utils/custom-tags-table.js +++ b/src/sunstone/public/app/utils/custom-tags-table.js @@ -16,18 +16,19 @@ define(function(require) { - var Locale = require('utils/locale'); - var TemplateHTML = require('hbs!./custom-tags-table/html'); - var RowTemplateHTML = require('hbs!./custom-tags-table/row'); - var VectorRowTemplateHTML = require('hbs!./custom-tags-table/vector-row'); - var VectorAttributeRowTemplateHTML = require('hbs!./custom-tags-table/vector-attribute-row'); - var TemplateUtils = require('utils/template-utils'); - var WizardFields = require('utils/wizard-fields'); - var Sunstone = require('sunstone'); + var Locale = require("utils/locale"); + var TemplateHTML = require("hbs!./custom-tags-table/html"); + var RowTemplateHTML = require("hbs!./custom-tags-table/row"); + var VectorRowTemplateHTML = require("hbs!./custom-tags-table/vector-row"); + var VectorAttributeRowTemplateHTML = require("hbs!./custom-tags-table/vector-attribute-row"); + var TemplateUtils = require("utils/template-utils"); + var WizardFields = require("utils/wizard-fields"); + var Sunstone = require("sunstone"); var removedStyles = false; var showMandatory = false; var showDefault = false; + var deleteTags = ["VCENTER_CUSTOMIZATION_SPEC"]; function _reset(){ showDefault = false; @@ -35,8 +36,8 @@ define(function(require) { } function _html(classTable, classButton, removeStyles, mandatory, deflt){ - var classTableName = classTable && classTable.length>0 ? classTable : ''; - var classButtonName = classButton && classButton.length>0 ? classButton : ''; + var classTableName = classTable && classTable.length>0 ? classTable : ""; + var classButtonName = classButton && classButton.length>0 ? classButton : ""; if(mandatory){ showMandatory = true; } @@ -48,12 +49,12 @@ define(function(require) { } return TemplateHTML({ - 'titleKey': Locale.tr("Name"), - 'titleMandatory': showMandatory ? Locale.tr("Type") : '', - 'titleValue': Locale.tr("Value"), - 'titleDefault': showDefault? Locale.tr("Default Value"): '', - 'classTable': classTableName, - 'classButton': classButtonName + "titleKey": Locale.tr("Name"), + "titleMandatory": showMandatory ? Locale.tr("Type") : "", + "titleValue": Locale.tr("Value"), + "titleDefault": showDefault? Locale.tr("Default Value"): "", + "classTable": classTableName, + "classButton": classButtonName }); } @@ -66,8 +67,8 @@ define(function(require) { $("tbody.custom_tags", context).append( RowTemplateHTML({ styles: !removedStyles, - mandatory: showMandatory? 'M' : '', - valueDefault: showDefault? ' ' : '' + mandatory: showMandatory? "M" : "", + valueDefault: showDefault? " " : "" }) ); if(hide_vector_button){ @@ -79,7 +80,7 @@ define(function(require) { } if(element && element.CAPACITY){ element.CAPACITY[key] = this.value; - Sunstone.runAction(resourceType+".update_template",elementID, TemplateUtils.templateToString(element)); + Sunstone.runAction(resourceType+".update_template",elementID, TemplateUtils.templateToString(element)); } }); } @@ -96,29 +97,29 @@ define(function(require) { context.off("click", ".add_vector_attribute"); context.on("click", ".add_vector_attribute", function(){ - var tbody = $("tbody.custom_vector_attributes", $(this).closest('table')); + var tbody = $("tbody.custom_vector_attributes", $(this).closest("table")); tbody.append(VectorAttributeRowTemplateHTML()); }); context.off("click", ".change_to_vector_attribute"); context.on("click", ".change_to_vector_attribute", function(){ - var td = $($(this).closest('table')).parent(); + var td = $($(this).closest("table")).parent(); var tr = $(td).parent(); - $('.change_to_vector_attribute', td).addClass('add_vector_attribute').removeClass('change_to_vector_attribute'); - $('tbody.custom_body', td).addClass('custom_vector_attributes').removeClass('custom_body'); - $('.custom_tag_key', tr).addClass('custom_vector_key').removeClass('custom_tag_key').css('margin-top', '5px'); - $('tbody.custom_vector_attributes', td).append(VectorAttributeRowTemplateHTML({ - key: $('textarea.custom_tag_value', td).val() + $(".change_to_vector_attribute", td).addClass("add_vector_attribute").removeClass("change_to_vector_attribute"); + $("tbody.custom_body", td).addClass("custom_vector_attributes").removeClass("custom_body"); + $(".custom_tag_key", tr).addClass("custom_vector_key").removeClass("custom_tag_key").css("margin-top", "5px"); + $("tbody.custom_vector_attributes", td).append(VectorAttributeRowTemplateHTML({ + key: $("textarea.custom_tag_value", td).val() })); - $('textarea.custom_tag_value', td).remove(); + $("textarea.custom_tag_value", td).remove(); }); $(".add_custom_tag", context).trigger("click"); context.on("click", "tbody.custom_tags i.remove-tab", function(){ - var tr = $(this).closest('tr'); + var tr = $(this).closest("tr"); tr.remove(); if(hide_vector_button){ - var key = $(".custom_tag_key",this.parentElement.parentElement.parentElement).val() + var key = $(".custom_tag_key",this.parentElement.parentElement.parentElement).val(); if(element && element.CAPACITY && element.CAPACITY[key] && elementID){ delete element.CAPACITY[key]; Sunstone.runAction(resourceType+".update_template",elementID, TemplateUtils.templateToString(element)); @@ -130,24 +131,24 @@ define(function(require) { // context is the container div of customTagsHtml() function _retrieveCustomTags(context){ var template_json = {}; - $('tbody.custom_tags tr', context).each(function(){ - if ($('.custom_tag_key', $(this)).val()) { - var key = WizardFields.retrieveInput($('.custom_tag_key', $(this))); - template_json[key] = WizardFields.retrieveInput($('.custom_tag_value', $(this))); + $("tbody.custom_tags tr", context).each(function(){ + if ($(".custom_tag_key", $(this)).val()) { + var key = WizardFields.retrieveInput($(".custom_tag_key", $(this))); + template_json[key] = WizardFields.retrieveInput($(".custom_tag_value", $(this))); } - if ($('.custom_vector_key', $(this)).val()) { + if ($(".custom_vector_key", $(this)).val()) { var vectorAttributes = {}; - $('tbody.custom_vector_attributes tr', $(this)).each(function(){ - var key = WizardFields.retrieveInput($('.custom_vector_attribute_key', $(this))); + $("tbody.custom_vector_attributes tr", $(this)).each(function(){ + var key = WizardFields.retrieveInput($(".custom_vector_attribute_key", $(this))); if (key) { - vectorAttributes[key] = WizardFields.retrieveInput($('.custom_vector_attribute_value', $(this))); + vectorAttributes[key] = WizardFields.retrieveInput($(".custom_vector_attribute_value", $(this))); } }); if (!$.isEmptyObject(vectorAttributes)){ - var key = WizardFields.retrieveInput($('.custom_vector_key', $(this))); + var key = WizardFields.retrieveInput($(".custom_vector_key", $(this))); template_json[key] = vectorAttributes; } } @@ -158,10 +159,18 @@ define(function(require) { // context is the container div of customTagsHtml() // template_json are the key:values that will be put into the table - function _fillCustomTags(context, template_json){ + function _fillCustomTags(context, templateJson){ $("tbody.custom_tags i.remove-tab", context).trigger("click"); + + var template_json = $.extend({}, templateJson); + + //remove tags + deleteTags.forEach(element => { + delete template_json[element]; + }); + $.each(template_json, function(key, value){ - if (typeof value == 'object') { + if (typeof value === "object") { $("tbody.custom_tags", context).append( VectorRowTemplateHTML({key: key, value: value}) ); @@ -171,8 +180,8 @@ define(function(require) { RowTemplateHTML({ key: key, value: val, - mandatory: showMandatory ? 'M': '', - valueDefault: showDefault? ' ': '' + mandatory: showMandatory ? "M": "", + valueDefault: showDefault? " ": "" }) ); } @@ -180,10 +189,10 @@ define(function(require) { } return { - 'html': _html, - 'setup': _setup, - 'retrieve': _retrieveCustomTags, - 'fill': _fillCustomTags, - 'reset': _reset + "html": _html, + "setup": _setup, + "retrieve": _retrieveCustomTags, + "fill": _fillCustomTags, + "reset": _reset }; });