From 6b3aeebb09ee24ec6fef4032396f95fe9e65a5c1 Mon Sep 17 00:00:00 2001 From: Jorge Miguel Lobo Escalona <47326048+jloboescalona2@users.noreply.github.com> Date: Mon, 1 Jun 2020 18:52:31 +0200 Subject: [PATCH] B #1487: Fix TB input (#4855) Signed-off-by: Jorge Lobo --- .../app/tabs/vms-tab/dialogs/disk-resize.js | 20 ++- src/sunstone/public/app/utils/range-slider.js | 13 +- .../public/app/utils/range-slider/html.hbs | 9 +- src/sunstone/public/app/utils/user-inputs.js | 141 ++++++------------ 4 files changed, 71 insertions(+), 112 deletions(-) diff --git a/src/sunstone/public/app/tabs/vms-tab/dialogs/disk-resize.js b/src/sunstone/public/app/tabs/vms-tab/dialogs/disk-resize.js index b26d3bd5e3..7c12fddda6 100644 --- a/src/sunstone/public/app/tabs/vms-tab/dialogs/disk-resize.js +++ b/src/sunstone/public/app/tabs/vms-tab/dialogs/disk-resize.js @@ -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())); diff --git a/src/sunstone/public/app/utils/range-slider.js b/src/sunstone/public/app/utils/range-slider.js index 502836b119..43b1523280 100644 --- a/src/sunstone/public/app/utils/range-slider.js +++ b/src/sunstone/public/app/utils/range-slider.js @@ -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 ); }); } diff --git a/src/sunstone/public/app/utils/range-slider/html.hbs b/src/sunstone/public/app/utils/range-slider/html.hbs index 7655fc9286..8973fe2481 100644 --- a/src/sunstone/public/app/utils/range-slider/html.hbs +++ b/src/sunstone/public/app/utils/range-slider/html.hbs @@ -34,10 +34,13 @@
- + {{#if disabled}}disabled="true"{{/if}}/> +
diff --git a/src/sunstone/public/app/utils/user-inputs.js b/src/sunstone/public/app/utils/user-inputs.js index ad8f15150a..ec2b94a71d 100644 --- a/src/sunstone/public/app/utils/user-inputs.js +++ b/src/sunstone/public/app/utils/user-inputs.js @@ -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( "
"+ "
" + _attributeInput(attr) + - "
" + - "
" + - _attributeInput(attr_gb) + - "
" + - "
" + - _attributeInput(attr_tb) + - "
" + - "
"+ + "
"+ "