From d62ea951ea6d222813ed6a27bcdc84ff188e6aa6 Mon Sep 17 00:00:00 2001 From: Robert Bartel Date: Thu, 22 Aug 2024 16:31:08 -0400 Subject: [PATCH] Moving to independent "let" use in domain.js. Switching from use of var and combined declarations; also refactoring a few variable names for clarity, per suggestions. --- python/gui/MaaS/static/common/js/domain.js | 104 ++++++++++----------- 1 file changed, 51 insertions(+), 53 deletions(-) diff --git a/python/gui/MaaS/static/common/js/domain.js b/python/gui/MaaS/static/common/js/domain.js index 640361d26..ad558dad9 100644 --- a/python/gui/MaaS/static/common/js/domain.js +++ b/python/gui/MaaS/static/common/js/domain.js @@ -48,22 +48,24 @@ function loadFabricTypes() { } function insertOptionInOrder(option, newParentSelect) { - var next_i, i = 0, next_size = 200; + let next_index; + let current_index = 0; + let next_size = 200; - next_i = i + next_size; - while (next_i < newParentSelect.options.length) { - if (parseInt(option.value) < parseInt(newParentSelect.options[next_i].value)) { + next_index = current_index + next_size; + while (next_index < newParentSelect.options.length) { + if (parseInt(option.value) < parseInt(newParentSelect.options[next_index].value)) { break; } else { - i = next_i; - next_i = i + next_size; + current_index = next_index; + next_index = current_index + next_size; } } - for (i; i < newParentSelect.options.length; i++) { - if (parseInt(option.value) < parseInt(newParentSelect.options[i].value)) { - newParentSelect.options.add(option, newParentSelect.options[i]); + for (current_index; current_index < newParentSelect.options.length; current_index++) { + if (parseInt(option.value) < parseInt(newParentSelect.options[current_index].value)) { + newParentSelect.options.add(option, newParentSelect.options[current_index]); return; } } @@ -71,20 +73,21 @@ function insertOptionInOrder(option, newParentSelect) { } function addDomainChoicesOption(values) { - var select = document.getElementById('domainChoices'); - for (var i = 0; i < values.length; i++) { - var option = document.createElement('option'); - option.value = values[i].substring(4); - option.innerHTML = values[i]; + let select = document.getElementById('domainChoices'); + for (let optionIndex = 0; optionIndex < values.length; optionIndex++) { + const option = document.createElement('option'); + option.value = values[optionIndex].substring(4); + option.innerHTML = values[optionIndex]; insertOptionInOrder(option, select); } } function controlSelectAdd() { - var choices = document.getElementById('domainChoices'), - selected = document.getElementById('domainSelections'); - for (var i = choices.options.length - 1; i >=0; i--) { - var opt = choices.options[i]; + let choices = document.getElementById('domainChoices'); + let selected = document.getElementById('domainSelections'); + + for (let optionIndex = choices.options.length - 1; optionIndex >=0; optionIndex--) { + let opt = choices.options[optionIndex]; if (opt.selected) { opt.selected = false; choices.removeChild(opt); @@ -94,12 +97,12 @@ function controlSelectAdd() { } function controlSelectRemove() { - var choices = document.getElementById('domainChoices'), + let choices = document.getElementById('domainChoices'), selected = document.getElementById('domainSelections'), - i, opt; - for (i = selected.options.length - 1; i >=0; i--) { - opt = selected.options[i]; + + for (let optionIndex = selected.options.length - 1; optionIndex >=0; optionIndex--) { + opt = selected.options[optionIndex]; if (opt.selected) { opt.selected = false; selected.removeChild(opt); @@ -109,12 +112,12 @@ function controlSelectRemove() { } function controlSelectAll() { - var choices = document.getElementById('domainChoices'), - selected = document.getElementById('domainSelections'), - i, - opt; - for (i = choices.options.length - 1; i >= 0 ; i--) { - opt = choices.options[i]; + let choices = document.getElementById('domainChoices'); + let selected = document.getElementById('domainSelections'); + let opt; + + for (let optionIndex = choices.options.length - 1; optionIndex >= 0 ; optionIndex--) { + opt = choices.options[optionIndex]; if (opt.selected) { opt.selected = false; } @@ -124,12 +127,12 @@ function controlSelectAll() { } function controlSelectClear() { - var choices = document.getElementById('domainChoices'), - selected = document.getElementById('domainSelections'), - i, - opt; - for (i = selected.options.length - 1; i >= 0 ; i--) { - opt = selected.options[i]; + let choices = document.getElementById('domainChoices'); + let selected = document.getElementById('domainSelections'); + let opt; + + for (let optionIndex = selected.options.length - 1; optionIndex >= 0 ; optionIndex--) { + opt = selected.options[optionIndex]; if (opt.selected) { opt.selected = false; } @@ -139,14 +142,11 @@ function controlSelectClear() { } function loadFabricDomain(event) { - var name = $("#fabric-selector").val(), - type = "catchment", //$("#fabric-type-selector").val(), - catLists = [document.getElementById('domainChoices'), - document.getElementById('domainSelections')], - loadingOverDiv = document.getElementById('loadCatsOverlay'), - select, - l, - i; + let name = $("#fabric-selector").val(); + let type = "catchment"; //$("#fabric-type-selector").val(), + let catLists = [document.getElementById('domainChoices'), + document.getElementById('domainSelections')]; + let loadingOverDiv = document.getElementById('loadCatsOverlay'); catLists[0].style.display = "none"; loadingOverDiv.style.display = "block"; @@ -154,14 +154,13 @@ function loadFabricDomain(event) { $("input[name=fabric]").val(name); // Clear any existing