This commit is contained in:
Henrique Dias 2017-01-03 22:33:59 +00:00
parent ad964b8824
commit 267203bec9
4 changed files with 134 additions and 136 deletions

View File

@ -981,6 +981,8 @@ header .actions {
padding: 2em;
max-width: 25em;
width: 90%;
max-height: 95vh;
overflow: auto;
}
.prompt h3,

View File

@ -272,132 +272,6 @@ function openEvent(event) {
return false;
}
function selectMoveFolder(event) {
if(event.target.getAttribute("aria-selected") === "true") {
event.target.setAttribute("aria-selected", false);
return;
} else {
if(document.querySelector(".file-list li[aria-selected=true]")) {
document.querySelector(".file-list li[aria-selected=true]").setAttribute("aria-selected", false);
}
event.target.setAttribute("aria-selected", true);
return;
}
}
function loadNextFolder(event) {
let request = new XMLHttpRequest(),
prompt = document.querySelector("form.prompt.active");
prompt.addEventListener("submit", moveSelected);
request.open("GET", event.target.dataset.url);
request.setRequestHeader("Accept", "application/json");
request.send();
request.onreadystatechange = function () {
if(request.readyState == 4 && request.status == 200) {
let dirs = 0;
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++;
let newNode = document.createElement("li");
newNode.dataset.url = f.URL;
newNode.innerHTML = f.Name;
newNode.setAttribute("aria-selected", false);
newNode.addEventListener("dblclick", loadNextFolder);
newNode.addEventListener("click", selectMoveFolder);
prompt.querySelector("div.file-list ul").appendChild(newNode);
}
}
if(dirs === 0) {
prompt.querySelector("p").innerHTML = `There aren't any folders in this directory.`;
}
}
}
}
function moveSelected(event) {
event.preventDefault();
let promises = [];
buttons.setLoading("move");
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));
}
Promise.all(promises)
.then(() => {
closePrompt(event);
buttons.setDone("move");
listing.reload();
})
.catch(e => {
console.log(e);
})
}
function moveEvent(event) {
if(event.currentTarget.classList.contains("disabled"))
return;
let request = new XMLHttpRequest();
request.open("GET", window.location.pathname, true);
request.setRequestHeader("Accept", "application/json");
request.send();
request.onreadystatechange = function () {
if(request.readyState == 4) {
if(request.status == 200) {
let prompt = document.importNode(templates.move.content, true),
dirs = 0;
prompt.querySelector("form").addEventListener("submit", moveSelected);
prompt.querySelector('code').innerHTML = window.location.pathname;
for(let f of JSON.parse(request.response)) {
if(f.IsDir === true) {
dirs++;
let newNode = document.createElement("li");
newNode.dataset.url = f.URL;
newNode.innerHTML = f.Name;
newNode.setAttribute("aria-selected", false);
newNode.addEventListener("dblclick", loadNextFolder);
newNode.addEventListener("click", selectMoveFolder);
prompt.querySelector("div.file-list ul").appendChild(newNode);
}
}
if(dirs === 0) {
prompt.querySelector("p").innerHTML = `There aren't any folders in this directory.`;
}
document.body.appendChild(prompt);
document.querySelector(".overlay").classList.add("active");
document.querySelector(".prompt").classList.add("active");
}
}
}
}
function deleteOnSingleFile() {
closePrompt(event);
buttons.setLoading('delete');
@ -510,7 +384,7 @@ function searchEvent(event) {
url = removeLastDirectoryPartOf(url);
}
let protocol = ssl ? 'wss:' : 'ws';
let protocol = ssl ? 'wss:' : 'ws:';
if(supported && user.AllowCommands) {
let conn = new WebSocket(`${protocol}//${url}?command=true`);
@ -638,12 +512,10 @@ document.addEventListener("DOMContentLoaded", function (event) {
buttons.open = document.getElementById("open");
buttons.delete = document.getElementById("delete");
buttons.previous = document.getElementById("previous");
buttons.move = document.getElementById("move");
// Attach event listeners
buttons.logout.addEventListener("click", logoutEvent);
buttons.open.addEventListener("click", openEvent);
buttons.move.addEventListener("click", moveEvent);
templates.question = document.querySelector('#question-template');
templates.info = document.querySelector('#info-template');

View File

@ -358,6 +358,134 @@ window.addEventListener("resize", () => {
listing.updateColumns();
});
function selectMoveFolder(event) {
if(event.target.getAttribute("aria-selected") === "true") {
event.target.setAttribute("aria-selected", false);
return;
} else {
if(document.querySelector(".file-list li[aria-selected=true]")) {
document.querySelector(".file-list li[aria-selected=true]").setAttribute("aria-selected", false);
}
event.target.setAttribute("aria-selected", true);
return;
}
}
function loadNextFolder(event) {
let request = new XMLHttpRequest(),
prompt = document.querySelector("form.prompt.active");
prompt.addEventListener("submit", moveSelected);
request.open("GET", event.target.dataset.url);
request.setRequestHeader("Accept", "application/json");
request.send();
request.onreadystatechange = function () {
if(request.readyState == 4 && request.status == 200) {
let dirs = 0;
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++;
let newNode = document.createElement("li");
newNode.dataset.url = f.URL;
newNode.innerHTML = f.Name;
newNode.setAttribute("aria-selected", false);
newNode.addEventListener("dblclick", loadNextFolder);
newNode.addEventListener("click", selectMoveFolder);
prompt.querySelector("div.file-list ul").appendChild(newNode);
}
}
if(dirs === 0) {
prompt.querySelector("p").innerHTML = `There aren't any folders in this directory.`;
}
}
}
}
function moveSelected(event) {
event.preventDefault();
let promises = [];
buttons.setLoading("move");
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));
}
Promise.all(promises)
.then(() => {
closePrompt(event);
buttons.setDone("move");
listing.reload();
})
.catch(e => {
console.log(e);
})
}
function moveEvent(event) {
if(event.currentTarget.classList.contains("disabled"))
return;
let request = new XMLHttpRequest();
request.open("GET", window.location.pathname, true);
request.setRequestHeader("Accept", "application/json");
request.send();
request.onreadystatechange = function () {
if(request.readyState == 4) {
if(request.status == 200) {
let prompt = document.importNode(templates.move.content, true),
dirs = 0;
prompt.querySelector("form").addEventListener("submit", moveSelected);
prompt.querySelector('code').innerHTML = window.location.pathname;
for(let f of JSON.parse(request.response)) {
if(f.IsDir === true) {
dirs++;
let newNode = document.createElement("li");
newNode.dataset.url = f.URL;
newNode.innerHTML = f.Name;
newNode.setAttribute("aria-selected", false);
newNode.addEventListener("dblclick", loadNextFolder);
newNode.addEventListener("click", selectMoveFolder);
prompt.querySelector("div.file-list ul").appendChild(newNode);
}
}
if(dirs === 0) {
prompt.querySelector("p").innerHTML = `There aren't any folders in this directory.`;
}
document.body.appendChild(prompt);
document.querySelector(".overlay").classList.add("active");
document.querySelector(".prompt").classList.add("active");
}
}
}
}
document.addEventListener('DOMContentLoaded', event => {
listing.updateColumns();
listing.addDoubleTapEvent();
@ -366,6 +494,9 @@ document.addEventListener('DOMContentLoaded', event => {
buttons.upload = document.getElementById("upload");
buttons.new = document.getElementById('new');
buttons.download = document.getElementById('download');
buttons.move = document.getElementById("move");
buttons.move.addEventListener("click", moveEvent);
document.getElementById('multiple-selection-activate').addEventListener('click', event => {
listing.selectMultiple = true;

View File

@ -144,13 +144,6 @@
</div>
{{- end }}
{{- if and (.User.AllowEdit) (not .IsDir) }}
<div class="action" id="move">
<i class="material-icons" title="Move">forward</i>
<span>Move file</span>
</div>
{{- end }}
<div {{ if .IsDir }}data-dropdown{{ end }} class="action" id="download">
{{- if not .IsDir}}<a href="?download=true">{{ end }}
<i class="material-icons" title="Download">file_download</i><span>Download</span>