1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-22 18:50:08 +03:00

Bug #4117: Show cpu and mem cost in template instantiate

(cherry picked from commit 18439c4b2c3e7cd4d5744b99ba0aca0bed48eca5)
This commit is contained in:
Carlos Martín 2015-11-03 17:00:06 +01:00
parent ceb6710f80
commit 5e0cf9b5e0
3 changed files with 40 additions and 1 deletions

View File

@ -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

View File

@ -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"){

View File

@ -27,6 +27,10 @@
<span class="left">
<i class="fa fa-laptop fa-lg"></i>&emsp;{{tr "Capacity"}}
</span>
<span class="capacity_cost_div hidden">
<span class="cost_value">0.00</span>
<small style="color: #999;">{{tr "COST"}} / {{tr "HOUR"}}</small>
</span>
<br>
</h3>
</div>