aboutsummaryrefslogtreecommitdiffstats
path: root/loggedin.js
diff options
context:
space:
mode:
authorAlex Vitkov <alexvitkov98@gmail.com>2021-02-13 09:12:28 +0200
committerAlex Vitkov <alexvitkov98@gmail.com>2021-02-13 09:12:28 +0200
commitb17c9ee6046735433e4ba037c9b60c5f592bd15e (patch)
tree55726d2a51f187060e14d31bee2388f9aabe2b5b /loggedin.js
parent34df293dec1ee19cde50e33f757c8eefdbfc33d9 (diff)
downloadfileup-b17c9ee6046735433e4ba037c9b60c5f592bd15e.tar.gz
/php/move.php
Diffstat (limited to 'loggedin.js')
-rw-r--r--loggedin.js34
1 files changed, 30 insertions, 4 deletions
diff --git a/loggedin.js b/loggedin.js
index a703849..0f48746 100644
--- a/loggedin.js
+++ b/loggedin.js
@@ -123,7 +123,7 @@ function load_dir() {
}
function delete_file(filename) {
- var file_full_path = get_path() + "/" + filename;
+ var file_full_path = path_combine(get_path(), filename);
var data = new FormData();
data.append('path', file_full_path);
@@ -137,7 +137,7 @@ function delete_file(filename) {
}
function rename_file(filename) {
- var file_full_path = get_path() + filename;
+ var file_full_path = path_combine(get_path(), filename);
var new_name = prompt(`Rename ${filename} to`, filename);
if (!new_name)
@@ -155,6 +155,20 @@ function rename_file(filename) {
xhr.send(data);
}
+function move_file(new_folder, filename) {
+ var data = new FormData();
+ data.append('old_folder', get_path());
+ data.append('new_folder', new_folder);
+ data.append('filename', filename);
+
+ var xhr = new XMLHttpRequest();
+ xhr.open('POST', '/php/move.php', true);
+ xhr.onload = function () {
+ load_dir();
+ };
+ xhr.send(data);
+}
+
function new_folder() {
var dirname = prompt(`Directory name`, "New Folder");
if (!dirname)
@@ -210,7 +224,11 @@ function end_drag(e) {
}
function drop_handler(dst, src) {
- alert(`Dropped ${dst.filename} on ${src.filename}`);
+ if (dst.is_directory) {
+ move_file(path_combine(get_path(), dst.filename), src.filename);
+ } else {
+ alert(`Dropped ${dst.filename} on ${src.filename}`);
+ }
}
function add_file_visuals(fileview) {
@@ -256,7 +274,7 @@ function add_file_visuals(fileview) {
visuals.onmouseup = (e) => {
if (dragging) {
- drop_handler(dragging_fileview, fileview);
+ drop_handler(fileview, dragging_fileview);
end_drag();
}
e.preventDefault();
@@ -308,6 +326,14 @@ function get_path() {
return path;
}
+function path_combine(a, b) {
+ const last_char = a.slice(-1);
+ if (last_char == "/")
+ return a + b;
+ else
+ return a + "/" + b;
+}
+
document.body.onclick = () => {
if (context_menu)
context_menu.remove();