Initial commit. Implemented OAuth, Linodes, volumes, and images
This commit is contained in:
31
volumes/attach/attach.css
Normal file
31
volumes/attach/attach.css
Normal file
@ -0,0 +1,31 @@
|
||||
/*
|
||||
* 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');
|
||||
|
||||
#attach {
|
||||
padding: 0px 15px 15px;
|
||||
}
|
||||
|
||||
tbody tr td:first-of-type {
|
||||
font-weight: bold;
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
tbody tr:last-of-type {
|
||||
border: none;
|
||||
}
|
132
volumes/attach/attach.js
Normal file
132
volumes/attach/attach.js
Normal file
@ -0,0 +1,132 @@
|
||||
/*
|
||||
* 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.attachButton = "attach-button";
|
||||
elements.label = "label";
|
||||
elements.linode = "linode";
|
||||
elements.volumeLabel = "volume-label";
|
||||
|
||||
// Data recieved from API calls
|
||||
var data = {};
|
||||
data.volume = {};
|
||||
|
||||
// Static references to UI elements
|
||||
var ui = {};
|
||||
ui.attachButton = {};
|
||||
ui.label = {};
|
||||
ui.linode = {};
|
||||
ui.volumeLabel = {};
|
||||
|
||||
// Callback for linodes API call
|
||||
var displayLinodes = function(response)
|
||||
{
|
||||
// Add linodes to selector
|
||||
for (var i = 0; i < response.data.length; i++) {
|
||||
var linode = document.createElement("option");
|
||||
linode.value = response.data[i].id;
|
||||
linode.innerHTML = response.data[i].label;
|
||||
ui.linode.appendChild(linode);
|
||||
}
|
||||
|
||||
// Request the next page if there are more pages
|
||||
if (response.page != response.pages) {
|
||||
var filter = {
|
||||
"region": data.volume.region
|
||||
};
|
||||
apiGet("/linode/instances?page=" + (response.page + 1), displayLinodes, null);
|
||||
return;
|
||||
}
|
||||
|
||||
ui.attachButton.disabled = false;
|
||||
};
|
||||
|
||||
// Callback for volume API call
|
||||
var displayVolume = function(response)
|
||||
{
|
||||
data.volume = response;
|
||||
|
||||
// Redirect to settings if already attached
|
||||
if (data.volume.linode_id)
|
||||
location.href = "/volumes/settings?vid=" + data.params.vid;
|
||||
|
||||
// Set page title and header stuff
|
||||
document.title += " // " + data.volume.label;
|
||||
ui.volumeLabel.innerHTML = data.volume.label;
|
||||
ui.label.innerHTML = data.volume.label;
|
||||
|
||||
// Get linodes in the same DC
|
||||
var filter = {
|
||||
"region": data.volume.region
|
||||
};
|
||||
apiGet("/linode/instances", displayLinodes, filter);
|
||||
};
|
||||
|
||||
// Click handler for attach button
|
||||
var handleAttach = function(event)
|
||||
{
|
||||
if (event.currentTarget.disabled)
|
||||
return;
|
||||
|
||||
var req = {
|
||||
"linode_id": parseInt(ui.linode.value)
|
||||
};
|
||||
apiPost("/volumes/" + data.params.vid + "/attach", req, function(response)
|
||||
{
|
||||
location.href = "/linodes/dashboard?lid=" + response.linode_id;
|
||||
});
|
||||
};
|
||||
|
||||
// Initial setup
|
||||
var setup = function()
|
||||
{
|
||||
// Parse URL parameters
|
||||
data.params = parseParams();
|
||||
|
||||
// We need a volume ID, so die if we don't have it
|
||||
if (!data.params.vid) {
|
||||
alert("No volume ID supplied!");
|
||||
return;
|
||||
}
|
||||
|
||||
setupHeader();
|
||||
|
||||
// Update links on page to include proper volume ID
|
||||
var anchors = document.getElementsByTagName("a");
|
||||
for (var i = 0; i < anchors.length; i++)
|
||||
anchors[i].href = anchors[i].href.replace("vid=0", "vid=" + data.params.vid);
|
||||
|
||||
// Get element references
|
||||
ui.attachButton = document.getElementById(elements.attachButton);
|
||||
ui.label = document.getElementById(elements.label);
|
||||
ui.linode = document.getElementById(elements.linode);
|
||||
ui.volumeLabel = document.getElementById(elements.volumeLabel);
|
||||
|
||||
// Attach event handlers
|
||||
ui.attachButton.addEventListener("click", handleAttach);
|
||||
|
||||
// Get data from API
|
||||
apiGet("/volumes/" + data.params.vid, displayVolume, null);
|
||||
};
|
||||
|
||||
// Attach onload handler
|
||||
window.addEventListener("load", setup);
|
||||
})();
|
58
volumes/attach/index.shtml
Normal file
58
volumes/attach/index.shtml
Normal file
@ -0,0 +1,58 @@
|
||||
<!--
|
||||
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 - Attach Volume</title>
|
||||
<link rel="shortcut icon" type="image/x-icon" href="/favicon.ico" />
|
||||
<link rel="stylesheet" type="text/css" href="attach.css" />
|
||||
<script src="attach.js" type="module"></script>
|
||||
</head>
|
||||
<body>
|
||||
<!--#include virtual="/include/header.html"-->
|
||||
<div id="main-content" class="wrapper">
|
||||
<div id="top-links"><a href="/volumes">Volumes</a> » <a id="volume-label" href="/volumes/settings?vid=0"></a> » <span class="top-links-title">Attach Volume</span></div>
|
||||
<div id="attach">
|
||||
<table class="lmc-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<td colspan="3">Attach a Volume</td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr class="lmc-tr3">
|
||||
<td>Volume</td>
|
||||
<td id="label"></td>
|
||||
<td class="info">The volume to attach</td>
|
||||
</tr>
|
||||
<tr class="lmc-tr3">
|
||||
<td>Attach To</td>
|
||||
<td><select id="linode"></select></td>
|
||||
<td class="info">The Linode to attach this volume to</td>
|
||||
</tr>
|
||||
<tr class="lmc-tr3">
|
||||
<td></td>
|
||||
<td><button disabled id="attach-button" type="button">Attach »</button></td>
|
||||
<td></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
Reference in New Issue
Block a user