mirror of https://github.com/zlatinb/muwire
move download js into a separate file
parent
85814b7544
commit
edd4a1ff4b
|
@ -0,0 +1,65 @@
|
||||||
|
class Downloader {
|
||||||
|
constructor(xmlNode) {
|
||||||
|
this.name = xmlNode.getElementsByTagName("Name")[0].childNodes[0].nodeValue;
|
||||||
|
this.state = xmlNode.getElementsByTagName("State")[0].childNodes[0].nodeValue;
|
||||||
|
this.speed = xmlNode.getElementsByTagName("Speed")[0].childNodes[0].nodeValue;
|
||||||
|
this.ETA = xmlNode.getElementsByTagName("ETA")[0].childNodes[0].nodeValue;
|
||||||
|
this.progress = xmlNode.getElementsByTagName("Progress")[0].childNodes[0].nodeValue;
|
||||||
|
this.infoHash = xmlNode.getElementsByTagName("InfoHash")[0].childNodes[0].nodeValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var downloader = null;
|
||||||
|
var downloaders = new Map()
|
||||||
|
|
||||||
|
function updateDownloader(infoHash) {
|
||||||
|
var selected = downloaders.get(infoHash);
|
||||||
|
|
||||||
|
var downloadDetailsDiv = document.getElementById("downloadDetails");
|
||||||
|
downloadDetailsDiv.innerHTML = "<p>Details for "+selected.name+"</p>"
|
||||||
|
}
|
||||||
|
|
||||||
|
function refreshDownloader() {
|
||||||
|
var xmlhttp = new XMLHttpRequest();
|
||||||
|
xmlhttp.onreadystatechange = function() {
|
||||||
|
if (this.readyState == 4 && this.status == 200) {
|
||||||
|
var xmlDoc = this.responseXML;
|
||||||
|
downloaders.clear();
|
||||||
|
var i;
|
||||||
|
var x = xmlDoc.getElementsByTagName("Download");
|
||||||
|
for (i = 0; i < x.length; i ++) {
|
||||||
|
var download = new Downloader(x[i]);
|
||||||
|
downloaders.set(download.infoHash, download);
|
||||||
|
}
|
||||||
|
|
||||||
|
var table = "<table><thead><tr><th>Name</th><th>State</th><th>Speed</th><th>ETA</th><th>Progress</th><th>Cancel</th></tr></thead></tbody>";
|
||||||
|
var downloadsDiv = document.getElementById("downloads");
|
||||||
|
for (var [infoHash, download] of downloaders) {
|
||||||
|
table += "<tr><td><a href='#' onclick='updateDownloader(\""+infoHash+"\");return false;'>";
|
||||||
|
table += download.name;
|
||||||
|
table += "</a></td>";
|
||||||
|
table += "<td>"+download.state+"</td>";
|
||||||
|
table += "<td>"+download.speed+"</td>";
|
||||||
|
table += "<td>"+download.ETA+"</td>";
|
||||||
|
table += "<td>"+download.progress+"</td>";
|
||||||
|
|
||||||
|
table += "<td><form action='/MuWire/Download' method='post'><input type='hidden' name='infoHash' value='" +
|
||||||
|
infoHash + "'><input type='hidden' name='action' value='cancel'><input type='submit' value='Cancel'></form></td>";
|
||||||
|
|
||||||
|
table += "</tr>";
|
||||||
|
}
|
||||||
|
table += "</tbody></table>";
|
||||||
|
if (downloaders.size > 0)
|
||||||
|
downloadsDiv.innerHTML = table;
|
||||||
|
if (downloader != null)
|
||||||
|
updateDownloader(downloader);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
xmlhttp.open("GET", "/MuWire/Download", true);
|
||||||
|
xmlhttp.send();
|
||||||
|
}
|
||||||
|
|
||||||
|
function initDownloads() {
|
||||||
|
setInterval(refreshDownloader, 3000)
|
||||||
|
setTimeout(refreshDownloader,1);
|
||||||
|
}
|
|
@ -16,7 +16,8 @@
|
||||||
<head>
|
<head>
|
||||||
<%@include file="css.jsi"%>
|
<%@include file="css.jsi"%>
|
||||||
</head>
|
</head>
|
||||||
<body onload="initConnectionsCount()">
|
<script src="js/download.js" type="text/javascript"></script>
|
||||||
|
<body onload="initConnectionsCount(); initDownloads();">
|
||||||
<%@include file="header.jsi"%>
|
<%@include file="header.jsi"%>
|
||||||
<p>Downloads:</p>
|
<p>Downloads:</p>
|
||||||
|
|
||||||
|
@ -28,72 +29,5 @@
|
||||||
<hr/>
|
<hr/>
|
||||||
<p>Download Details</p>
|
<p>Download Details</p>
|
||||||
<div id="downloadDetails"><p>Click on a download to view details</p></div>
|
<div id="downloadDetails"><p>Click on a download to view details</p></div>
|
||||||
|
|
||||||
<script>
|
|
||||||
|
|
||||||
class Downloader {
|
|
||||||
constructor(xmlNode) {
|
|
||||||
this.name = xmlNode.getElementsByTagName("Name")[0].childNodes[0].nodeValue;
|
|
||||||
this.state = xmlNode.getElementsByTagName("State")[0].childNodes[0].nodeValue;
|
|
||||||
this.speed = xmlNode.getElementsByTagName("Speed")[0].childNodes[0].nodeValue;
|
|
||||||
this.ETA = xmlNode.getElementsByTagName("ETA")[0].childNodes[0].nodeValue;
|
|
||||||
this.progress = xmlNode.getElementsByTagName("Progress")[0].childNodes[0].nodeValue;
|
|
||||||
this.infoHash = xmlNode.getElementsByTagName("InfoHash")[0].childNodes[0].nodeValue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var downloader = null;
|
|
||||||
var downloaders = new Map()
|
|
||||||
|
|
||||||
function updateDownloader(infoHash) {
|
|
||||||
var selected = downloaders.get(infoHash);
|
|
||||||
|
|
||||||
var downloadDetailsDiv = document.getElementById("downloadDetails");
|
|
||||||
downloadDetailsDiv.innerHTML = "<p>Details for "+selected.name+"</p>"
|
|
||||||
}
|
|
||||||
|
|
||||||
function refreshDownloader() {
|
|
||||||
var xmlhttp = new XMLHttpRequest();
|
|
||||||
xmlhttp.onreadystatechange = function() {
|
|
||||||
if (this.readyState == 4 && this.status == 200) {
|
|
||||||
var xmlDoc = this.responseXML;
|
|
||||||
downloaders.clear();
|
|
||||||
var i;
|
|
||||||
var x = xmlDoc.getElementsByTagName("Download");
|
|
||||||
for (i = 0; i < x.length; i ++) {
|
|
||||||
var download = new Downloader(x[i]);
|
|
||||||
downloaders.set(download.infoHash, download);
|
|
||||||
}
|
|
||||||
|
|
||||||
var table = "<table><thead><tr><th>Name</th><th>State</th><th>Speed</th><th>ETA</th><th>Progress</th><th>Cancel</th></tr></thead></tbody>";
|
|
||||||
var downloadsDiv = document.getElementById("downloads");
|
|
||||||
for (var [infoHash, download] of downloaders) {
|
|
||||||
table += "<tr><td><a href='#' onclick='updateDownloader(\""+infoHash+"\");return false;'>";
|
|
||||||
table += download.name;
|
|
||||||
table += "</a></td>";
|
|
||||||
table += "<td>"+download.state+"</td>";
|
|
||||||
table += "<td>"+download.speed+"</td>";
|
|
||||||
table += "<td>"+download.ETA+"</td>";
|
|
||||||
table += "<td>"+download.progress+"</td>";
|
|
||||||
|
|
||||||
table += "<td><form action='/MuWire/Download' method='post'><input type='hidden' name='infoHash' value='" +
|
|
||||||
infoHash + "'><input type='hidden' name='action' value='cancel'><input type='submit' value='Cancel'></form></td>";
|
|
||||||
|
|
||||||
table += "</tr>";
|
|
||||||
}
|
|
||||||
table += "</tbody></table>";
|
|
||||||
if (downloaders.size > 0)
|
|
||||||
downloadsDiv.innerHTML = table;
|
|
||||||
if (downloader != null)
|
|
||||||
updateDownloader(downloader);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
xmlhttp.open("GET", "/MuWire/Download", true);
|
|
||||||
xmlhttp.send();
|
|
||||||
}
|
|
||||||
|
|
||||||
setInterval(refreshDownloader, 3000)
|
|
||||||
setTimeout(refreshDownloader,1);
|
|
||||||
</script>
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
Loading…
Reference in New Issue