diff options
author | Roland Reichwein <mail@reichwein.it> | 2020-05-11 20:03:09 +0200 |
---|---|---|
committer | Roland Reichwein <mail@reichwein.it> | 2020-05-11 20:03:09 +0200 |
commit | 99048beee343e0aacf538d53ce91c7b545f09089 (patch) | |
tree | 8b810067649a7762350b81edd3498ccfdaefe18e /plugins/webbox/html | |
parent | 15b2be158ac0147982dd30382251b3ce83e219c7 (diff) |
webbox: added copy function
Diffstat (limited to 'plugins/webbox/html')
-rw-r--r-- | plugins/webbox/html/index.html | 10 | ||||
-rw-r--r-- | plugins/webbox/html/webbox.js | 65 |
2 files changed, 75 insertions, 0 deletions
diff --git a/plugins/webbox/html/index.html b/plugins/webbox/html/index.html index cc1cf12..01d1a5a 100644 --- a/plugins/webbox/html/index.html +++ b/plugins/webbox/html/index.html @@ -44,6 +44,7 @@ <tr><td class="entry" onclick="hideMenu(); download();">Download</td></tr> <tr class="writecommand"><td class="entry" onclick="hideMenu(); upload();">Upload</td></tr> <tr class="writecommand"><td class="entry" onclick="hideMenu(); deleteItems();">Delete</td></tr> + <tr class="writecommand"><td class="entry" onclick="hideMenu(); copy();">Copy</td></tr> <tr class="writecommand"><td class="entry" onclick="hideMenu(); move();">Move</td></tr> <tr class="writecommand"><td class="entry" onclick="hideMenu(); rename();">Rename</td></tr> <tr><td class="entry" onclick="hideMenu(); info();">Info</td></tr> @@ -67,6 +68,15 @@ Download multiple files as ZIP?<br> </div> + <div id="copy-dialog" hidden> + Copying files to folder:<br> + <input type="text" id="copydir" class="textinput"></input> + <br/> + Files to copy: + <br/> + <div id="copyfiles"></div> + </div> + <div id="move-dialog" hidden> Moving files to folder:<br> <input type="text" id="movedir" class="textinput"></input> 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(); |