From 4d514a0abe3d88fbfd57781d09e2a38219664240 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Mon, 7 Jan 2019 18:52:13 +0100 Subject: [PATCH] development: fix rounding in template cost calculation --- .../form-panels/create/wizard-tabs/general.js | 19 +--------- .../wizard-tabs/general/capacity-create.js | 37 ++++++++++++------- 2 files changed, 26 insertions(+), 30 deletions(-) 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 0661114f5b..275417bb18 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 @@ -122,15 +122,6 @@ define(function(require) { } return number.toFixed(6); } - function caculatedTotalMemory(context){ - var memory_cost = document.getElementById('MEMORY_COST').value; - var type = document.getElementById('MEMORY_UNIT_COST').value; - var real_memory = document.getElementById('MEMORY').value; - memory = memory_cost * real_memory * 24 * 30; //24 hours and 30 days - document.getElementById('total_value_memory').textContent = convertCostNumber(memory); - if (memory_cost != "") - $(".total_memory_cost", context).show(); - } function _setup(context) { var that = this; @@ -145,21 +136,15 @@ define(function(require) { }); context.on("change", "#MEMORY_COST", function() { - caculatedTotalMemory(context); CapacityCreate.calculatedRealMemory(context); }); context.on("change", "#MEMORY_UNIT_COST", function() { - caculatedTotalMemory(context); - CapacityCreate.calculatedRealMemory(); + CapacityCreate.calculatedRealMemory(context); }); context.on("change", "#CPU_COST", function() { - var cpu = document.getElementById('CPU').value; - var cpu_cost = document.getElementById('CPU_COST').value; - document.getElementById('total_value_cpu').textContent = convertCostNumber(cpu * cpu_cost * 24 * 30); - $(".total_cpu_cost", context).show(); - CapacityCreate.calculatedRealCpu(); + CapacityCreate.calculatedRealCpu(context); }); context.on("change", "#DISK_COST", function() { diff --git a/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/general/capacity-create.js b/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/general/capacity-create.js index 0f84e0900e..3213aa9f13 100644 --- a/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/general/capacity-create.js +++ b/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/general/capacity-create.js @@ -106,47 +106,58 @@ define(function(require) { } } - function _calculatedRealMemory(){ + function _calculatedRealMemory(context){ var memory_cost = $("#MEMORY_COST").val(); - var type_cost = $("#MEMORY_UNIT_COST").val(); + var type_cost = $("#MEMORY_UNIT_COST").val(); + var memory = $("#MEMORY").val(); - var type = $("#memory_unit").val(); + var type = $("#memory_unit").val(); + if (type_cost == "GB"){ memory = (memory / 1024) * memory_cost * 24 * 30; } else { memory = memory * memory_cost * 24 * 30; } - document.getElementById('real_memory_cost').textContent = "Cost: " + convertCostNumber(memory); + document.getElementById('real_memory_cost').value = memory; - document.getElementById('total_value_memory').textContent = memory; + document.getElementById('total_value_memory').textContent = convertCostNumber(memory); + + if (memory_cost != "") + $(".total_memory_cost", context).show(); + _totalCost(); } - function _calculatedRealCpu(){ + function _calculatedRealCpu(context){ var cpu_cost = $("#CPU_COST").val(); - var cpu = $("#CPU").val(); + var cpu = $("#CPU").val(); + cpu = cpu * cpu_cost * 24 * 30; - document.getElementById('real_cpu_cost').textContent = "Cost: " + convertCostNumber(cpu); + document.getElementById('real_cpu_cost').value = cpu; - document.getElementById('total_value_cpu').textContent = cpu; + document.getElementById('total_value_cpu').textContent = convertCostNumber(cpu); + + if (cpu_cost != "") + $(".total_cpu_cost", context).show(); + _totalCost(); } function _setup(context) { context.on("change", "#MEMORY", function() { - _calculatedRealMemory(); + _calculatedRealMemory(context); }); context.on("change", "#MEMORY_GB", function() { - _calculatedRealMemory(); + _calculatedRealMemory(context); }); context.on("change", "#memory_unit", function() { - _calculatedRealMemory(); + _calculatedRealMemory(context); }); context.on("change", "#CPU", function() { - _calculatedRealCpu(); + _calculatedRealCpu(context); }); // MB to GB