117 lines
3.5 KiB
JavaScript
117 lines
3.5 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, apiGet, apiPost, parseParams, setupHeader } from "/global.js";
|
|
|
|
(function()
|
|
{
|
|
// Element names specific to this page
|
|
elements.addButton = "add-button";
|
|
elements.label = "label";
|
|
elements.linodeLabel = "linode-label";
|
|
elements.linodeTag = "linode-tag";
|
|
elements.linodeTagLink = "linode-tag-link";
|
|
elements.subnav = "subnav-link";
|
|
elements.subnavActive = "subnav-link-active";
|
|
|
|
// Data recieved from API calls
|
|
var data = {};
|
|
data.linode = {};
|
|
|
|
// Static references to UI elements
|
|
var ui = {};
|
|
ui.addButton = {};
|
|
ui.label = {};
|
|
ui.linodeLabel = {};
|
|
ui.linodeTag = {};
|
|
ui.linodeTagLink = {};
|
|
|
|
// Callback for linode details API call
|
|
var displayDetails = function(response)
|
|
{
|
|
data.linode = response;
|
|
|
|
// Set page title and header stuff
|
|
document.title += " // " + data.linode.label;
|
|
ui.linodeLabel.innerHTML = data.linode.label;
|
|
ui.label.innerHTML = data.linode.label;
|
|
if (data.linode.tags.length == 1) {
|
|
ui.linodeTagLink.href = "/linodes?tag=" + data.linode.tags[0];
|
|
ui.linodeTagLink.innerHTML = "(" + data.linode.tags[0] + ")";
|
|
ui.linodeTag.style.display = "inline";
|
|
}
|
|
};
|
|
|
|
// Handler for add button
|
|
var handleAdd = function(event)
|
|
{
|
|
if (event.currentTarget.disabled)
|
|
return;
|
|
|
|
var req = {
|
|
"public": false,
|
|
"type": "ipv4"
|
|
};
|
|
apiPost("/linode/instances/" + data.params.lid + "/ips", req, function(response) {
|
|
location.href = "/linodes/remote_access?lid=" + data.params.lid;
|
|
});
|
|
};
|
|
|
|
// Initial setup
|
|
var setup = function()
|
|
{
|
|
// Parse URL parameters
|
|
data.params = parseParams();
|
|
|
|
// We need a Linode ID, so die if we don't have it
|
|
if (!data.params.lid) {
|
|
alert("No Linode ID supplied!");
|
|
return;
|
|
}
|
|
|
|
setupHeader();
|
|
|
|
// Update links on page to include proper Linode ID
|
|
var anchors = document.getElementsByTagName("a");
|
|
for (var i = 0; i < anchors.length; i++)
|
|
anchors[i].href = anchors[i].href.replace("lid=0", "lid=" + data.params.lid);
|
|
|
|
// Highlight the remote access subnav link
|
|
var subnavLinks = document.getElementsByClassName(elements.subnav);
|
|
for (var i = 0; i < subnavLinks.length; i++) {
|
|
if (subnavLinks[i].pathname == "/linodes/remote_access")
|
|
subnavLinks[i].className += " " + elements.subnavActive;
|
|
}
|
|
|
|
// Get element references
|
|
ui.addButton = document.getElementById(elements.addButton);
|
|
ui.label = document.getElementById(elements.label);
|
|
ui.linodeLabel = document.getElementById(elements.linodeLabel);
|
|
ui.linodeTag = document.getElementById(elements.linodeTag);
|
|
ui.linodeTagLink = document.getElementById(elements.linodeTagLink);
|
|
|
|
// Attach event handlers
|
|
ui.addButton.addEventListener("click", handleAdd);
|
|
|
|
// Get data from API
|
|
apiGet("/linode/instances/" + data.params.lid, displayDetails, null);
|
|
};
|
|
|
|
// Attach onload handler
|
|
window.addEventListener("load", setup);
|
|
})();
|