function updateDownloads(downloads) { var dls = []; var i = 0; var tbody = $("").attr("id", "table") for (var d of downloads) { var row = $("").addClass("download").attr("index", i) var index = $("").attr("scope", "row").text(i) var filename = $("").text(d.subdir + "/" + d.filename).addClass("lastlog") var url = $("").text(d.url) var status = $("").addClass(d.status).css("cursor", "pointer").text(d.status + "\n" + d.error).on("click",{index: i, download: d}, evt => { if (d.status != "Queue" || d.status != "Complete") { setDownload([{ index: evt.data("index"), status: "Queue", priority: evt.data("d").priority }]) } }) var action = $("").addClass("dropdown") var button = $("").addClass("btn btn-secondary dropdown-toggle").attr("type", "button").attr("data-toggle", "dropdown") var menu = $("
").addClass("dropdown-menu") var del = $('Delete').addClass("dropdown-item").on("click",{index: i, download: d}, evt => { if (confirm("confirm deletion of " + evt.data.download.filename)) { deleteDownload([{ index: evt.data.index }]) } }) var resume = $('Resume').addClass("dropdown-item").on("click",{index: i, download: d}, evt => { setDownload([{ index: evt.data.index, status: "Queue", priority: evt.data.download.priority }]) }) var stop = $('Stop').addClass("dropdown-item").on("click",{index: i, download: d}, evt => { setDownload([{ index: evt.data.index, status: "Stop", priority: evt.data.download.priority }]) }) var na = $('N/A').addClass("dropdown-item") menu.append(del, resume, stop, na) action.append(button, menu) var progress = $("").append( $("
").addClass("progress").append( $("
").addClass("progress-bar text-dark").css("width", (d.progress ?? "0") + '%').attr("id", "progress-" + i) .text((d.progress ?? "0") + '%') ), ) row.append( index, filename, url, status, action, progress ) tbody.append(row) i++; } $("#table").replaceWith(tbody) } function deleteDownload(data){ var xhr = new XMLHttpRequest(); xhr.open("DELETE", "http://gloader.narnian.us:8844/delete"); xhr.setRequestHeader("Content-Type", "application/javascript"); xhr.send(JSON.stringify(data)); } function setDownload(data){ var xhr = new XMLHttpRequest(); xhr.open("POST", "http://gloader.narnian.us:8844/set"); xhr.setRequestHeader("Content-Type", "application/javascript"); xhr.send(JSON.stringify(data)); }