mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-22 18:50:08 +03:00
Feature #4317: Use 2 inputs for min,max in capacity inputs
This commit is contained in:
parent
225b250c62
commit
a29cc36831
@ -50,73 +50,62 @@ define(function(require) {
|
||||
return TemplateHTML();
|
||||
}
|
||||
|
||||
function _m2g(val){
|
||||
if(isNaN(val) || val == ""){
|
||||
return "";
|
||||
}
|
||||
|
||||
return val / 1024;
|
||||
}
|
||||
|
||||
function _g2m(val){
|
||||
if(isNaN(val) || val == ""){
|
||||
return "";
|
||||
}
|
||||
|
||||
return Math.floor(val * 1024);
|
||||
}
|
||||
|
||||
function _setup(context) {
|
||||
|
||||
// MB to GB
|
||||
context.on("input", "div.memory_input input", function(){
|
||||
if (this.value && this.value >= 0) {
|
||||
$("div.memory_gb_input input", context).val( this.value / 1024 );
|
||||
} else {
|
||||
$("div.memory_gb_input input", context).val("");
|
||||
}
|
||||
$("div.memory_gb_input input", context).val(_m2g(this.value));
|
||||
});
|
||||
|
||||
// MB to GB, range input
|
||||
context.on("input", "div.memory_modify_opt.range input.mb_unit", function(){
|
||||
var val = this.value.split("..").map(function(e){
|
||||
if(isNaN(e) || e == ""){
|
||||
return "";
|
||||
}
|
||||
context.on("input", "div.mb_unit input.user_input_params_min", function(){
|
||||
$("div.gb_unit input.user_input_params_min").val(_m2g(this.value));
|
||||
});
|
||||
|
||||
return e / 1024;
|
||||
}).join("..");
|
||||
|
||||
$("div.memory_modify_opt.range input.gb_unit", context).val(val);
|
||||
context.on("input", "div.mb_unit input.user_input_params_max", function(){
|
||||
$("div.gb_unit input.user_input_params_max").val(_m2g(this.value));
|
||||
});
|
||||
|
||||
// MB to GB, list input
|
||||
context.on("input", "div.memory_modify_opt.list input.mb_unit", function(){
|
||||
var val = this.value.split(",").map(function(e){
|
||||
if(isNaN(e) || e == ""){
|
||||
return "";
|
||||
}
|
||||
|
||||
return e / 1024;
|
||||
}).join(",");
|
||||
var val = this.value.split(",").map(_m2g).join(",");
|
||||
|
||||
$("div.memory_modify_opt.list input.gb_unit", context).val(val);
|
||||
});
|
||||
|
||||
// GB to MB
|
||||
context.on("input", "div.memory_gb_input input", function(){
|
||||
if (this.value && this.value >= 0) {
|
||||
$("div.memory_input input", context).val( Math.floor(this.value * 1024) );
|
||||
} else {
|
||||
$("div.memory_input input", context).val("");
|
||||
}
|
||||
$("div.memory_input input", context).val(_g2m(this.value));
|
||||
});
|
||||
|
||||
// GB to MB, range input
|
||||
context.on("input", "div.memory_modify_opt.range input.gb_unit", function(){
|
||||
var val = this.value.split("..").map(function(e){
|
||||
if(isNaN(e) || e == ""){
|
||||
return "";
|
||||
}
|
||||
context.on("input", "div.gb_unit input.user_input_params_min", function(){
|
||||
$("div.mb_unit input.user_input_params_min").val(_g2m(this.value));
|
||||
});
|
||||
|
||||
return Math.floor(e * 1024);
|
||||
}).join("..");
|
||||
|
||||
$("div.memory_modify_opt.range input.mb_unit", context).val(val);
|
||||
context.on("input", "div.gb_unit input.user_input_params_max", function(){
|
||||
$("div.mb_unit input.user_input_params_max").val(_g2m(this.value));
|
||||
});
|
||||
|
||||
// GB to MB, list input
|
||||
context.on("input", "div.memory_modify_opt.list input.gb_unit", function(){
|
||||
var val = this.value.split(",").map(function(e){
|
||||
if(isNaN(e) || e == ""){
|
||||
return "";
|
||||
}
|
||||
|
||||
return Math.floor(e * 1024);
|
||||
}).join(",");
|
||||
var val = this.value.split(",").map(_g2m).join(",");
|
||||
|
||||
$("div.memory_modify_opt.list input.mb_unit", context).val(val);
|
||||
});
|
||||
@ -189,7 +178,22 @@ define(function(require) {
|
||||
|
||||
$("."+classname+"_modify_type", context).val(attr.type).change();
|
||||
|
||||
$("input."+classname+"_modify_opt."+attr.type, context).val(attr.params).trigger("input");
|
||||
if (attr.type == "range" ||
|
||||
attr.type == "range-float"){
|
||||
|
||||
var values = attr.params.split(".."); // "2..8"
|
||||
|
||||
if (values.length == 2){
|
||||
var param_context = $("div."+classname+"_modify_opt."+attr.type, context);
|
||||
|
||||
$("input.user_input_params_min", param_context).val(values[0]).trigger("input");
|
||||
$("input.user_input_params_max", param_context).val(values[1]).trigger("input");
|
||||
} else {
|
||||
console.error('Wrong user input parameters for "'+name+'". Expected "MIN..MAX", received "'+attr.params+'"');
|
||||
}
|
||||
} else if (attr.type == "list"){
|
||||
$("input."+classname+"_modify_opt."+attr.type, context).val(attr.params).trigger("input");
|
||||
}
|
||||
|
||||
delete userInputsJSON[name];
|
||||
}
|
||||
@ -227,10 +231,16 @@ define(function(require) {
|
||||
attr.initial = $('input[wizard_field="'+attr.name+'"]', context).val();
|
||||
|
||||
if (attr.type == "range" ||
|
||||
attr.type == "range-float" ||
|
||||
attr.type == "list"){
|
||||
attr.type == "range-float"){
|
||||
|
||||
attr.params = $("input."+classname+"_modify_opt."+attr.type, context).val();
|
||||
var param_context = $("div."+classname+"_modify_opt."+attr.type, context);
|
||||
|
||||
var min = $("input.user_input_params_min", param_context).val();
|
||||
var max = $("input.user_input_params_max", param_context).val();
|
||||
attr.params = min + ".." + max;
|
||||
|
||||
} else if (attr.type == "list"){
|
||||
attr.params = $("input."+classname+"_modify_opt."+attr.type, context).val();
|
||||
}
|
||||
|
||||
userInputsJSON[attr.name] = UserInputs.marshall(attr);
|
||||
|
@ -57,8 +57,22 @@
|
||||
</div>
|
||||
<div class="small-6 columns">
|
||||
<div class="memory_modify_opt range">
|
||||
<input type=text class="mb_unit memory_modify_opt range" placeholder="512..4096"/>
|
||||
<input type=text class="gb_unit" placeholder="0.5..4"/>
|
||||
<div class="row mb_unit">
|
||||
<div class="small-6 columns">
|
||||
<input type="number" min="0" class="user_input_params_min" placeholder="{{tr "Min"}}"/>
|
||||
</div>
|
||||
<div class="small-6 columns">
|
||||
<input type="number" min="0" class="user_input_params_max" placeholder="{{tr "Max"}}"/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row gb_unit">
|
||||
<div class="small-6 columns">
|
||||
<input type="number" min="0" step="any" class="user_input_params_min" placeholder="{{tr "Min"}}"/>
|
||||
</div>
|
||||
<div class="small-6 columns">
|
||||
<input type="number" min="0" step="any" class="user_input_params_max" placeholder="{{tr "Max"}}"/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="memory_modify_opt list">
|
||||
<input type=text class="mb_unit memory_modify_opt list" placeholder="1024,4096,8192"/>
|
||||
@ -98,12 +112,19 @@
|
||||
<select class="cpu_modify_type" >
|
||||
<option value="fixed">{{tr "fixed"}}</option>
|
||||
<option selected value="number-float">{{tr "any value"}}</option>
|
||||
<option value="range">{{tr "range"}}</option>
|
||||
<option value="range-float">{{tr "range"}}</option>
|
||||
<option value="list">{{tr "list"}}</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="small-8 columns">
|
||||
<input type=text class="cpu_modify_opt range" placeholder="0.5..8"/>
|
||||
<div class="row cpu_modify_opt range-float">
|
||||
<div class="small-6 columns">
|
||||
<input type="number" min="0" step="0.01" class="user_input_params_min" placeholder="{{tr "Min"}}"/>
|
||||
</div>
|
||||
<div class="small-6 columns">
|
||||
<input type="number" min="0" step="0.01" class="user_input_params_max" placeholder="{{tr "Max"}}"/>
|
||||
</div>
|
||||
</div>
|
||||
<input type=text class="cpu_modify_opt list" placeholder="0.5,1,4,16"/>
|
||||
</div>
|
||||
</div>
|
||||
@ -140,7 +161,14 @@
|
||||
</select>
|
||||
</div>
|
||||
<div class="small-8 columns">
|
||||
<input type=text class="vcpu_modify_opt range" placeholder="1..8"/>
|
||||
<div class="row vcpu_modify_opt range">
|
||||
<div class="small-6 columns">
|
||||
<input type="number" min="0" step="1" class="user_input_params_min" placeholder="{{tr "Min"}}"/>
|
||||
</div>
|
||||
<div class="small-6 columns">
|
||||
<input type="number" min="0" step="1" class="user_input_params_max" placeholder="{{tr "Max"}}"/>
|
||||
</div>
|
||||
</div>
|
||||
<input type=text class="vcpu_modify_opt list" placeholder="4,8,16"/>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -129,6 +129,8 @@ define(function(require) {
|
||||
attr.initial = element.TEMPLATE.CPU;
|
||||
}
|
||||
|
||||
attr.step = 0.01;
|
||||
|
||||
input = UserInputs.attributeInput(attr);
|
||||
|
||||
$("div.cpu_input", context).html(input);
|
||||
@ -195,7 +197,8 @@ define(function(require) {
|
||||
// Update memory_gb with the value set in memory
|
||||
$("input, select", $("div.memory_input", context)).trigger("input");
|
||||
|
||||
if ($("input, select", $("div.memory_input", context)).val() >= 1024){
|
||||
var mem_value = $("input, select", $("div.memory_input", context)).val();
|
||||
if (mem_value == "" || (mem_value >= 1024 && (mem_value % 1024 == 0))){
|
||||
$("#memory_unit", context).val("GB").change();
|
||||
} else {
|
||||
$("#memory_unit", context).val("MB").change();
|
||||
|
Loading…
x
Reference in New Issue
Block a user