lmc/profile/ssh/remove/remove.js

81 lines
2.1 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, apiDelete, apiGet, parseParams, setupHeader } from "/global.js";
(function()
{
// Element names specific to this page
elements.label = "label";
elements.removeButton = "remove-button";
// Data received from API calls
var data = {};
// Static references to UI elements
var ui = {};
ui.label = {};
ui.removeButton = {};
// Callback for key API call
var displayKey = function(response)
{
ui.label.innerHTML = response.label;
ui.removeButton.disabled = false;
};
// Click handler for remove button
var handleRemove = function(event)
{
if (event.currentTarget.disabled)
return;
apiDelete("/profile/sshkeys/" + data.params.kid, function(response)
{
location.href = "/profile/ssh";
});
};
// Initial setup
var setup = function()
{
// Parse URL parameters
data.params = parseParams();
// We need a key ID, so die if we don't have it
if (!data.params.kid) {
alert("No key ID supplied!");
return;
}
setupHeader();
// Get element references
ui.label = document.getElementById(elements.label);
ui.removeButton = document.getElementById(elements.removeButton);
// Register event handlers
ui.removeButton.addEventListener("click", handleRemove);
// Get data from API
apiGet("/profile/sshkeys/" + data.params.kid, displayKey, null);
};
// Attach onload handler
window.addEventListener("load", setup);
})();