B #1487: Fix TB input (#4855)

Signed-off-by: Jorge Lobo <jlobo@opennebula.io>
This commit is contained in:
Jorge Miguel Lobo Escalona authored and GitHub committed 2020-06-01 18:52:31 +02:00
1 parent 01798df34e
commit 6b3aeebb09
4 files changed
+71 -112

No files matched your search

@@ -23,7 +23,8 @@ define(function(require) {
var TemplateHTML = require('hbs!./disk-resize/html');
var Sunstone = require('sunstone');
var Tips = require('utils/tips');
var RangeSlider = require('utils/range-slider');
var UserInputs = require("utils/user-inputs");
//var RangeSlider = require('utils/range-slider');
var Humanize = require('utils/humanize');
/*
@@ -82,13 +83,16 @@ define(function(require) {
Tips.setup(context);
var oneTera = Humanize.sizeToMB("1024GB")*1024;
var max = that.diskSize > oneTera? that.diskSize*1024 : oneTera;
$( ".diskSlider", context).html(RangeSlider.html({
min: that.diskSize,
max: max,
initial: that.diskSize,
name: "resize",
max_value: ""
}));
var attrs = {
min: that.diskSize,
max: max,
initial: that.diskSize,
name: "resize",
max_value: "",
type: "range"
}
//$( ".diskSlider", context).html(RangeSlider.html(attrs));
UserInputs.insertAttributeInputMB(attrs, $(".diskSlider", context))
$( ".uinput-slider-val",context).prop('type', 'text');
$( ".uinput-slider-val",context).val(Humanize.size($( ".uinput-slider",context).val()));
+11 -2
View File
@@ -45,7 +45,6 @@ define(function(require) {
function _html(opts) {
opts['sliderId'] = sliderId;
opts['ticks'] = [];
if (opts.tick_size !== undefined){
var tick_val = opts.tick_size * Math.ceil(opts.min / opts.tick_size);
@@ -53,6 +52,15 @@ define(function(require) {
opts['ticks'].push(tick_val);
tick_val += opts.tick_size;
}
if(
opts &&
opts.min &&
opts.tick_size &&
parseInt(opts.min,10) &&
parseInt(opts.min, 10) < parseInt(opts.tick_size)
){
opts['ticks'].unshift(opts.min)
}
}
sliderId += 1;
return TemplateHTML(opts);
@@ -66,9 +74,10 @@ define(function(require) {
if(parseInt(this.value) > parseInt(max))
$("input[type=number]", $(this).closest('.uinput-slider-container')).val(max);
});
$(document).off("input", "input.uinput-slider");
$(document).on("input", "input.uinput-slider", function(){
//change selector to MB
$(".mb_input_unit", $(this).closest('.mb_input_wrapper')).val("MB");
$("input[type=number]", $(this).closest('.uinput-slider-container')).val( this.value );
});
}
@@ -34,10 +34,13 @@
</datalist>
</div>
<div class="large-4 small-6 columns">
<input type="number" class="uinput-slider-val"
min="{{min}}" max="{{max_value}}" step="{{step}}"
<input type="number" class="uinput-slider-val hide"
min="{{min}}" max="{{max_value}}"
value="{{initial}}"
{{#unless wizard_field_disabled}}wizard_field="{{name}}"{{/unless}}
{{#if disabled}}disabled="true"{{/if}} required/>
{{#if disabled}}disabled="true"{{/if}}/>
<input type="number" class="visor"
data-min="{{min}}" data-max="{{max_value}}"
value="{{initial}}" required/>
</div>
</div>
+42 -99
View File
@@ -718,52 +718,11 @@ define(function(require) {
if (attr.type == "range"){
attr.tick_size = 1024;
}
delete attr_gb.initial;
attr_gb.wizard_field_disabled = true;
if (attr_gb.type == "range"){
attr_gb.type = "range-float";
attr_gb.min = Math.ceil((attr_gb.min / 1024));
attr_gb.max = Math.floor((attr_gb.max / 1024));
attr_gb.step = "1";
attr_gb.tick_size = 1;
} else if (attr_gb.type == "list"){
attr_gb.options = attr_gb.options.map(function(e){
return e / 1024;
});
} else if (attr_gb.type == "number"){
attr_gb.type = "number-float";
attr_gb.step = "0.1";
}
// Modified input for TB
var attr_tb = $.extend({}, attr);
delete attr_tb.initial;
attr_tb.wizard_field_disabled = true;
if (attr_tb.type == "range"){
attr_tb.type = "range-float";
attr_tb.min = (attr_tb.min / (1024*1024));
attr_tb.max = (attr_tb.max / (1024*1024));
attr_tb.step = "0.0001";
attr_tb.tick_size = 0.0001;
} else if (attr_tb.type == "list"){
attr_tb.options = attr_tb.options.map(function(e){
return e / (1024*1024);
});
} else if (attr_tb.type == "number"){
attr_tb.type = "number-float";
attr_tb.step = "0.1";
}
div.html(
"<div class=\"input-group mb_input_wrapper\">"+
"<div class=\"mb_input input-group-field\">" +
_attributeInput(attr) +
"</div>" +
"<div class=\"gb_input input-group-field\">" +
_attributeInput(attr_gb) +
"</div>" +
"<div class=\"tb_input input-group-field\">" +
_attributeInput(attr_tb) +
"</div>" +
"<div class=\"input-group-button\">"+
"</div><div class=\"input-group-button\">"+
"<select class=\"mb_input_unit\">" +
"<option value=\"MB\">"+Locale.tr("MB")+"</option>" +
"<option value=\"GB\" selected>"+Locale.tr("GB")+"</option>" +
@@ -772,14 +731,17 @@ define(function(require) {
"</div>"+
"</div>");
_setupAttributeInputMB(div);
// Update attr_gb with the value set in attr
$("input, select", $("div.mb_input", div)).trigger("input");
var input_val = $("input, select", $("div.mb_input", div)).val();
if (input_val == ""){
$(".mb_input_unit", div).val("GB").change();
}else{
if ((input_val >= 1024) && (input_val < 1048576) && (input_val % 1024 == 0)){
if (
(input_val >= 1024) &&
(input_val < 1048576) &&
(input_val % 1024 == 0)
){
$(".mb_input_unit", div).val("GB").change();
} else if ((input_val >= 1048576) && (input_val % 1048576 == 0)){
$(".mb_input_unit", div).val("TB").change();
@@ -790,72 +752,53 @@ define(function(require) {
}
function _setupAttributeInputMB(context) {
// MB to GB and TB
$("div.mb_input", context).on("change", "input, select", function(){
var valGB = "";
var valTB = "";
$("div.mb_input", context).on("change", "input.visor, select", function(e){
var base = 1024;
var baseCal = 1;
var unit = "MB";
var valueInMB = 0;
var element = $(this);
var min = parseInt(element.attr("data-min"),10);
var max = parseInt(element.attr("data-max"),10);
var value = element.val();
var valueInUnit = value;
if (this.value && this.value >= 0) {
valGB = this.value / 1024;
valTB = this.value / 1048576;
var contextElement = $("div.mb_input", context);
var mb_input_unit_val = $(".mb_input_unit :selected", context).val();
switch (mb_input_unit_val) {
case 'TB':
baseCal = base**2;
unit = "TB";
break;
case 'GB':
baseCal = base;
unit = "GB";
break;
default:
break;
}
$("input, select", $("div.gb_input", context)).val(valGB);
$("input, select", $("div.tb_input", context)).val(valTB);
});
// GB to MB and TB
$("div.gb_input", context).on("change", "input, select", function(){
var valMB = "";
var valTB = "";
if (this.value && this.value >= 0) {
valMB = Math.floor(this.value * 1024);
valTB = this.value / 1024;
if (value && value.length > 0) {
//aca se puede colocar el div de validation de min and max
valueInMB = value * baseCal;
if(!isNaN(min) && parseInt(min, 10) > valueInMB ){
valueInMB = min;
}
$("input, select", contextElement).val(valueInMB);
valueInUnit = valueInMB / baseCal;
}
$("input, select", $("div.mb_input", context)).val(valMB);
$("input, select", $("div.tb_input", context)).val(valTB);
});
// TB to MB and GB
$("div.tb_input", context).on("change", "input, select", function(){
var valMB = "";
var valGB = "";
if (this.value && this.value >= 0) {
valGB = Math.floor(this.value * (1024));
valMB = Math.floor(this.value * (1048576));
}
$("input, select", $("div.mb_input", context)).val(valMB);
$("input, select", $("div.gb_input", context)).val(valGB);
$("input.visor", contextElement).val(valueInUnit);
var contextUnit = contextElement.siblings(".input-group-button");
$(".mb_input_unit", contextUnit).val(unit);
});
// Unit select
$(".mb_input_unit", context).on("change", function() {
var mb_input_unit_val = $(".mb_input_unit :selected", context).val();
if (mb_input_unit_val == "TB") {
$("div.mb_input", context).hide();
$("div.gb_input", context).hide();
$("div.tb_input", context).show();
$("input, select", $("div.mb_input",context)).trigger("change");
} else if (mb_input_unit_val == "GB") {
$("div.mb_input", context).hide();
$("div.gb_input", context).show();
$("div.tb_input", context).hide();
$("input, select", $("div.mb_input",context)).trigger("change");
} else {
$("div.mb_input", context).show();
$("div.gb_input", context).hide();
$("div.tb_input", context).hide();
}
$("input, select", $("div.mb_input",context)).trigger("change");
});
$(".mb_input_unit", context).change();
}
/**