diff --git a/src/sunstone/public/app/tabs/files-tab/form-panels/create.js b/src/sunstone/public/app/tabs/files-tab/form-panels/create.js index 1d287ede59..50612d35d4 100644 --- a/src/sunstone/public/app/tabs/files-tab/form-panels/create.js +++ b/src/sunstone/public/app/tabs/files-tab/form-panels/create.js @@ -29,6 +29,7 @@ define(function(require) { var ResourceSelect = require('utils/resource-select'); var BrowserInfo = require('utils/browser-info'); var OpenNebulaDatastore = require('opennebula/datastore'); + var WizardFields = require('utils/wizard-fields'); var TemplateWizardHTML = require('hbs!./create/wizard'); var TemplateAdvancedHTML = require('hbs!./create/advanced'); @@ -199,20 +200,20 @@ define(function(require) { var img_json = {}; - var name = $('#file_name', context).val(); + var name = WizardFields.retrieveInput($('#file_name', context)); img_json["NAME"] = name; - var desc = $('#file_desc', context).val(); + var desc = WizardFields.retrieveInput($('#file_desc', context)); if (desc.length) { img_json["DESCRIPTION"] = desc; } - var type = $('#file_type', context).val(); + var type = WizardFields.retrieveInput($('#file_type', context)); img_json["TYPE"] = type; switch ($('#src_path_select input:checked', context).val()){ case "path": - path = $('#file_path', context).val(); + path = WizardFields.retrieveInput($('#file_path', context)); if (path) img_json["PATH"] = path; break; case "upload": diff --git a/src/sunstone/public/app/tabs/hosts-tab/form-panels/create.js b/src/sunstone/public/app/tabs/hosts-tab/form-panels/create.js index 37dfff988c..40e93419c3 100644 --- a/src/sunstone/public/app/tabs/hosts-tab/form-panels/create.js +++ b/src/sunstone/public/app/tabs/hosts-tab/form-panels/create.js @@ -205,7 +205,7 @@ define(function(require) { } function _submitWizard(context) { - var name = $('#name', context).val(); + var name = WizardFields.retrieveInput($('#name', context)); if (!name) { Sunstone.hideFormPanelLoading(this.tabId); Notifier.notifyError(Locale.tr("Host name missing!")); @@ -216,9 +216,9 @@ define(function(require) { if (!cluster_id) cluster_id = "-1"; var vmm_mad = $('select#vmm_mad', context).val(); - vmm_mad = vmm_mad == "custom" ? $('input[name="custom_vmm_mad"]').val() : vmm_mad; + vmm_mad = vmm_mad == "custom" ? WizardFields.retrieveInput($('input[name="custom_vmm_mad"]')) : vmm_mad; var im_mad = $('select#im_mad', context).val(); - im_mad = im_mad == "custom" ? $('input[name="custom_im_mad"]').val() : im_mad; + im_mad = im_mad == "custom" ? WizardFields.retrieveInput($('input[name="custom_im_mad"]')) : im_mad; var host_json = { "host": { diff --git a/src/sunstone/public/app/tabs/images-tab/form-panels/create.js b/src/sunstone/public/app/tabs/images-tab/form-panels/create.js index 1ef9823deb..0febb4e05f 100644 --- a/src/sunstone/public/app/tabs/images-tab/form-panels/create.js +++ b/src/sunstone/public/app/tabs/images-tab/form-panels/create.js @@ -31,6 +31,7 @@ define(function(require) { var CustomTagsTable = require('utils/custom-tags-table'); var BrowserInfo = require('utils/browser-info'); var Config = require('sunstone-config'); + var WizardFields = require('utils/wizard-fields'); var TemplateWizardHTML = require('hbs!./create/wizard'); var TemplateAdvancedHTML = require('hbs!./create/advanced'); @@ -265,48 +266,48 @@ define(function(require) { var img_json = {}; - var name = $('#img_name', context).val(); + var name = WizardFields.retrieveInput($('#img_name', context)); img_json["NAME"] = name; - var desc = $('#img_desc', context).val(); + var desc = WizardFields.retrieveInput($('#img_desc', context)); if (desc.length) { img_json["DESCRIPTION"] = desc; } - var type = $('#img_type', context).val(); + var type = WizardFields.retrieveInput($('#img_type', context)); img_json["TYPE"] = type; img_json["PERSISTENT"] = $('#img_persistent:checked', context).length ? "YES" : "NO"; - var dev_prefix = $('#img_dev_prefix', context).val(); + var dev_prefix = WizardFields.retrieveInput($('#img_dev_prefix', context)); if (dev_prefix.length) { img_json["DEV_PREFIX"] = dev_prefix; } - var driver = $('#img_driver', context).val(); + var driver = WizardFields.retrieveInput($('#img_driver', context)); if (driver.length) img_json["DRIVER"] = driver; - var target = $('#img_target', context).val(); + var target = WizardFields.retrieveInput($('#img_target', context)); if (target) img_json["TARGET"] = target; - var adapter_type = $('#adapter_type', context).val(); + var adapter_type = WizardFields.retrieveInput($('#adapter_type', context)); if (adapter_type) img_json["ADAPTER_TYPE"] = adapter_type; - var disk_type = $('#disk_type', context).val(); + var disk_type = WizardFields.retrieveInput($('#disk_type', context)); if (disk_type) img_json["DISK_TYPE"] = disk_type; switch ($('#src_path_select input:checked', context).val()){ case "path": - path = $('#img_path', context).val(); + path = WizardFields.retrieveInput($('#img_path', context)); if (path) img_json["PATH"] = path; break; case "datablock": - size = $('#img_size', context).val(); - fstype = $('#img_fstype', context).val(); + size = WizardFields.retrieveInput($('#img_size', context)); + fstype = WizardFields.retrieveInput($('#img_fstype', context)); if (size) img_json["SIZE"] = size; if (fstype) img_json["FSTYPE"] = fstype; break; diff --git a/src/sunstone/public/app/tabs/marketplaceapps-tab/form-panels/create.js b/src/sunstone/public/app/tabs/marketplaceapps-tab/form-panels/create.js index 9e42608937..236ee4729c 100644 --- a/src/sunstone/public/app/tabs/marketplaceapps-tab/form-panels/create.js +++ b/src/sunstone/public/app/tabs/marketplaceapps-tab/form-panels/create.js @@ -183,16 +183,6 @@ define(function(require) { var marketPlaceJSON = {}; $.extend(marketPlaceJSON, WizardFields.retrieve(context)); - var vmTemplate = $('#VMTEMPLATE', context).val(); - if (vmTemplate) { - marketPlaceJSON['VMTEMPLATE64'] = btoa(vmTemplate); - } - - var appTemplate = $('#APPTEMPLATE', context).val(); - if (appTemplate) { - marketPlaceJSON['APPTEMPLATE64'] = btoa(appTemplate); - } - var marketPlaceAppObj = { "marketplaceapp" : marketPlaceJSON, "mp_id" : this.marketPlacesTable.idInput().val() diff --git a/src/sunstone/public/app/tabs/marketplaceapps-tab/form-panels/create/wizard.hbs b/src/sunstone/public/app/tabs/marketplaceapps-tab/form-panels/create/wizard.hbs index f4f158da0c..9992e62c55 100644 --- a/src/sunstone/public/app/tabs/marketplaceapps-tab/form-panels/create/wizard.hbs +++ b/src/sunstone/public/app/tabs/marketplaceapps-tab/form-panels/create/wizard.hbs @@ -69,7 +69,7 @@ {{tr "VM Template"}} - +
- +
\ No newline at end of file diff --git a/src/sunstone/public/app/tabs/marketplaces-tab/form-panels/create.js b/src/sunstone/public/app/tabs/marketplaces-tab/form-panels/create.js index f1457a8154..b56b6fea0d 100644 --- a/src/sunstone/public/app/tabs/marketplaces-tab/form-panels/create.js +++ b/src/sunstone/public/app/tabs/marketplaces-tab/form-panels/create.js @@ -195,11 +195,16 @@ define(function(require) { this.resourceId = element.ID; + // Populates the Avanced mode Tab + $('#template', context).val(TemplateUtils.templateToEditor(element.TEMPLATE)); + WizardFields.fill(context, element.TEMPLATE); - $('#NAME', context).val(element.NAME). - prop("disabled", true). - prop('wizard_field_disabled', true);; - $('#MARKET_MAD', context).val(element.MARKET_MAD).change(); + + WizardFields.fillInput($('#NAME', context), element.NAME); + $('#NAME', context).prop("disabled", true).prop('wizard_field_disabled', true); + + WizardFields.fillInput($('#MARKET_MAD', context), element.MARKET_MAD); + $('#MARKET_MAD', context).change(); } // Set up the create datastore dialog @@ -242,7 +247,7 @@ define(function(require) { }; Sunstone.runAction("MarketPlace.create", marketObj); } else if (this.action == "update") { - Sunstone.runAction("Network.update", this.resourceId, template); + Sunstone.runAction("MarketPlace.update", this.resourceId, template); return false; } diff --git a/src/sunstone/public/app/tabs/secgroups-tab/form-panels/create.js b/src/sunstone/public/app/tabs/secgroups-tab/form-panels/create.js index 193c86bd5e..7704f8fdf0 100644 --- a/src/sunstone/public/app/tabs/secgroups-tab/form-panels/create.js +++ b/src/sunstone/public/app/tabs/secgroups-tab/form-panels/create.js @@ -173,14 +173,14 @@ define(function(require) { }) .on('formvalid.zf.abide', function(ev, frm) { var rule = {}; - rule["PROTOCOL"] = $(".security_group_rule_protocol", context).val(); - rule["RULE_TYPE"] = $(".security_group_rule_type", context).val(); + rule["PROTOCOL"] = WizardFields.retrieveInput($(".security_group_rule_protocol", context)); + rule["RULE_TYPE"] = WizardFields.retrieveInput($(".security_group_rule_type", context)); switch ($('.security_group_rule_range_sel', context).val()) { case "ALL": break; case "RANGE": - rule["RANGE"] = $(".security_group_rule_range input", context).val(); + rule["RANGE"] = WizardFields.retrieveInput($(".security_group_rule_range input", context)); break; } @@ -188,8 +188,8 @@ define(function(require) { case "ANY": break; case "NETWORK": - rule["IP"] = $('#security_group_rule_first_ip', context).val(); - rule["SIZE"] = $('#security_group_rule_size', context).val(); + rule["IP"] = WizardFields.retrieveInput($('#security_group_rule_first_ip', context)); + rule["SIZE"] = WizardFields.retrieveInput($('#security_group_rule_size', context)); break; case "VNET": rule["NETWORK_ID"] = that.vnetsTable.retrieveResourceTableSelect(); @@ -197,7 +197,7 @@ define(function(require) { } if (rule["PROTOCOL"] == "ICMP" ){ - var icmp_type_val = $(".security_group_rule_icmp_type", context).val(); + var icmp_type_val = WizardFields.retrieveInput($(".security_group_rule_icmp_type", context)); if (icmp_type_val != ""){ rule["ICMP_TYPE"] = icmp_type_val; @@ -254,8 +254,8 @@ define(function(require) { function _submitWizard(context) { - var name = $('#security_group_name', context).val(); - var description = $('#security_group_description', context).val(); + var name = WizardFields.retrieveInput($('#security_group_name', context)); + var description = WizardFields.retrieveInput($('#security_group_description', context)); var rules = []; @@ -311,14 +311,12 @@ define(function(require) { this.resourceId = element.ID; // Populates the Avanced mode Tab - $('#template', context).val(TemplateUtils.templateToString(element.TEMPLATE).replace(/^[\r\n]+$/g, "")); + $('#template', context).val(TemplateUtils.templateToEditor(element.TEMPLATE)); - $('#security_group_name',context).val( - TemplateUtils.escapeDoubleQuotes(TemplateUtils.htmlDecode( element.NAME ))). - prop("disabled", true); + WizardFields.fillInput($('#security_group_name',context), element.NAME); + $('#security_group_name',context).prop("disabled", true); - $('#security_group_description', context).val( - TemplateUtils.escapeDoubleQuotes(TemplateUtils.htmlDecode( element.TEMPLATE.DESCRIPTION )) ); + WizardFields.fillInput($('#security_group_description', context), element.TEMPLATE.DESCRIPTION ); var rules = element.TEMPLATE.RULE; diff --git a/src/sunstone/public/app/tabs/templates-tab/form-panels/create.js b/src/sunstone/public/app/tabs/templates-tab/form-panels/create.js index db9f0e3390..79e4e98115 100644 --- a/src/sunstone/public/app/tabs/templates-tab/form-panels/create.js +++ b/src/sunstone/public/app/tabs/templates-tab/form-panels/create.js @@ -190,8 +190,7 @@ define(function(require) { var templateJSON = element.TEMPLATE; // Populates the Avanced mode Tab - $('#template', context).val( - TemplateUtils.templateToString(templateJSON).replace(/^[\r\n]+$/g, "")); + $('#template', context).val(TemplateUtils.templateToEditor(templateJSON)); $.each(this.wizardTabs, function(index, wizardTab) { wizardTab.fill($('#' + wizardTab.wizardTabId, context), templateJSON); 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 267cd6d8c3..be198a45e2 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 @@ -187,7 +187,7 @@ define(function(require) { var templateJSON = {}; if($("input[name='context_type']:checked", context).val() == "context_type_vcenter"){ - var customization = $('input.vcenter_customizations_value', context).val(); + var customization = WizardFields.retrieveInput($('input.vcenter_customizations_value', context)); if (customization) { templateJSON["VCENTER_PUBLIC_CLOUD"] = { @@ -199,9 +199,9 @@ define(function(require) { $.extend(contextJSON, CustomTagsTable.retrieve(context)); if ($(".ssh_context", context).is(":checked")) { - var public_key = $("#ssh_public_key", context).val(); + var public_key = WizardFields.retrieveInput($("#ssh_public_key", context)); if (public_key) { - contextJSON["SSH_PUBLIC_KEY"] = TemplateUtils.escapeDoubleQuotes(public_key); + contextJSON["SSH_PUBLIC_KEY"] = public_key; } else { contextJSON["SSH_PUBLIC_KEY"] = '$USER[SSH_PUBLIC_KEY]'; } @@ -222,10 +222,10 @@ define(function(require) { contextJSON[name] = "$" + name; }); - var start_script = $(".START_SCRIPT", context).val(); + var start_script = WizardFields.retrieveInput($(".START_SCRIPT", context)); if (start_script != "") { if ($(".ENCODE_START_SCRIPT", context).is(":checked")) { - contextJSON["START_SCRIPT_BASE64"] = btoa(start_script); + contextJSON["START_SCRIPT_BASE64"] = btoa($(".START_SCRIPT", context).val()); } else { contextJSON["START_SCRIPT"] = start_script; } @@ -255,7 +255,7 @@ define(function(require) { $("input#context_type_vcenter", context).click(); if(this["CUSTOMIZATION_SPEC"]){ - $('input.vcenter_customizations_value', context).val(this["CUSTOMIZATION_SPEC"]).change(); + WizardFields.fillInput($('input.vcenter_customizations_value', context), this["CUSTOMIZATION_SPEC"]); } else if(userInputsJSON || contextJSON) { $("input#context_type_opennebula", context).click(); } @@ -296,16 +296,16 @@ define(function(require) { $(".ssh_context", context).prop('checked', 'checked'); if (!publickey_regexp.test(value)) { - $("#ssh_public_key", context).val(TemplateUtils.htmlDecode(value)); + WizardFields.fillInput($("#ssh_public_key", context), value); } } else if (token_regexp.test(key)) { $(".token_context", context).prop('checked', 'checked'); } else if (net_regexp.test(key)) { $(".network_context", context).prop('checked', 'checked'); } else if ("INIT_SCRIPTS" == key) { - $("input.INIT_SCRIPTS").val(TemplateUtils.htmlDecode(value)); + WizardFields.fillInput($("input.INIT_SCRIPTS", context), value); } else if ("FILES_DS" == key) { - $('.FILES_DS', context).val(TemplateUtils.escapeDoubleQuotes(TemplateUtils.htmlDecode(contextJSON["FILES_DS"]))) + WizardFields.fillInput($('.FILES_DS', context), contextJSON["FILES_DS"]); var files = []; while (match = file_ds_regexp.exec(value)) { files.push(match[1]) @@ -319,7 +319,7 @@ define(function(require) { $(".ENCODE_START_SCRIPT", context).prop('checked', 'checked'); $(".START_SCRIPT", context).val(atob(value)); } else if ("START_SCRIPT" == key) { - $(".START_SCRIPT", context).val(TemplateUtils.escapeDoubleQuotes(TemplateUtils.htmlDecode(value))); + WizardFields.fillInput($(".START_SCRIPT", context), value); } else { customTagsJSON[key] = value; } diff --git a/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/general.js b/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/general.js index 3e7082878f..3ff277c6b5 100644 --- a/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/general.js +++ b/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/general.js @@ -26,6 +26,7 @@ define(function(require) { var Config = require('sunstone-config'); var UserInputs = require('utils/user-inputs'); var UniqueId = require('utils/unique-id'); + var TemplateUtils = require('utils/template-utils'); /* TEMPLATES @@ -93,7 +94,7 @@ define(function(require) { context.on("change", "#LOGO", function() { $("#template_create_logo", context).show(); $("#template_create_logo", context).html('' + - '' + + '' + ''); }); @@ -114,7 +115,7 @@ define(function(require) { if (templateJSON["HYPERVISOR"] == 'vcenter') { templateJSON["VCENTER_PUBLIC_CLOUD"] = { 'TYPE': 'vcenter', - 'VM_TEMPLATE': $("#vcenter_template_uuid", context).val() + 'VM_TEMPLATE': WizardFields.retrieveInput($("#vcenter_template_uuid", context)) }; templateJSON["KEEP_DISKS_ON_DONE"] = $("#KEEP_DISKS", context).is(':checked')?"YES":"NO" @@ -135,9 +136,9 @@ define(function(require) { // Retrieve Datastore Attribute var dsInput = $(".vcenter_datastore_input", context); if (dsInput.length > 0) { - var dsModify = $('.modify_datastore', dsInput).val(); - var dsInitial = $('.initial_datastore', dsInput).val(); - var dsParams = $('.available_datastores', dsInput).val(); + var dsModify = WizardFields.retrieveInput($('.modify_datastore', dsInput)); + var dsInitial = WizardFields.retrieveInput($('.initial_datastore', dsInput)); + var dsParams = WizardFields.retrieveInput($('.available_datastores', dsInput)); if (dsModify === 'fixed' && dsInitial !== '') { templateJSON['VCENTER_DATASTORE'] = dsInitial; @@ -156,9 +157,9 @@ define(function(require) { // Retrieve Resource Pool Attribute var rpInput = $(".vcenter_rp_input", context); if (rpInput.length > 0) { - var rpModify = $('.modify_rp', rpInput).val(); - var rpInitial = $('.initial_rp', rpInput).val(); - var rpParams = $('.available_rps', rpInput).val(); + var rpModify = WizardFields.retrieveInput($('.modify_rp', rpInput)); + var rpInitial = WizardFields.retrieveInput($('.initial_rp', rpInput)); + var rpParams = WizardFields.retrieveInput($('.available_rps', rpInput)); if (rpModify === 'fixed' && rpInitial !== '') { templateJSON['RESOURCE_POOL'] = rpInitial; @@ -167,7 +168,7 @@ define(function(require) { type: 'list', description: Locale.tr("Which resource pool you want this VM to run in?"), initial: rpInitial, - params: $('.available_rps', rpInput).val() + params: WizardFields.retrieveInput($('.available_rps', rpInput)) }); userInputs['RESOURCE_POOL'] = rpUserInputs; @@ -213,7 +214,7 @@ define(function(require) { $.each(publicClouds, function(){ if(this["TYPE"] == "vcenter"){ - $("#vcenter_template_uuid", context).val(this["VM_TEMPLATE"]); + WizardFields.fillInput($("#vcenter_template_uuid", context), this["VM_TEMPLATE"]); return false; } }); @@ -243,12 +244,12 @@ define(function(require) { if (templateJSON["VCENTER_DATASTORE"]) { $('.modify_datastore', context).val('fixed'); - $('.initial_datastore', context).val(templateJSON["VCENTER_DATASTORE"]); + WizardFields.fillInput($('.initial_datastore', context), templateJSON["VCENTER_DATASTORE"]); } if (templateJSON["RESOURCE_POOL"]) { $('.modify_rp', context).val('fixed'); - $('.initial_rp', context).val(templateJSON["RESOURCE_POOL"]); + WizardFields.fillInput($('.initial_rp', context), templateJSON["RESOURCE_POOL"]); } CapacityCreate.fill($("div.capacityCreate", context), templateJSON); diff --git a/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/io.js b/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/io.js index b87ca91099..7aaa76855e 100644 --- a/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/io.js +++ b/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/io.js @@ -74,7 +74,6 @@ define(function(require) { function _setup(context) { $("input[name='graphics_type']", context).change(function() { - $("#TYPE", context).val($(this).attr("value")); if ($(this).attr("value") !== '') { $('input[wizard_field="LISTEN"]', context).val("0.0.0.0"); } else { @@ -93,14 +92,14 @@ define(function(require) { var element1 = document.createElement("input"); element1.id = "INPUT_TYPE" element1.type = "text"; - element1.value = $('select#INPUT_TYPE', context).val() + element1.value = WizardFields.retrieveInput($('select#INPUT_TYPE', context)); cell1.appendChild(element1); var cell2 = row.insertCell(1); var element2 = document.createElement("input"); element2.id = "INPUT_BUS" element2.type = "text"; - element2.value = $('select#INPUT_BUS', context).val() + element2.value = WizardFields.retrieveInput($('select#INPUT_BUS', context)); cell2.appendChild(element2); var cell3 = row.insertCell(2); @@ -127,8 +126,8 @@ define(function(require) { $('#input_table tr', context).each(function() { if ($('#INPUT_TYPE', $(this)).val()) { inputsJSON.push({ - 'TYPE': $('#INPUT_TYPE', $(this)).val(), - 'BUS': $('#INPUT_BUS', $(this)).val() + 'TYPE': WizardFields.retrieveInput($('#INPUT_TYPE', $(this))), + 'BUS': WizardFields.retrieveInput($('#INPUT_BUS', $(this))) }); } }); diff --git a/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/io/html.hbs b/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/io/html.hbs index feb84c41b4..60be31df5c 100644 --- a/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/io/html.hbs +++ b/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/io/html.hbs @@ -20,19 +20,18 @@ {{tr "Graphics"}}
- + - + - + - +

-