Added Account section
This commit is contained in:
30
account/backups_enable_all/backups_enable_all.css
Normal file
30
account/backups_enable_all/backups_enable_all.css
Normal file
@ -0,0 +1,30 @@
|
||||
/*
|
||||
* 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 url('/global.css');
|
||||
|
||||
#backups-enable-all {
|
||||
padding: 15px 15px 15px;
|
||||
}
|
||||
|
||||
h2 {
|
||||
font-size: 18px;
|
||||
}
|
||||
|
||||
.info {
|
||||
font-size: 12px;
|
||||
}
|
179
account/backups_enable_all/backups_enable_all.js
Normal file
179
account/backups_enable_all/backups_enable_all.js
Normal file
@ -0,0 +1,179 @@
|
||||
/*
|
||||
* 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, apiPost, parseParams, setupHeader } from "/global.js";
|
||||
|
||||
(function()
|
||||
{
|
||||
// Element names specific to this page
|
||||
elements.cost = "cost";
|
||||
elements.doIt = "doit";
|
||||
elements.linodeCount = "linode-count";
|
||||
elements.subnav = "subnav-link";
|
||||
elements.subnavActive = "subnav-link-active";
|
||||
|
||||
// Data received from API calls
|
||||
var data = {};
|
||||
data.linodes = [];
|
||||
data.plans = {};
|
||||
|
||||
// Static references to UI elements
|
||||
var ui = {};
|
||||
ui.cost = {};
|
||||
ui.dotIt = {};
|
||||
ui.linodeCount = [];
|
||||
|
||||
// Temporary state
|
||||
var state = {};
|
||||
state.haveLinodes = false;
|
||||
state.havePlans = false;
|
||||
state.numResponses = 0;
|
||||
state.numRequests = 0;
|
||||
|
||||
// Computes and displays the total monthly cost
|
||||
var displayCost = function()
|
||||
{
|
||||
var cost = 0;
|
||||
var haveAll = true;
|
||||
for (var i = 0; i < data.linodes.length; i++) {
|
||||
if (data.linodes[i].backups.enabled)
|
||||
continue;
|
||||
|
||||
if (!data.plans[data.linodes[i].type]) {
|
||||
haveAll = false;
|
||||
apiGet("/linode/types/" + data.linodes[i].type, function(response)
|
||||
{
|
||||
data.plans[response.id] = response;
|
||||
displayCost();
|
||||
}, null);
|
||||
continue;
|
||||
}
|
||||
|
||||
cost += data.plans[data.linodes[i].type].addons.backups.price.monthly;
|
||||
}
|
||||
|
||||
if (haveAll) {
|
||||
ui.cost.innerHTML = cost.toFixed(2);
|
||||
ui.doIt.disabled = false;
|
||||
}
|
||||
};
|
||||
|
||||
// Callback for linodes API call
|
||||
var displayLinodes = function(response)
|
||||
{
|
||||
data.linodes = data.linodes.concat(response.data);
|
||||
|
||||
// Request the next page if there are more
|
||||
if (response.page != response.pages) {
|
||||
apiGet("/linode/instances?page=" + (response.page + 1), displayLinodes, null);
|
||||
return;
|
||||
}
|
||||
|
||||
state.haveLinodes = true;
|
||||
|
||||
// Display count of linodes without backups
|
||||
var count = 0;
|
||||
for (var i = 0; i < data.linodes.length; i++) {
|
||||
if (!data.linodes[i].backups.enabled)
|
||||
count++;
|
||||
}
|
||||
|
||||
// If there are no linodes without backups, go back
|
||||
if (!count)
|
||||
location.href = "/account/settings";
|
||||
|
||||
for (var i = 0; i < ui.linodeCount.length; i++)
|
||||
ui.linodeCount[i].innerHTML = count;
|
||||
|
||||
if (state.havePlans)
|
||||
displayCost();
|
||||
};
|
||||
|
||||
// Callback for plans API call
|
||||
var displayPlans = function(response)
|
||||
{
|
||||
for (var i = 0; i < response.data.length; i++)
|
||||
data.plans[response.data[i].id] = response.data[i];
|
||||
|
||||
// Request the next page if there are more
|
||||
if (response.page != response.pages) {
|
||||
apiGet("/linode/types?page=" + (response.page + 1), displayPlans, null);
|
||||
return;
|
||||
}
|
||||
|
||||
state.havePlans = true;
|
||||
|
||||
if (state.haveLinode)
|
||||
displayCost();
|
||||
};
|
||||
|
||||
// Click handler for enable button
|
||||
var doIt = function(event)
|
||||
{
|
||||
if (event.currentTarget.disabled)
|
||||
return;
|
||||
|
||||
// Enable backups for each linode without backups
|
||||
for (var i = 0; i < data.linodes.length; i++) {
|
||||
if (data.linodes[i].backups.enabled)
|
||||
continue;
|
||||
|
||||
state.numRequests++;
|
||||
apiPost("/linode/instances/" + data.linodes[i].id + "/backups/enable", {}, function(response)
|
||||
{
|
||||
state.numResponses++;
|
||||
if (state.numResponses >= state.numRequests)
|
||||
location.href = "/account/settings";
|
||||
});
|
||||
}
|
||||
|
||||
ui.doIt.disabled = true;
|
||||
};
|
||||
|
||||
// Initial setup
|
||||
var setup = function()
|
||||
{
|
||||
// Parse URL parameters
|
||||
data.params = parseParams();
|
||||
|
||||
setupHeader();
|
||||
|
||||
// Highlight the account settings subnav link
|
||||
var subnavLinks = document.getElementsByClassName(elements.subnav);
|
||||
for (var i = 0; i < subnavLinks.length; i++) {
|
||||
if (subnavLinks[i].pathname == "/account/settings")
|
||||
subnavLinks[i].className = elements.subnav + " " + elements.subnavActive;
|
||||
else
|
||||
subnavLinks[i].className = elements.subnav;
|
||||
}
|
||||
|
||||
// Get element references
|
||||
ui.cost = document.getElementById(elements.cost);
|
||||
ui.doIt = document.getElementById(elements.doIt);
|
||||
ui.linodeCount = document.getElementsByClassName(elements.linodeCount);
|
||||
|
||||
// Attach event handlers
|
||||
ui.doIt.addEventListener("click", doIt);
|
||||
|
||||
// Get data from the API
|
||||
apiGet("/linode/instances", displayLinodes, null);
|
||||
apiGet("/linode/types", displayPlans, null);
|
||||
};
|
||||
|
||||
// Attach onload handler
|
||||
window.addEventListener("load", setup);
|
||||
})();
|
39
account/backups_enable_all/index.shtml
Normal file
39
account/backups_enable_all/index.shtml
Normal file
@ -0,0 +1,39 @@
|
||||
<!--
|
||||
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/>.
|
||||
-->
|
||||
<!DOCTYPE HTML>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<title>LMC - Account // Enable Backups for All Linodes</title>
|
||||
<link rel="shortcut icon" type="image/x-icon" href="/favicon.ico" />
|
||||
<link rel="stylesheet" type="text/css" href="backups_enable_all.css" />
|
||||
<script src="backups_enable_all.js" type="module"></script>
|
||||
</head>
|
||||
<body>
|
||||
<!--#include virtual="/include/header.html"-->
|
||||
<!--#include virtual="/include/account_subnav.html"-->
|
||||
<div id="main-content" class="wrapper">
|
||||
<div id="backups-enable-all">
|
||||
<h2>Backup Enrollment</h2>
|
||||
<p>This will enable the Linode Backup Service for <strong><span class="linode-count"></span></strong> Linodes, for a total additional cost of <strong>$<span id="cost"></span></strong>/month.</p>
|
||||
<p>Are you sure you want to do this?</p>
|
||||
<p class="info">The cost of the Linode Backup Service for each Linode plan is listed on the <a href="https://www.linode.com/products/backups" target="_blank">Backups info page</a>.</p>
|
||||
<button disabled id="doit" type="button">Yes, I want to enable Backups for <span class="linode-count"></span> Linodes</button>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
Reference in New Issue
Block a user