aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--css/style.css2
-rw-r--r--loggedin.js47
2 files changed, 36 insertions, 13 deletions
diff --git a/css/style.css b/css/style.css
index ebfe7c2..b99d13f 100644
--- a/css/style.css
+++ b/css/style.css
@@ -176,7 +176,7 @@ form > h2 {
background: white;
}
-.window h3 > .separator {
+.window h3 .separator {
flex: 0 0 1px;
align-self: stretch;
background: #bbb;
diff --git a/loggedin.js b/loggedin.js
index f00ccc5..60a7d59 100644
--- a/loggedin.js
+++ b/loggedin.js
@@ -23,6 +23,7 @@ class Window {
this.h2 = null; // The titlebar of the window
this.fileview = null;
this.files = [];
+ this.txt_editor = null; // For editable text files, this is the DOM element the user can edit
}
}
@@ -46,7 +47,7 @@ var override_file = false;
var override_file_filename = "";
var override_file_path = "";
-var open_file_mimetype = null;
+var open_file = null;
// Some elements have custom right click context menus
// If there's a custom context menu active, this will be it
@@ -327,7 +328,10 @@ function openfile_nondir() {
focus.filecontentsroot.style.display = 'flex';
focus.foldercontents.style.display = 'none';
- if (open_file_mimetype.split("/")[0] == "image") {
+ let is_image = open_file.mimetype.split("/")[0] == "image";
+ focus.save_btn_container.style.display = (open_file.write_permissions && !is_image) ? "flex" : "none";
+
+ if (is_image) {
xhr.responseType = 'arraybuffer';
xhr.onload = function () {
let b = `data:image/png;base64,${base64ArrayBuffer(xhr.response)}`;
@@ -340,11 +344,11 @@ function openfile_nondir() {
focus.filecontents.classList.remove('imgview');
focus.filecontents.style.backgroundImage = "unset";
- var pre = mk(focus.filecontents, 'pre');
+ focus.txt_editor = mk(focus.filecontents, 'pre');
xhr.onload = function () {
- pre.innerText = xhr.responseText;
- pre.contentEditable = "true";
+ focus.txt_editor.innerText = xhr.responseText;
+ focus.txt_editor.contentEditable = "true";
};
}
@@ -863,10 +867,13 @@ function make_window(pwd, has_close) {
share_btn.onclick = () => { share(true); }
mk(h3, 'div', 'separator');
- let replace_btn = mk(h3, 'button');
- replace_btn.innerText = "Save Changes";
- replace_btn.onclick = () => { alert("No implemento"); }
- mk(h3, 'div', 'separator');
+ wnd.save_btn_container = mk(h3, 'div');
+ wnd.save_btn_container.style.display = 'flex';
+
+ let save_btn = mk(wnd.save_btn_container, 'button');
+ save_btn.innerText = "Save";
+ save_btn.onclick = save_open_text_file;
+ mk(wnd.save_btn_container, 'div', 'separator');
wnd.filecontents = mk(wnd.filecontentsroot, 'div', 'filecontents');
}
@@ -875,6 +882,21 @@ function make_window(pwd, has_close) {
}
+function save_open_text_file() {
+ const contents = focus.txt_editor.innerText;
+ let xhr = new XMLHttpRequest();
+ xhr.open('POST', '/php/upload.php', true);
+
+ var data = new FormData();
+ data.append('parent_directory', get_path (focus.pwd.length - 1));
+ data.append('filename', focus.pwd[focus.pwd.length - 1]);
+ data.append('content', contents);
+ data.append('overwrite', '1');
+
+ xhr.send(data);
+}
+
+
// Create the visuals for a FileView
function add_file_visuals(fileview) {
// Are we in a subdirectory of the trash folder?
@@ -903,8 +925,9 @@ function add_file_visuals(fileview) {
fileview.visuals.onclick = () => {
focus.pwd.push(fileview.filename);
- if (!fileview.is_directory)
- open_file_mimetype = fileview.mimetype;
+ if (!fileview.is_directory) {
+ open_file = fileview;
+ }
openfile(fileview.is_directory);
}
@@ -922,7 +945,7 @@ function add_file_visuals(fileview) {
new_pwd.push(fileview.filename);
var new_wnd = make_window(new_pwd, true);
focus_window(new_wnd);
- open_file_mimetype = fileview.mimetype;
+ open_file = fileview;
openfile(fileview.is_directory);
}],
];