summaryrefslogtreecommitdiffhomepage
path: root/html
diff options
context:
space:
mode:
authorRoland Stigge <stigge@antcom.de>2018-01-07 16:07:49 +0100
committerRoland Stigge <stigge@antcom.de>2018-01-07 16:07:49 +0100
commitfb24f0bc60d9ff910d49646aaeadad99f22826e5 (patch)
treee3a92e1bfd8c6c4c1f34137700371e68ad2e0340 /html
parentce94c74b8bfb69b94bdb78aaa60d7dce2d058184 (diff)
Implemented file move
Diffstat (limited to 'html')
-rw-r--r--html/index.html13
-rw-r--r--html/webbox.js100
2 files changed, 108 insertions, 5 deletions
diff --git a/html/index.html b/html/index.html
index 3cb221d..49dafef 100644
--- a/html/index.html
+++ b/html/index.html
@@ -8,7 +8,7 @@
</head>
<body onload="initMainpage();">
<div>
- <h1 class="title"></h1>
+ <h1 class="title">&nbsp;</h1>
<input id="uploadfile" type="file" onchange="onUploadFile();" hidden/>
<table class="menu">
<tr>
@@ -16,7 +16,7 @@
<td class="entry" onclick="createDir();">New folder</td>
<td class="entry" onclick="download();">Download</td>
<td class="entry" onclick="upload();">Upload</td>
- <td class="entry" onclick="deleteItem();">Delete</td>
+ <td class="entry" onclick="deleteItems();">Delete</td>
<td class="entry" onclick="move();">Move</td>
<td class="entry" onclick="info();">Info</td>
<td class="entry" onclick="selectAll();">Select All</td>
@@ -49,6 +49,15 @@
Download multiple files as ZIP?<br>
</div>
+ <div id="move-dialog" hidden>
+ Moving files to folder:<br>
+ <input type="text" id="movedir" class="textinput"></input>
+ <br/>
+ Files to move:
+ <br/>
+ <div id="movefiles"></div>
+ </div>
+
<a download="webbox-download.zip" id="download-a" hidden/>
<div class="footer">
diff --git a/html/webbox.js b/html/webbox.js
index faa2bb2..58b04fb 100644
--- a/html/webbox.js
+++ b/html/webbox.js
@@ -341,6 +341,7 @@ function createDir() {
}
document.getElementById("dialog").innerHTML = document.getElementById("create-dir-dialog").innerHTML;
+ document.getElementById("newdir").focus();
}
function upload() {
@@ -373,12 +374,105 @@ function onUploadFile() {
xhr.send(formData);
}
-function deleteItem() {
- alert("TBD");
+function deleteItems() {
+ showDialog();
+
+ var files = getSelectedFiles();
+ if (files.length == 0) {
+ document.getElementById("dialog").innerHTML = "No files selected.";
+ document.getElementById("okbutton").onclick = hideDialog;
+ return;
+ }
+
+ var message = "Are sure to delete the following files and directories?<br/><br/>";
+
+ for (var i = 0; i < files.length; i++) {
+ message += files[i] + "<br/>";
+ }
+
+ document.getElementById("dialog").innerHTML = message;
+
+ document.getElementById("okbutton").onclick = function() {
+
+ var xhr = new XMLHttpRequest();
+
+ xhr.onreadystatechange = function() {
+ if (this.readyState != 4 || this.status != 200) {
+ return;
+ }
+
+ document.getElementById("dialog").innerHTML = xhr.responseText;
+ document.getElementById("okbutton").onclick = hideDialog;
+ loadContents(currentDir); // load new file list with deleted items
+ }
+
+ var parser = new DOMParser();
+ var xmlDocument = parser.parseFromString("<files></files>", "text/xml");
+ var filesElement = xmlDocument.getElementsByTagName("files")[0];
+
+ 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", "/bin/query" + currentDir + "?command=delete", true);
+ xhr.setRequestHeader("Content-type", "text/xml");
+ xhr.send(xmlDocument);
+ }
}
function move() {
- alert("TBD");
+ 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("move-dialog").innerHTML;
+ document.getElementById("movedir").focus();
+ document.getElementById("movefiles").innerHTML = message;
+
+ document.getElementById("okbutton").onclick = function() {
+
+ var xhr = new XMLHttpRequest();
+
+ xhr.onreadystatechange = function() {
+ if (this.readyState != 4 || this.status != 200) {
+ return;
+ }
+
+ document.getElementById("dialog").innerHTML = xhr.responseText;
+ document.getElementById("okbutton").onclick = hideDialog;
+ 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("movedir").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", "/bin/query" + currentDir + "?command=move", true);
+ xhr.setRequestHeader("Content-type", "text/xml");
+ xhr.send(xmlDocument);
+ }
}
// File info: date, size, type