Get region names from API instead of hard-coding them

This commit is contained in:
2024-05-06 16:57:12 -04:00
parent 4c4db6a734
commit 8ea657c757
21 changed files with 333 additions and 107 deletions
+14 -3
View File
@@ -15,13 +15,14 @@
* along with Linode Manager Classic. If not, see <https://www.gnu.org/licenses/>.
*/
import { settings, elements, apiGet, apiPost, parseParams, regionNames, setupHeader } from "/global.js";
import { settings, elements, apiGet, apiPost, countryContinents, parseParams, regionNames, setupHeader } from "/global.js";
(function()
{
// Element names specific to this page
elements.addButton = "add-button";
elements.attachment = "attachment";
elements.dcOther = "dc-other";
elements.label = "label";
elements.location = "location";
elements.size = "size";
@@ -35,6 +36,7 @@ import { settings, elements, apiGet, apiPost, parseParams, regionNames, setupHea
var ui = {};
ui.addButton = {};
ui.attachment = {};
ui.dcOther = {};
ui.label = {};
ui.location = {};
ui.size = {};
@@ -90,11 +92,19 @@ import { settings, elements, apiGet, apiPost, parseParams, regionNames, setupHea
for (var i = 0; i < data.regions.length; i++) {
var loc = document.createElement("option");
loc.value = data.regions[i].id;
if (regionNames[data.regions[i].id])
if (data.regions[i].label && data.regions[i].label.length)
loc.innerHTML = data.regions[i].label;
else if (regionNames[data.regions[i].id])
loc.innerHTML = regionNames[data.regions[i].id];
else
loc.innerHTML = data.regions[i].id;
ui.location.appendChild(loc);
var optgroup = null;
if (countryContinents[data.regions[i].country])
optgroup = document.getElementById(countryContinents[data.regions[i].country]);
if (!optgroup)
optgroup = ui.dcOther;
optgroup.style.display = "initial";
optgroup.appendChild(loc);
}
// Request linodes in all the supported regions
@@ -180,6 +190,7 @@ import { settings, elements, apiGet, apiPost, parseParams, regionNames, setupHea
// Get element references
ui.addButton = document.getElementById(elements.addButton);
ui.attachment = document.getElementById(elements.attachment);
ui.dcOther = document.getElementById(elements.dcOther);
ui.label = document.getElementById(elements.label);
ui.location = document.getElementById(elements.location);
ui.size = document.getElementById(elements.size);