From 24ec3ed37be74f36e91a44daab05332973422397 Mon Sep 17 00:00:00 2001 From: fabioswartz Date: Tue, 3 Jan 2017 22:21:53 +0000 Subject: [PATCH] Move file dialog - Testing --- _embed/public/js/common.js | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/_embed/public/js/common.js b/_embed/public/js/common.js index 1ae36b34..2f48a44f 100644 --- a/_embed/public/js/common.js +++ b/_embed/public/js/common.js @@ -301,6 +301,11 @@ function loadNextFolder(event) { prompt.querySelector("ul").innerHTML = ""; prompt.querySelector('code').innerHTML = event.target.dataset.url; + if(JSON.parse(request.response) == null) { + prompt.querySelector("p").innerHTML = `There aren't any folders in this directory.`; + return; + } + for(let f of JSON.parse(request.response)) { if(f.IsDir === true) { dirs++; @@ -327,23 +332,25 @@ function loadNextFolder(event) { function moveSelected(event) { event.preventDefault(); - // TODO: this only works for ONE file. What if there are more files selected? - // TODO: use webdav.rename + let promises = []; + buttons.setLoading("move"); - /* let request = new XMLHttpRequest(), - oldLink = toWebDavURL(window.location.pathname), - newLink = toWebDavURL(event.srcElement.querySelector("li[aria-selected=true]").innerHTML + "/"); + for(let file of selectedItems) { + let fileElement = document.getElementById(file), + destFolder = event.target.querySelector("p code").innerHTML; + if(event.srcElement.querySelector("li[aria-selected=true]") != null) destFolder = event.srcElement.querySelector("li[aria-selected=true]").innerHTML; + promises.push(webdav.move(fileElement.dataset.url, "/" + destFolder + "/" + fileElement.querySelector(".name").innerHTML)); + } - request.open("MOVE", oldLink); - request.setRequestHeader("Destination", newLink); - request.send(); - request.onreadystatechange = function () { - if(request.readyState == 4) { - if(request.status == 200 || request.status == 204) { - window.reload(); - } - } - } */ + Promise.all(promises) + .then(() => { + closePrompt(event); + buttons.setDone("move"); + listing.reload(); + }) + .catch(e => { + console.log(e); + }) } function moveEvent(event) {