F diff --git a/loggedin.js b/loggedin.js
--- a/loggedin.js
+++ b/loggedin.js
}
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);
}
}
- data.append('path', path);
+ var data = new FormData();
+ data.append('path', get_path());
var xhr = new XMLHttpRequest();
xhr.open('POST', '/php/readdir.php', true);
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');
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();
}
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();