diff options
author | Alex Vitkov <alexvitkov98@gmail.com> | 2021-02-12 16:35:22 +0200 |
---|---|---|
committer | Alex Vitkov <alexvitkov98@gmail.com> | 2021-02-12 16:35:22 +0200 |
commit | 6992510faf7de95b37d151da3d5e6f7026af343e (patch) | |
tree | 78cce49943f3f8a44352252dbc3c067ccf73c6dd | |
parent | e9d94ce6144746fe69a3d9f26e12a8fab9d4a534 (diff) | |
download | fileup-6992510faf7de95b37d151da3d5e6f7026af343e.tar.gz |
front end code for rename/delete
-rw-r--r-- | loggedin.js | 52 |
1 files changed, 44 insertions, 8 deletions
diff --git a/loggedin.js b/loggedin.js index d80c734..78a7099 100644 --- a/loggedin.js +++ b/loggedin.js @@ -72,11 +72,6 @@ function done_upload(fileview) { } function load_dir() { - var data = new FormData(); - - var path = "/"; - for (const d of pwd) - path += d + "/"; while (the_path.children.length > 1) the_path.removeChild(the_path.lastChild); @@ -100,7 +95,8 @@ function load_dir() { } } - data.append('path', path); + var data = new FormData(); + data.append('path', get_path()); var xhr = new XMLHttpRequest(); xhr.open('POST', '/php/readdir.php', true); @@ -117,6 +113,39 @@ function load_dir() { xhr.send(data); } +function delete_file(filename) { + var file_full_path = get_path() + filename; + + var data = new FormData(); + data.append('path', file_full_path); + + var xhr = new XMLHttpRequest(); + xhr.open('POST', '/php/delete.php', true); + xhr.onload = function () { + load_dir(); + }; + xhr.send(data); +} + +function rename_file(filename) { + var file_full_path = get_path() + filename; + + var new_name = prompt(`Rename ${filename} to`, filename); + if (!new_name) + return; + + var data = new FormData(); + data.append('path', file_full_path); + data.append('new_name', new_name); + + var xhr = new XMLHttpRequest(); + xhr.open('POST', '/php/rename.php', true); + xhr.onload = function () { + load_dir(); + }; + xhr.send(data); +} + function add_file_visuals(name, is_directory, mimetype) { var fileDiv = document.createElement('div'); @@ -143,9 +172,9 @@ function add_file_visuals(name, is_directory, mimetype) { alert('not implemented'); } }], - ['Rename', () => {alert('not implemented')}], + ['Rename', () => { rename_file(name); }], ['Share', () => {alert('not implemented')}], - ['Delete', () => {alert('not implemented')}], + ['Delete', () => { delete_file(name); }], ]); e.preventDefault(); } @@ -192,6 +221,13 @@ function context(e, entries) { document.body.appendChild(context_menu); } +function get_path() { + var path = "/"; + for (const d of pwd) + path += d + "/"; + return path; +} + document.body.onclick = () => { if (context_menu) context_menu.remove(); |