From 2229da3596c9f6e25b1d30a30df35bf21b2bc219 Mon Sep 17 00:00:00 2001 From: Alex Vitkov Date: Sat, 13 Feb 2021 09:22:23 +0200 Subject: Move file to parent directories by dragging onto the path entries --- loggedin.js | 40 +++++++++++++++++++++++++++++++--------- loggedin.php | 2 +- php/move.php | 2 +- 3 files changed, 33 insertions(+), 11 deletions(-) diff --git a/loggedin.js b/loggedin.js index 0f48746..324a18a 100644 --- a/loggedin.js +++ b/loggedin.js @@ -81,10 +81,7 @@ function load_dir() { entry.innerText = d; the_path.appendChild(entry); - entry.onclick = () => { - pwd.length = i + 1; - load_dir(); - } + add_link_functionality(entry, i + 1); } var data = new FormData(); @@ -231,6 +228,26 @@ function drop_handler(dst, src) { } } +function add_link_functionality(link, length) { + link.onclick = () => { + pwd.length = length, + load_dir(); + } + + link.onmouseup = (e) => { + if (dragging) { + var new_folder = get_path(length); + move_file(new_folder, dragging_fileview.filename); + end_drag(); + + e.preventDefault(); + e.stopPropagation(); + } + } +} + +add_link_functionality(document.getElementById("home_path_entry"), 0); + function add_file_visuals(fileview) { var visuals = document.createElement('div'); fileview.visuals = visuals; @@ -317,12 +334,17 @@ function context(e, entries) { document.body.appendChild(context_menu); } -function get_path() { +function get_path(max_length) { + if (max_length == undefined) { + max_length = pwd.length; + } + var path = "/"; - for (const d of pwd) - path += d + "/"; - if (path.length > 1) - path = path.substring(0, path.length - 1); + for (let i = 0; i < max_length; i++) { + path += pwd[i]; + if (i != max_length - 1) + path + "/"; + } return path; } diff --git a/loggedin.php b/loggedin.php index 8d54d65..b655819 100644 --- a/loggedin.php +++ b/loggedin.php @@ -6,7 +6,7 @@
- +
diff --git a/php/move.php b/php/move.php index a79ce83..3b1bf05 100644 --- a/php/move.php +++ b/php/move.php @@ -8,7 +8,7 @@ require_once "misc.php"; session_start(); if (!isset($_POST['old_folder']) || !isset($_POST['new_folder']) || !isset($_POST['filename'])) { - error_log("bad /php/move.php call $_POST of:$_POST[old_folder] nf:$_POST[new_folder] fn:$_POST[filename]"); + error_log("bad /php/move.php call"); http_response_code(400); exit(1); } -- cgit v1.2.3