diff options
Diffstat (limited to 'plugins/webbox/html/webbox.js')
-rw-r--r-- | plugins/webbox/html/webbox.js | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/plugins/webbox/html/webbox.js b/plugins/webbox/html/webbox.js index e056c16..80ee8ed 100644 --- a/plugins/webbox/html/webbox.js +++ b/plugins/webbox/html/webbox.js @@ -626,6 +626,71 @@ function deleteItems() { } } +function copy() { + showDialog(); + + var files = getSelectedFiles(); + if (files.length == 0) { + document.getElementById("dialog").innerHTML = "No files selected."; + document.getElementById("okbutton").onclick = hideDialog; + return; + } + + var message = ""; + for (var i = 0; i < files.length; i++) { + message += files[i] + "<br/>"; + } + + document.getElementById("dialog").innerHTML = document.getElementById("copy-dialog").innerHTML; + document.getElementById("copydir").focus(); + document.getElementById("copydir").onkeydown = function(evt) { + if (evt.key == "Enter") { + document.getElementById("okbutton").click(); + } + } + + document.getElementById("copyfiles").innerHTML = message; + + document.getElementById("okbutton").onclick = function() { + + var xhr = new XMLHttpRequest(); + + xhr.onreadystatechange = function() { + if (this.readyState != 4) { + return; + } + if (this.status != 200) { + document.getElementById("dialog").innerHTML = "HTTP error"; + } else { + document.getElementById("dialog").innerHTML = xhr.responseText; + } + + document.getElementById("okbutton").onclick = hideDialog; + document.getElementById("okbutton").focus(); + loadContents(currentDir); // load new file list with deleted items + } + + var parser = new DOMParser(); + var xmlDocument = parser.parseFromString("<request></request>", "text/xml"); + var filesElement = xmlDocument.getElementsByTagName("request")[0]; + + var targetElement = xmlDocument.createElement("target"); + targetElement.appendChild(document.createTextNode(document.getElementById("copydir").value)); + filesElement.appendChild(targetElement); + + for (var i = 0; i < files.length; i++) { + var fileElement = xmlDocument.createElement("file"); + fileElement.appendChild(document.createTextNode(files[i])); + filesElement.appendChild(fileElement); + } + + xhr.open("POST", relativePath(currentDir) + "?command=copy", true); + xhr.setRequestHeader("Authorization", "Basic " + btoa(username + ":" + password)); + xhr.setRequestHeader("Content-type", "text/xml"); + xhr.send(xmlDocument); + } +} + function move() { showDialog(); |