From 163b91d52280fd3de41c2c430cf4d1751ef4a07b Mon Sep 17 00:00:00 2001 From: juanmont Date: Mon, 8 May 2017 12:35:21 +0200 Subject: [PATCH] Feature template (#296) * removed merge templates function * saved disk template into disk-tab --- .../form-panels/create.js | 13 ++++--------- .../form-panels/create-common.js | 15 ++++----------- .../create/wizard-tabs/storage/disk-tab.js | 4 +++- .../wizard-tabs/storage/disk-tab/html.hbs | 2 +- .../public/app/utils/template-utils.js | 19 ------------------- 5 files changed, 12 insertions(+), 41 deletions(-) diff --git a/src/sunstone/public/app/tabs/oneflow-templates-tab/form-panels/create.js b/src/sunstone/public/app/tabs/oneflow-templates-tab/form-panels/create.js index 32be38d488..41c0fa2808 100644 --- a/src/sunstone/public/app/tabs/oneflow-templates-tab/form-panels/create.js +++ b/src/sunstone/public/app/tabs/oneflow-templates-tab/form-panels/create.js @@ -230,27 +230,22 @@ define(function(require) { json_template['ready_status_gate'] = ready_status_gate; - var templateStr = $('textarea#template', $("form#createServiceTemplateFormAdvanced")).val(); - var template_final = TemplateUtils.mergeTemplates(json_template, templateStr); if (this.action == "create") { - Sunstone.runAction("ServiceTemplate.create", template_final ); + Sunstone.runAction("ServiceTemplate.create", json_template ); return false; } else if (this.action == "update") { - Sunstone.runAction("ServiceTemplate.update",this.resourceId, JSON.stringify(template_final)); + Sunstone.runAction("ServiceTemplate.update",this.resourceId, JSON.stringify(json_template)); return false; } } function _submitAdvanced(context) { var templateStr = $('textarea#template', context).val(); - var templateJSON = this.retrieve($("form#createServiceTemplateFormWizard")); - var template_final = TemplateUtils.mergeTemplates(templateStr, templateJSON, true); - template_final = TemplateUtils.templateToString(template_final); if (this.action == "create") { - Sunstone.runAction("ServiceTemplate.create", JSON.parse(template_final) ); + Sunstone.runAction("ServiceTemplate.create", JSON.parse(templateStr) ); return false; } else if (this.action == "update") { - Sunstone.runAction("ServiceTemplate.update", this.resourceId, template_final); + Sunstone.runAction("ServiceTemplate.update", this.resourceId, templateStr); return false; } } 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 9de6d5f257..1bd75b75e2 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 @@ -188,32 +188,25 @@ define(function(require) { function _submitWizard(context) { var templateJSON = this.retrieve(context); - var contextAdv = context[0].id.replace("Wizard", "Advanced") - var templateStr = $('textarea#template', $("form#"+contextAdv)).val(); - var template_final = TemplateUtils.mergeTemplates(templateJSON, templateStr); if (this.action == "create") { - Sunstone.runAction(this.resource+".create", {'vmtemplate': template_final}); + Sunstone.runAction(this.resource+".create", {'vmtemplate': templateJSON}); return false; } else if (this.action == "update") { - Sunstone.runAction(this.resource+".update", this.resourceId, TemplateUtils.templateToString(template_final)); + Sunstone.runAction(this.resource+".update", this.resourceId, TemplateUtils.templateToString(templateJSON)); return false; } } function _submitAdvanced(context) { var templateStr = $('textarea#template', context).val(); - var contextWiz = context[0].id.replace("Advanced", "Wizard"); - var templateJSON = this.retrieve($("form#"+contextWiz)); - var template_final = TemplateUtils.mergeTemplates(templateStr, templateJSON, true); - template_final = TemplateUtils.templateToString(template_final); if (this.action == "create") { - Sunstone.runAction(this.resource+".create", {"vmtemplate": {"template_raw": template_final}}); + Sunstone.runAction(this.resource+".create", {"vmtemplate": {"template_raw": templateStr}}); return false; } else if (this.action == "update") { - Sunstone.runAction(this.resource+".update", this.resourceId, template_final); + Sunstone.runAction(this.resource+".update", this.resourceId, templateStr); return false; } } diff --git a/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/storage/disk-tab.js b/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/storage/disk-tab.js index 2a7d361f33..df39d45a70 100644 --- a/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/storage/disk-tab.js +++ b/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/storage/disk-tab.js @@ -25,6 +25,7 @@ define(function(require) { var ImageTable = require('tabs/images-tab/datatable') var WizardFields = require('utils/wizard-fields'); var UniqueId = require('utils/unique-id'); + var TemplateUtils = require('utils/template-utils'); /* TEMPLATES @@ -159,7 +160,7 @@ define(function(require) { } tmpl["DEV_PREFIX"] = dev_prefix; } - + $.extend(tmpl, TemplateUtils.stringToTemplate($('#templateStr',context).val())); return tmpl; } @@ -198,6 +199,7 @@ define(function(require) { } WizardFields.fill(selectedContext, templateJSON); + $('#templateStr',context).val(TemplateUtils.templateToString(templateJSON)); var dev_prefix = templateJSON["DEV_PREFIX"]; if (dev_prefix != undefined && dev_prefix.length) { diff --git a/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/storage/disk-tab/html.hbs b/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/storage/disk-tab/html.hbs index 8edbec819d..d42db7a385 100644 --- a/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/storage/disk-tab/html.hbs +++ b/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/storage/disk-tab/html.hbs @@ -13,7 +13,7 @@ {{! See the License for the specific language governing permissions and }} {{! limitations under the License. }} {{! -------------------------------------------------------------------------- }} - +
diff --git a/src/sunstone/public/app/utils/template-utils.js b/src/sunstone/public/app/utils/template-utils.js index bd3d7b9ad4..fc718b3852 100644 --- a/src/sunstone/public/app/utils/template-utils.js +++ b/src/sunstone/public/app/utils/template-utils.js @@ -93,24 +93,6 @@ define(function(require) { return template_str; } - function _merge_templates(template_master, template_slave, advanced){ - if(!advanced){ - template_slave = _convert_string_to_template(template_slave); - } else { - template_master = _convert_string_to_template(template_master); - } - if(template_slave.USER_INPUTS){ - delete template_slave.USER_INPUTS; - } - if((advanced && template_master) || (!advanced && template_slave)){ - var template_final = {}; - $.extend(template_final, template_slave, template_master); - return template_final; - } else { - Notifier.notifyError(Locale.tr("Advanced template malformed")); - } - return template_master; - } // Transforms an object to an opennebula template string function _convert_string_to_template(string_json, unshown_values) { var i = 0; @@ -190,7 +172,6 @@ define(function(require) { } return { - 'mergeTemplates' : _merge_templates, 'stringToTemplate': _convert_string_to_template, 'templateToString': _convert_template_to_string, 'htmlDecode': _htmlDecode,