From 9b29bb3deb3943dd101d7ab7b01f42ee49951e1b Mon Sep 17 00:00:00 2001 From: Alex Vitkov Date: Fri, 12 Feb 2021 14:33:42 +0200 Subject: icons for different mimetypes --- loggedin.js | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) (limited to 'loggedin.js') diff --git a/loggedin.js b/loggedin.js index d774e16..b275c4a 100644 --- a/loggedin.js +++ b/loggedin.js @@ -8,12 +8,22 @@ const current_directory = document.getElementById("current_directory"); the_file.onchange = on_file_added; -var files = []; const pwd = "/"; const pending_uploads = []; +class FileView { + constructor(filename, visuals, mimetype, is_directory) { + this.filename = filename; + this.visuals = visuals; + this.mimetype = mimetype; + this.is_directory = is_directory; + } +} + +var files = []; + function on_file_added(_e) { if (the_file.files.length >= 1) { filename_input.value = the_file.files[0].name; @@ -54,24 +64,30 @@ function load_dir(pwd) { xhr.open('POST', '/php/readdir.php', true); xhr.onload = function () { for (const f of files) - f[1].remove(); + f.visuals.remove(); files = []; var json = JSON.parse(this.responseText); for (const f of json) { - add_file_visuals(f.name, f.mimetype); + add_file_visuals(f.name, f.is_directory, f.mimetype); } }; xhr.send(data); } -function add_file_visuals(name, mimetype) { +function add_file_visuals(name, is_directory, mimetype) { var fileDiv = document.createElement('div'); var img = document.createElement('img'); var filename = document.createElement('div'); - img.src="/mimeicons/application-pdf.png"; + if (is_directory) { + img.src="/mimeicons/directory.png"; + } + else { + img.src=`/mimeicons/${mimetype.replace("/", "-")}.png`; + } + fileDiv.classList.add('file'); filename.classList.add('filename'); filename.innerText = name; @@ -81,9 +97,9 @@ function add_file_visuals(name, mimetype) { current_directory.appendChild(fileDiv); - files.push([name, fileDiv]); - - return fileDiv; + var file = new FileView(name, fileDiv, mimetype, is_directory); + files.push(file); + return file; } function begin_upload() { -- cgit v1.2.3