diff --git a/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/general/capacity-inputs.js b/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/general/capacity-inputs.js index 9d28f09f71..2779006f0c 100644 --- a/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/general/capacity-inputs.js +++ b/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/general/capacity-inputs.js @@ -37,6 +37,7 @@ define(function(require) { return { 'html': _html, 'setup': _setup, + 'setCallback': _setCallback, 'fill': _fill, 'retrieve': _retrieve, 'retrieveResize': _retrieveResize @@ -146,7 +147,7 @@ define(function(require) { new_val = Math.floor(memory_input.val() * 1024); } - context.foundation('slider', 'reflow'); + $("#memory_slider", context).foundation('slider', 'reflow'); memory_input.val(new_val); $("#memory_slider", context).foundation('slider', 'set_value', new_val * 100); $("#memory_slider", context).on('change.fndtn.slider', function() { @@ -202,6 +203,17 @@ define(function(require) { WizardFields.fill(context, element.TEMPLATE); } + /** + * Sets a callback that will be called when the input values change + * @param {Object} context jQuery selector + * @param {Function} callback will be called as callback( retrieve(context) ) + */ + function _setCallback(context, callback) { + context.on("change.fndtn.slider", function(){ + callback( _retrieve(context) ); + }); + } + /** * Retrieves the input values * @param {Object} context JQuery selector diff --git a/src/sunstone/public/app/tabs/templates-tab/form-panels/instantiate.js b/src/sunstone/public/app/tabs/templates-tab/form-panels/instantiate.js index 2e9ace3f97..e8593c6b4b 100644 --- a/src/sunstone/public/app/tabs/templates-tab/form-panels/instantiate.js +++ b/src/sunstone/public/app/tabs/templates-tab/form-panels/instantiate.js @@ -32,6 +32,7 @@ define(function(require) { var DisksResize = require('utils/disks-resize'); var NicsSection = require('utils/nics-section'); var CapacityInputs = require('tabs/templates-tab/form-panels/create/wizard-tabs/general/capacity-inputs'); + var Config = require('sunstone-config'); /* CONSTANTS @@ -196,6 +197,28 @@ define(function(require) { CapacityInputs.setup(capacityContext); CapacityInputs.fill(capacityContext, template_json.VMTEMPLATE); + var cpuCost = template_json.VMTEMPLATE.TEMPLATE.CPU_COST; + var memoryCost = template_json.VMTEMPLATE.TEMPLATE.MEMORY_COST; + + if ((cpuCost != undefined || memoryCost != undefined) && Config.isFeatureEnabled("showback")) { + var cost = 0; + + var cpu = template_json.VMTEMPLATE.TEMPLATE.CPU; + var memory = template_json.VMTEMPLATE.TEMPLATE.MEMORY; + + if (cpu != undefined && memory != undefined) { + cost = cpuCost * cpu + memoryCost * memory; + } + + $(".cost_value", capacityContext).html(cost.toFixed(2)); + $(".capacity_cost_div", capacityContext).show(); + + CapacityInputs.setCallback(capacityContext, function(values){ + var cost = cpuCost * values.CPU + memoryCost * values.MEMORY; + $(".cost_value", capacityContext).html(cost.toFixed(2)); + }); + } + if (template_json.VMTEMPLATE.TEMPLATE.SUNSTONE_CAPACITY_SELECT && template_json.VMTEMPLATE.TEMPLATE.SUNSTONE_CAPACITY_SELECT.toUpperCase() == "NO"){ diff --git a/src/sunstone/public/app/tabs/templates-tab/form-panels/instantiate/templateRow.hbs b/src/sunstone/public/app/tabs/templates-tab/form-panels/instantiate/templateRow.hbs index 7eea3a3046..962b3a8afb 100644 --- a/src/sunstone/public/app/tabs/templates-tab/form-panels/instantiate/templateRow.hbs +++ b/src/sunstone/public/app/tabs/templates-tab/form-panels/instantiate/templateRow.hbs @@ -27,6 +27,10 @@  {{tr "Capacity"}} +