Added Account section
This commit is contained in:
55
account/paymentreceiptyear/index.shtml
Normal file
55
account/paymentreceiptyear/index.shtml
Normal file
@ -0,0 +1,55 @@
|
||||
<!--
|
||||
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 // View Payments in</title>
|
||||
<link rel="shortcut icon" type="image/x-icon" href="/favicon.ico" />
|
||||
<link rel="stylesheet" type="text/css" href="paymentreceiptyear.css" />
|
||||
<script src="paymentreceiptyear.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="paymentreceiptyear">
|
||||
<table class="lmc-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<td colspan="3">Payment(s) in <span id="year"></span></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Description</td>
|
||||
<td>Date</td>
|
||||
<td>Amount</td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="payments-body">
|
||||
<tr id="loading" class="lmc-tr1">
|
||||
<td colspan="3">Loading...</td>
|
||||
</tr>
|
||||
<tr id="no-payments" class="lmc-tr1">
|
||||
<td colspan="3">No payments to display.</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<p>Payment Total: <span id="total"></span></p>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
40
account/paymentreceiptyear/paymentreceiptyear.css
Normal file
40
account/paymentreceiptyear/paymentreceiptyear.css
Normal file
@ -0,0 +1,40 @@
|
||||
/*
|
||||
* 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');
|
||||
|
||||
.lmc-table tbody:not(.lmc-tbody-head) tr:last-of-type {
|
||||
border-bottom: 1px solid #E8E8E8;
|
||||
}
|
||||
|
||||
#no-payments {
|
||||
display: none;
|
||||
}
|
||||
|
||||
#paymentreceiptyear {
|
||||
padding: 15px 15px 15px;
|
||||
}
|
||||
|
||||
#paymentreceiptyear p {
|
||||
font-size: 13px;
|
||||
font-weight: bold;
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
table td:nth-of-type(3) {
|
||||
text-align: right;
|
||||
}
|
146
account/paymentreceiptyear/paymentreceiptyear.js
Normal file
146
account/paymentreceiptyear/paymentreceiptyear.js
Normal file
@ -0,0 +1,146 @@
|
||||
/*
|
||||
* 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, parseParams, setupHeader } from "/global.js";
|
||||
|
||||
(function()
|
||||
{
|
||||
// Element names specific to this page
|
||||
elements.lmcRow = "lmc-tr1";
|
||||
elements.lmcRowAlt = "lmc-tr2";
|
||||
elements.loading = "loading";
|
||||
elements.noPayments = "no-payments";
|
||||
elements.paymentsBody = "payments-body";
|
||||
elements.subnav = "subnav-link";
|
||||
elements.subnavActive = "subnav-link-active";
|
||||
elements.total = "total";
|
||||
elements.year = "year";
|
||||
|
||||
// Data received from API calls
|
||||
var data = {};
|
||||
data.payments = [];
|
||||
|
||||
// Static references to UI elements
|
||||
var ui = {};
|
||||
ui.loading = {};
|
||||
ui.noPayments = {};
|
||||
ui.paymentsBody = {};
|
||||
ui.total = {};
|
||||
ui.year = {};
|
||||
|
||||
// Generate a payment table row
|
||||
var createPaymentRow = function(payment, alt)
|
||||
{
|
||||
var row = document.createElement("tr");
|
||||
if (alt)
|
||||
row.className = elements.lmcRowAlt;
|
||||
else
|
||||
row.className = elements.lmcRow;
|
||||
|
||||
var description = document.createElement("td");
|
||||
description.innerHTML = "Payment. Thank you.";
|
||||
row.appendChild(description);
|
||||
|
||||
var date = document.createElement("td");
|
||||
var paymentDate = new Date(payment.date + "Z");
|
||||
date.innerHTML = paymentDate.toLocaleDateString();
|
||||
row.appendChild(date);
|
||||
|
||||
var amount = document.createElement("td");
|
||||
amount.innerHTML = "$" + payment.usd.toFixed(2);
|
||||
row.appendChild(amount);
|
||||
|
||||
return row;
|
||||
};
|
||||
|
||||
// Callback for payments API call
|
||||
var displayPayments = function(response)
|
||||
{
|
||||
// Only add payments from the specified year
|
||||
var year = parseInt(data.params.year);
|
||||
for (var i = 0; i < response.data.length; i++) {
|
||||
var paymentDate = new Date(response.data[i].date + "Z");
|
||||
if (paymentDate.getFullYear() == year)
|
||||
data.payments.push(response.data[i]);
|
||||
}
|
||||
|
||||
// Request the next page if there are more
|
||||
if (response.page != response.pages) {
|
||||
apiGet("/account/payments?page=" + (response.page + 1), displayPayments, null);
|
||||
return;
|
||||
}
|
||||
|
||||
ui.loading.remove();
|
||||
if (!data.payments.length) {
|
||||
ui.noPayments.style.display = "table-row";
|
||||
return;
|
||||
}
|
||||
|
||||
// Insert payments into table
|
||||
var total = 0.0;
|
||||
for (var i = 0; i < data.payments.length; i++) {
|
||||
total += data.payments[i].usd;
|
||||
ui.paymentsBody.appendChild(createPaymentRow(data.payments[i], i % 2));
|
||||
}
|
||||
|
||||
ui.total.innerHTML = "$" + total.toFixed(2);
|
||||
};
|
||||
|
||||
// Initial setup
|
||||
var setup = function()
|
||||
{
|
||||
// Parse URL parameters
|
||||
data.params = parseParams();
|
||||
|
||||
// We need a year, so die if we don't have it
|
||||
if (!data.params.year) {
|
||||
alert("No payment ID supplied!");
|
||||
return;
|
||||
} else if (!parseInt(data.params.year)) {
|
||||
alert("Supplied year is invalid!");
|
||||
return;
|
||||
}
|
||||
|
||||
setupHeader();
|
||||
|
||||
// Highlight the remote access subnav link
|
||||
var subnavLinks = document.getElementsByClassName(elements.subnav);
|
||||
for (var i = 0; i < subnavLinks.length; i++) {
|
||||
if (subnavLinks[i].pathname == "/account/billing_history")
|
||||
subnavLinks[i].className = elements.subnav + " " + elements.subnavActive;
|
||||
else
|
||||
subnavLinks[i].className = elements.subnav;
|
||||
}
|
||||
|
||||
// Get element references
|
||||
ui.loading = document.getElementById(elements.loading);
|
||||
ui.noPayments = document.getElementById(elements.noPayments);
|
||||
ui.paymentsBody = document.getElementById(elements.paymentsBody);
|
||||
ui.total = document.getElementById(elements.total);
|
||||
ui.year = document.getElementById(elements.year);
|
||||
|
||||
// Set year
|
||||
var year = parseInt(data.params.year);
|
||||
ui.year.innerHTML = year;
|
||||
|
||||
// Get data from API
|
||||
apiGet("/account/payments", displayPayments, null);
|
||||
};
|
||||
|
||||
// Attach onload handler
|
||||
window.addEventListener("load", setup);
|
||||
})();
|
Reference in New Issue
Block a user