lmc/account/cancel/cancel.js

75 lines
1.9 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, apiPost, parseParams, setupHeader } from "/global.js";
(function()
{
// Element names specific to this page
elements.cancelButton = "cancel-button";
elements.confirm = "confirm";
elements.reason = "reason";
// Data received from API calls
var data = {};
// Static references to UI elements
var ui = {};
ui.cancelButton = {};
ui.confirm = {};
ui.reason = {};
// Click handler for cancel button
var handleCancel = function(event)
{
if (!ui.confirm.checked)
return;
var req = {
"comments": ui.reason.value
};
apiPost("/account/cancel", req, function(response)
{
if (response.survey_link)
location.href = response.survey_link;
else
location.href = "/logout";
});
};
// Initial setup
var setup = function()
{
// Parse URL parameters
data.params = parseParams();
setupHeader();
// Get element references
ui.cancelButton = document.getElementById(elements.cancelButton);
ui.confirm = document.getElementById(elements.confirm);
ui.reason = document.getElementById(elements.reason);
// Attach event handlers
ui.cancelButton.addEventListener("click", handleCancel);
};
// Attach onload handler
window.addEventListener("load", setup);
})();