lmc/user/remove/remove.js

90 lines
2.6 KiB
JavaScript
Raw Normal View History

2020-03-13 23:01:39 -04:00
/*
* 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, parseParams, setupHeader } from "/global.js";
(function()
{
// Element names specific to this page
elements.cancelButton = "cancel-button";
elements.deleteButton = "delete-button";
elements.topUserLink = "top-user-link";
2020-03-13 23:01:39 -04:00
elements.userLabel = "user-label";
// Data received from API calls
var data = {};
// Static references to UI elements
var ui = {};
ui.cancelButton = {};
ui.deleteButton = {};
ui.topUserLink = {};
2020-03-13 23:01:39 -04:00
ui.userLabel = {};
// Click handler for delete button
var handleDelete = function(event)
{
apiDelete("/account/users/" + data.params.user, function(response)
{
location.href = "/user";
});
};
// Initial setup
var setup = function()
{
// Parse URL parameters
data.params = parseParams();
// We need a username, so die if we don't have it
if (!data.params.user) {
alert("No username supplied!");
return;
}
setupHeader();
// Highlight the account nav link
var navlinks = document.getElementsByClassName(elements.navlink);
for (var i = 0; i < navlinks.length; i++) {
if (navlinks[i].pathname == "/account/")
navlinks[i].className = " " + elements.navlinkActive;
}
// Get element references
ui.cancelButton = document.getElementById(elements.cancelButton);
ui.deleteButton = document.getElementById(elements.deleteButton);
ui.topUserLink = document.getElementById(elements.topUserLink);
2020-03-13 23:01:39 -04:00
ui.userLabel = document.getElementById(elements.userLabel);
// Populate username where we need it
ui.topUserLink.href = "/user/edit?user=" + data.params.user;
ui.topUserLink.innerHTML = data.params.user;
2020-03-13 23:01:39 -04:00
ui.userLabel.innerHTML = data.params.user;
// Attach event handlers
ui.cancelButton.addEventListener("click", function(event)
{
location.href = "/user";
});
ui.deleteButton.addEventListener("click", handleDelete);
};
// Attach onload handler
window.addEventListener("load", setup);
})();