lmc/images/delete/delete.js

86 lines
2.3 KiB
JavaScript

/*
* 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 <https://www.gnu.org/licenses/>.
*/
import { settings, elements, apiGet, apiDelete, parseParams, setupHeader, timeString } from "/global.js";
(function()
{
// Element names specific to this page
elements.deleteButton = "delete-button";
elements.label = "label";
elements.nav = "navlink";
elements.navActive = "navlink-active";
// Data recieved from API calls
var data = {};
// Static references to UI elements
var ui = {};
ui.deleteButton = {};
ui.label = {};
// Callback for image API call
var displayImage = function(response)
{
ui.label.innerHTML = response.label;
};
// Handler for delete button
var handleDelete = function(event)
{
apiDelete("/images/" + data.params.iid, function(response)
{
location.href = "/images";
});
};
// Initial setup
var setup = function()
{
// Parse URL parameters
data.params = parseParams();
// We need an image ID, so die if we don't have it
if (!data.params.iid) {
alert("No image ID supplied!");
return;
}
setupHeader();
// Highlight the Linodes nav link
var navLinks = document.getElementsByClassName(elements.nav);
for (var i = 0; i < navLinks.length; i++) {
if (navLinks[i].pathname == "/linodes/")
navLinks[i].className = elements.navActive;
}
// Get element references
ui.deleteButton = document.getElementById(elements.deleteButton);
ui.label = document.getElementById(elements.label);
// Attach event handlers
ui.deleteButton.addEventListener("click", handleDelete);
// Get data from API
apiGet("/images/" + data.params.iid, displayImage, null);
};
// Attach onload handler
window.addEventListener("load", setup);
})();