From 30675702c381660ad6557a7a9b0435074868d95a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Wed, 10 Jun 2015 16:41:11 +0200 Subject: [PATCH] Feature #3748: Oneflow template update wizard --- .../form-panels/create.js | 95 ++++++++++++++++++- .../form-panels/create/wizard.hbs | 46 ++++----- .../oneflow-templates-tab/utils/role-tab.js | 73 +++++++++++++- .../app/templates/helpers/advancedSection.js | 2 +- 4 files changed, 190 insertions(+), 26 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 879ab2e479..9f1199bbe7 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 @@ -9,6 +9,7 @@ define(function(require) { var Locale = require('utils/locale'); var Tips = require('utils/tips'); var RoleTab = require('tabs/oneflow-templates-tab/utils/role-tab'); + var TemplateUtils = require('utils/template-utils'); /* TEMPLATES @@ -266,7 +267,99 @@ define(function(require) { } function _fill(context, element) { - // TODO + var that = this; + + if (this.action != "update") {return;} + this.resourceId = element.ID; + + // Populates the Avanced mode Tab + $('#template', context).val(TemplateUtils.htmlDecode( + JSON.stringify(element.TEMPLATE.BODY, null, " "))); + + + $("#service_name", context).attr("disabled", "disabled"); + $("#service_name", context).val(TemplateUtils.htmlDecode(element.NAME)); + + $("#description", context).val(TemplateUtils.htmlDecode(element.TEMPLATE.BODY.description)); + + $('select[name="deployment"]', context).val(element.TEMPLATE.BODY.deployment); + $("select[name='shutdown_action_service']", context).val(element.TEMPLATE.BODY.shutdown_action); + $("input[name='ready_status_gate']", context).prop("checked",element.TEMPLATE.BODY.ready_status_gate || false); + + + $(".service_networks i.remove-tab", context).trigger("click"); + + if ( ! $.isEmptyObject( element.TEMPLATE.BODY['custom_attrs'] ) ) { + $("div#network_configuration a.accordion_advanced_toggle", context).trigger("click"); + + $.each(element.TEMPLATE.BODY['custom_attrs'], function(key, attr){ + var parts = attr.split("|"); + // 0 mandatory; 1 type; 2 desc; + var attrs = { + "name": key, + "mandatory": parts[0], + "type": parts[1], + "description": parts[2], + }; + + switch (parts[1]) { + case "vnet_id": + $(".add_service_network", context).trigger("click"); + + var tr = $(".service_networks tbody tr", context).last(); + $(".service_network_name", tr).val(TemplateUtils.htmlDecode(attrs.name)).change(); + $(".service_network_description", tr).val(TemplateUtils.htmlDecode(attrs.description)); + + break; + } + }); + } + + $("#roles_tabs i.remove-tab", context).trigger("click"); + + var network_names = []; + + $(".service_networks .service_network_name", context).each(function(){ + if ($(this).val()) { + network_names.push($(this).val()); + } + }); + + var roles_names = []; + $.each(element.TEMPLATE.BODY.roles, function(index, value){ + roles_names.push(value.name); + + $("#tf_btn_roles", context).click(); + + var role_context = $('.role_content', context).last(); + var role_id = $(role_context).attr("role_id"); + + that.roleTabObjects[role_id].fill(role_context, value, network_names); + }); + + $.each(element.TEMPLATE.BODY.roles, function(index, value){ + var role_context = $('.role_content', context)[index]; + var str = ""; + + $.each(roles_names, function(){ + if (this != value.name) { + str += "\ + \ + \ + \ + "+this+"\ + "; + } + }); + + $(".parent_roles_body", role_context).html(str); + + if (value.parents) { + $.each(value.parents, function(index, value){ + $(".parent_roles_body #"+this, role_context).attr('checked', true); + }); + } + }); } //---------------------------------------------------------------------------- diff --git a/src/sunstone/public/app/tabs/oneflow-templates-tab/form-panels/create/wizard.hbs b/src/sunstone/public/app/tabs/oneflow-templates-tab/form-panels/create/wizard.hbs index a68412f1b0..93eb55e1da 100644 --- a/src/sunstone/public/app/tabs/oneflow-templates-tab/form-panels/create/wizard.hbs +++ b/src/sunstone/public/app/tabs/oneflow-templates-tab/form-panels/create/wizard.hbs @@ -20,30 +20,32 @@
- {{#advancedSection (tr "Network Configuration") }} -
-
- - - - - - - - - - - - - - - -
{{tr "Name"}}{{tr "Description"}}
- {{tr "Add another Network"}} -
+
+ {{#advancedSection (tr "Network Configuration") }} +
+
+ + + + + + + + + + + + + + + +
{{tr "Name"}}{{tr "Description"}}
+ {{tr "Add another Network"}} +
+
+ {{/advancedSection}}
- {{/advancedSection}}
{{#advancedSection (tr "Advanced Service Parameters") }}
diff --git a/src/sunstone/public/app/tabs/oneflow-templates-tab/utils/role-tab.js b/src/sunstone/public/app/tabs/oneflow-templates-tab/utils/role-tab.js index 8da638f02a..99475ac740 100644 --- a/src/sunstone/public/app/tabs/oneflow-templates-tab/utils/role-tab.js +++ b/src/sunstone/public/app/tabs/oneflow-templates-tab/utils/role-tab.js @@ -3,6 +3,7 @@ define(function(require) { var Locale = require('utils/locale'); var Tips = require('utils/tips'); var TemplatesTable = require('tabs/templates-tab/datatable'); + var TemplateUtils = require('utils/template-utils'); var TemplateHTML = require('hbs!./role-tab/html'); var TemplateElasticityRowHTML = require('hbs!./role-tab/elasticity-row'); @@ -19,8 +20,7 @@ define(function(require) { 'setup': _setup_role_tab_content, 'onShow': _onShow, 'retrieve': _retrieve, - //'fill': _fill - + 'fill': _fill }; RoleTab.prototype.constructor = RoleTab; @@ -165,6 +165,75 @@ define(function(require) { return role; } + function _fill(context, value, network_names) { + $("#role_name", context).val(TemplateUtils.htmlDecode(value.name)); + $("#role_name", context).change(); + + $("#cardinality", context).val(TemplateUtils.htmlDecode(value.cardinality)); + + this.templatesTable.selectResourceTableSelect({ids : value.vm_template}); + + if (value.vm_template_contents){ + $(network_names).each(function(){ + var reg = new RegExp("\\$"+this+"\\b"); + + if(reg.exec(value.vm_template_contents) != null){ + $(".service_network_checkbox[value='"+this+"']", context).attr('checked', true).change(); + } + }); + + $(".vm_template_contents", context).val(TemplateUtils.htmlDecode(value.vm_template_contents)); + } + + $("select[name='shutdown_action_role']", context).val(value.shutdown_action); + + $("#min_vms", context).val(TemplateUtils.htmlDecode(value.min_vms)); + $("#max_vms", context).val(TemplateUtils.htmlDecode(value.max_vms)); + $("#cooldown", context).val(TemplateUtils.htmlDecode(value.cooldown)); + + if (value['elasticity_policies'].length > 0 || + value['scheduled_policies'].length > 0) { + $("div.elasticity_accordion a.accordion_advanced_toggle", context).trigger("click"); + } + + $("#elasticity_policies_table i.remove-tab", context).trigger("click"); + $("#scheduled_policies_table i.remove-tab", context).trigger("click"); + + if (value['elasticity_policies']) { + $.each(value['elasticity_policies'], function(){ + $("#tf_btn_elas_policies", context).click(); + var td = $("#elasticity_policies_tbody tr", context).last(); + $("#type" ,td).val(TemplateUtils.htmlDecode(this['type'])); + $("#type" ,td).change(); + $("#adjust" ,td).val(TemplateUtils.htmlDecode(this['adjust'] )); + $("#min_adjust_step" ,td).val(TemplateUtils.htmlDecode(this['min_adjust_step'] || "")); + $("#expression" ,td).val(TemplateUtils.htmlDecode(this.expression)); + $("#period_number" ,td).val(TemplateUtils.htmlDecode(this['period_number'] || "")); + $("#period" ,td).val(TemplateUtils.htmlDecode(this['period'] || "" )); + $("#cooldown" ,td).val(TemplateUtils.htmlDecode(this['cooldown'] || "" )); + }); + } + + if (value['scheduled_policies']) { + $.each(value['scheduled_policies'], function(){ + $("#tf_btn_sche_policies", context).click(); + var td = $("#scheduled_policies_tbody tr", context).last(); + $("#type", td).val(TemplateUtils.htmlDecode(this['type'])); + $("#type" ,td).change(); + $("#adjust", td).val(TemplateUtils.htmlDecode(this['adjust'] )); + $("#min_adjust_step", td).val(TemplateUtils.htmlDecode(this['min_adjust_step'] || "")); + + if (this['start_time']) { + $("#time_format", td).val('start_time'); + $("#time", td).val(TemplateUtils.htmlDecode(this['start_time'])); + } else if (this['recurrence']) { + $("#time_format", td).val('recurrence'); + $("#time", td).val(TemplateUtils.htmlDecode(this['recurrence'])); + } + }); + } + } + //---------------------------------------------------------------------------- function _removeEmptyObjects(obj){ diff --git a/src/sunstone/public/app/templates/helpers/advancedSection.js b/src/sunstone/public/app/templates/helpers/advancedSection.js index d9a8d9193b..19d25c39f9 100644 --- a/src/sunstone/public/app/templates/helpers/advancedSection.js +++ b/src/sunstone/public/app/templates/helpers/advancedSection.js @@ -10,7 +10,7 @@ define(function(require) { return new Handlebars.SafeString( '