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 8ff5dd47b1..365b107de2 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 OpenNebula = require('opennebula'); /* TEMPLATES @@ -140,18 +141,33 @@ define(function(require) { }); context.on("change", "#DISK_COST", function() { - var disk = parseFloat(document.getElementById('DISK_COST').value); - that.templateDISKS = JSON.parse(localStorage.getItem("disksJSON")); - if (that.templateDISKS){ - var totalGB = 0; - $.each(that.templateDISKS, function(key, value){ - totalGB += value.SIZE / 1024; - }); - totalCostDisk = totalGB * disk; - CapacityCreate.totalCost(totalCostDisk); + that.disk = parseFloat(document.getElementById('DISK_COST').value); + if(!isNaN(that.disk)){ + that.templateDISKS = JSON.parse(localStorage.getItem("disksJSON")); + if (that.templateDISKS){ + OpenNebula.Image.list({ + timeout: true, + success: function(request, obj_files){ + var totalGB = 0; + $.each(that.templateDISKS, function(ikey, ivalue){ + if (ivalue.IMAGE_ID){ + $.each(obj_files, function(jkey, jvalue){ + if (ivalue.IMAGE_ID == jvalue.IMAGE.ID){ + totalGB += jvalue.IMAGE.SIZE / 1024; + } + }); + } else { + totalGB += ivalue.SIZE / 1024; + } + }); + totalCostDisk = totalGB * that.disk; + CapacityCreate.totalCost(totalCostDisk); + document.getElementById('total_value_disk').textContent = convertCostNumber(that.disk * 24 * 30); + $(".total_disk_cost", context).show(); + } + }); + } } - document.getElementById('total_value_disk').textContent = convertCostNumber(disk * 24 * 30); - $(".total_disk_cost", context).show(); }); context.on("change", "#LOGO", function() { @@ -243,7 +259,6 @@ define(function(require) { } function _fill(context, templateJSON) { - var that = this; that.templateDISKS = $.extend(true, {}, templateJSON.DISK); localStorage.setItem("disksJSON", JSON.stringify(that.templateDISKS)); var sunstone_template = templateJSON.SUNSTONE; 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 9e94cf9e28..7cf30bc9d6 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 @@ -31,8 +31,6 @@ define(function(require) { var TemplateHTML = require('hbs!./capacity-create/html'); - this.totalCostDisk = 0; - /* CONSTRUCTOR */ @@ -93,7 +91,7 @@ define(function(require) { } if(memory === undefined && cpu === undefined){ - document.getElementById('total_cost').textContent = "Total: 0.00"; + document.getElementById('total_cost').textContent = "Total: " + this.totalCostDisk; } else if(memory === undefined){ document.getElementById('total_cost').textContent = "Total: " + convertCostNumber(cpu + this.totalCostDisk); } else if(cpu === undefined){ @@ -127,7 +125,7 @@ define(function(require) { } function _setup(context) { - + this.totalCostDisk = 0; context.on("change", "#MEMORY", function() { _calculatedRealMemory(); });