/* * This file is part of Linode Manager Classic. * * Linode Manager Classic is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Linode Manager Classic is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Linode Manager Classic. If not, see . */ import { settings, elements, apiGet, apiPost, parseParams, setupHeader } from "/global.js"; (function() { // Element names specific to this page elements.cloneButton = "clone-button"; elements.existingDomain = "existing-domain"; elements.newDomain = "new-domain"; // Data recieved from API calls var data = {}; // Static references to UI elements var ui = {}; ui.cloneButton = {}; ui.existingDomain = {}; ui.newDomain = {}; // Callback for domains API call var displayDomains = function(response) { // Add domains to selector for (var i = 0; i < response.data.length; i++) { var domain = document.createElement("option"); domain.value = response.data[i].id; domain.innerHTML = response.data[i].domain; ui.existingDomain.appendChild(domain); } // Request the next page if there are more pages if (response.page != response.pages) apiGet("/domains?page=" + (response.page + 1), displayDomains, null); else ui.cloneButton.disabled = false; }; // Click handler for clone button var handleClone = function(event) { if (event.currentTarget.disabled) return; // This request takes a few seconds ui.cloneButton.disabled = true; var req = { "domain": ui.newDomain.value }; apiPost("/domains/" + ui.existingDomain.value + "/clone", req, function(response) { location.href = "/dns/domain?did=" + response.id; }); }; // Initial setup var setup = function() { // Parse URL parameters data.params = parseParams(); setupHeader(); // Get element references ui.cloneButton = document.getElementById(elements.cloneButton); ui.existingDomain = document.getElementById(elements.existingDomain); ui.newDomain = document.getElementById(elements.newDomain); // Attach event handlers ui.cloneButton.addEventListener("click", handleClone); // Get data from API apiGet("/domains", displayDomains, null); }; // Attach onload handler window.addEventListener("load", setup); })();