From 95a796e04e99100b74ea4290dcbb5de6fc7b51f3 Mon Sep 17 00:00:00 2001 From: abelCoronado93 Date: Tue, 20 Jun 2017 10:42:37 +0200 Subject: [PATCH] F #5187 Solved problem resizing CPU & MEM host with the mouse. Solved color bug in range slider when updating CPU & MEM with the input field. --- .../public/app/tabs/hosts-tab/panels/info.js | 50 +++++++++++++------ 1 file changed, 36 insertions(+), 14 deletions(-) diff --git a/src/sunstone/public/app/tabs/hosts-tab/panels/info.js b/src/sunstone/public/app/tabs/hosts-tab/panels/info.js index ee19e0612b..6b4b9ac135 100644 --- a/src/sunstone/public/app/tabs/hosts-tab/panels/info.js +++ b/src/sunstone/public/app/tabs/hosts-tab/panels/info.js @@ -130,14 +130,38 @@ define(function(require) { }); } - function changeInputCPU(){ + function changeInputCPU(maxCPU){ document.getElementById('change_bar_cpu_hosts').value = parseInt(document.getElementById('textInput_reserved_cpu_hosts').value); document.getElementById('textInput_reserved_cpu_hosts').value = document.getElementById('change_bar_cpu_hosts').value; + changeColorInputCPU(maxCPU); } - function changeInputMEM(){ + function changeInputMEM(maxMEM){ document.getElementById('change_bar_mem_hosts').value = Humanize.sizeToMB(document.getElementById('textInput_reserved_mem_hosts').value); document.getElementById('textInput_reserved_mem_hosts').value = Humanize.size(document.getElementById('change_bar_mem_hosts').value); + changeColorInputMEM(maxMEM); + } + + function changeColorInputCPU(maxCPU){ + if(parseInt(document.getElementById('change_bar_cpu_hosts').value) > parseInt(maxCPU)){ + document.getElementById('textInput_reserved_cpu_hosts').style.backgroundColor = 'rgba(111, 220, 111, 0.5)'; + } + else if(parseInt(document.getElementById('change_bar_cpu_hosts').value) < parseInt(maxCPU)){ + document.getElementById('textInput_reserved_cpu_hosts').style.backgroundColor = 'rgba(255, 80, 80, 0.5)'; + } else { + document.getElementById('textInput_reserved_cpu_hosts').style.backgroundColor = 'white'; + } + } + + function changeColorInputMEM(maxMEM){ + if(parseInt(document.getElementById('change_bar_mem_hosts').value) > parseInt(maxMEM)){ + document.getElementById('textInput_reserved_mem_hosts').style.backgroundColor = 'rgba(111, 220, 111, 0.5)'; + } + else if(parseInt(document.getElementById('change_bar_mem_hosts').value) < parseInt(maxMEM)){ + document.getElementById('textInput_reserved_mem_hosts').style.backgroundColor = 'rgba(255, 80, 80, 0.5)'; + } else { + document.getElementById('textInput_reserved_mem_hosts').style.backgroundColor = 'white'; + } } function _setup(context) { @@ -172,21 +196,19 @@ define(function(require) { Sunstone.runAction("Host.append_template", that.element.ID, TemplateUtils.templateToString(obj)); }); - document.getElementById("change_bar_cpu_hosts").addEventListener("change", function(){ - if(parseInt(document.getElementById('change_bar_cpu_hosts').value) > that.element.HOST_SHARE.TOTAL_CPU) - document.getElementById('textInput_reserved_cpu_hosts').style.backgroundColor = 'rgba(111, 220, 111,0.5)'; - if(parseInt(document.getElementById('change_bar_cpu_hosts').value) < that.element.HOST_SHARE.TOTAL_CPU) - document.getElementById('textInput_reserved_cpu_hosts').style.backgroundColor = 'rgba(255, 80, 80,0.5)'; + document.getElementById("change_bar_cpu_hosts").addEventListener("input", function(){ + changeColorInputCPU(that.element.HOST_SHARE.TOTAL_CPU); document.getElementById('textInput_reserved_cpu_hosts').value = document.getElementById('change_bar_cpu_hosts').value; }); - document.getElementById("textInput_reserved_cpu_hosts").addEventListener("change", changeInputCPU); - document.getElementById("change_bar_mem_hosts").addEventListener("change", function(){ - if(parseInt(document.getElementById('change_bar_mem_hosts').value) > that.element.HOST_SHARE.TOTAL_MEM) - document.getElementById('textInput_reserved_mem_hosts').style.backgroundColor = 'rgba(111, 220, 111,0.5)'; - if(parseInt(document.getElementById('change_bar_mem_hosts').value) < that.element.HOST_SHARE.TOTAL_MEM) - document.getElementById('textInput_reserved_mem_hosts').style.backgroundColor = 'rgba(255, 80, 80,0.5)'; + document.getElementById("textInput_reserved_cpu_hosts").addEventListener("input", function(){ + changeInputCPU(that.element.HOST_SHARE.TOTAL_CPU); + }); + document.getElementById("change_bar_mem_hosts").addEventListener("input", function(){ + changeColorInputMEM(that.element.HOST_SHARE.TOTAL_MEM); document.getElementById('textInput_reserved_mem_hosts').value = Humanize.size(parseInt(document.getElementById('change_bar_mem_hosts').value)); }); - document.getElementById("textInput_reserved_mem_hosts").addEventListener("change", changeInputMEM); + document.getElementById("textInput_reserved_mem_hosts").addEventListener("input", function(){ + changeInputMEM(that.element.HOST_SHARE.TOTAL_MEM); + }); } });