From 0cb09738c93570e30550bc9d252ccd6ca3576f1f Mon Sep 17 00:00:00 2001 From: Henrique Dias Date: Tue, 3 Jan 2017 22:33:59 +0000 Subject: [PATCH] updates Former-commit-id: 267203bec9fa61572cc7952dcbef33ca7afbe50c --- _embed/public/css/styles.css | 2 + _embed/public/js/common.js | 130 +--------------------------------- _embed/public/js/listing.js | 131 +++++++++++++++++++++++++++++++++++ _embed/templates/base.tmpl | 7 -- 4 files changed, 134 insertions(+), 136 deletions(-) diff --git a/_embed/public/css/styles.css b/_embed/public/css/styles.css index de714cbe..75b292ce 100644 --- a/_embed/public/css/styles.css +++ b/_embed/public/css/styles.css @@ -981,6 +981,8 @@ header .actions { padding: 2em; max-width: 25em; width: 90%; + max-height: 95vh; + overflow: auto; } .prompt h3, diff --git a/_embed/public/js/common.js b/_embed/public/js/common.js index 2f48a44f..45811419 100644 --- a/_embed/public/js/common.js +++ b/_embed/public/js/common.js @@ -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'); diff --git a/_embed/public/js/listing.js b/_embed/public/js/listing.js index 0f88c355..32e155fc 100644 --- a/_embed/public/js/listing.js +++ b/_embed/public/js/listing.js @@ -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; diff --git a/_embed/templates/base.tmpl b/_embed/templates/base.tmpl index 01a6e207..ef708078 100644 --- a/_embed/templates/base.tmpl +++ b/_embed/templates/base.tmpl @@ -144,13 +144,6 @@ {{- end }} - {{- if and (.User.AllowEdit) (not .IsDir) }} -
- forward - Move file -
- {{- end }} -
{{- if not .IsDir}}{{ end }} file_downloadDownload