lmc/profile/referrals/referrals.js

76 lines
2.2 KiB
JavaScript
Raw Permalink Normal View History

/*
* 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.code = "code";
elements.completed = "completed";
elements.dollars = "dollars";
elements.pending = "pending";
elements.total = "total";
elements.url = "url";
// Data received from API calls
var data = {};
// Static references to UI elements
var ui = {};
ui.code = {};
ui.completed = {};
ui.dollars = {};
ui.pending = {};
ui.total = {};
ui.url = {};
// Callback for profile API call
var displayProfile = function(response)
{
ui.code.innerHTML = response.referrals.code;
ui.url.innerHTML = response.referrals.url;
ui.total.innerHTML = response.referrals.total;
ui.completed.innerHTML = response.referrals.completed;
ui.dollars.innerHTML = response.referrals.credit.toFixed(2);
ui.pending.innerHTML = response.referrals.pending;
};
// Initial setup
var setup = function()
{
// Parse URL parameters
data.params = parseParams();
setupHeader();
// Get element references
ui.code = document.getElementById(elements.code);
ui.completed = document.getElementById(elements.completed);
ui.dollars = document.getElementById(elements.dollars);
ui.pending = document.getElementById(elements.pending);
ui.total = document.getElementById(elements.total);
ui.url = document.getElementById(elements.url);
// Get data from API
apiGet("/profile", displayProfile, null);
};
// Attach onload handler
window.addEventListener("load", setup);
})();