From e5d54c499bf8572e9d4a7d527313873b626a6e4c Mon Sep 17 00:00:00 2001 From: Kobe Date: Tue, 27 May 2025 11:31:58 +0200 Subject: [PATCH] fixed eventlistener setups based on permissions --- routes/__pycache__/room_files.cpython-313.pyc | Bin 36760 -> 36760 bytes routes/__pycache__/rooms.cpython-313.pyc | Bin 14868 -> 14868 bytes templates/rooms/room.html | 234 +++++++++--------- 3 files changed, 120 insertions(+), 114 deletions(-) diff --git a/routes/__pycache__/room_files.cpython-313.pyc b/routes/__pycache__/room_files.cpython-313.pyc index 793cbc820e90034daf8af898ce6decddf4f5930d..2ac788dab0d158e9bea1e434bb4593e76a539730 100644 GIT binary patch delta 25 fcmbO+pJ~Q?Cce+Syj%=G;MHoH;hMUUud5#bVCDyg delta 25 fcmbO+pJ~Q?Cce+Syj%=GP<+EEV^z{dzOH@%XQBvU diff --git a/routes/__pycache__/rooms.cpython-313.pyc b/routes/__pycache__/rooms.cpython-313.pyc index 2344b0d6e68bbd7d9cb2891ee7eed39a3a19e72f..f893e97e77bd3ce9cc9eaa1d27b6a925c5203670 100644 GIT binary patch delta 23 dcmbPIGNpv?GcPX}0}w1}GR?45-^j;i1prmK23P<9 delta 23 dcmbPIGNpv?GcPX}0}%XZG|dQA+sMae1prx_2F3sY diff --git a/templates/rooms/room.html b/templates/rooms/room.html index eeb79a0..9de7de1 100644 --- a/templates/rooms/room.html +++ b/templates/rooms/room.html @@ -983,80 +983,84 @@ function showDeleteModal(filename, path = '') { document.getElementById('confirmDeleteBtn').addEventListener('click', deleteFileConfirmed); // Add event listener for download selected -document.getElementById('downloadSelectedBtn').addEventListener('click', function() { - const selectedCheckboxes = document.querySelectorAll('.select-item-checkbox:checked'); - if (selectedCheckboxes.length === 0) return; - - const selectedItems = Array.from(selectedCheckboxes).map(cb => { - const idx = parseInt(cb.dataset.idx); - return window.currentFiles[idx]; +if (canDownload === true || canDownload === 'true') { + document.getElementById('downloadSelectedBtn').addEventListener('click', function() { + const selectedCheckboxes = document.querySelectorAll('.select-item-checkbox:checked'); + if (selectedCheckboxes.length === 0) return; + + const selectedItems = Array.from(selectedCheckboxes).map(cb => { + const idx = parseInt(cb.dataset.idx); + return window.currentFiles[idx]; + }); + + // Submit the request to download the zip + const csrfToken = document.querySelector('meta[name="csrf-token"]').getAttribute('content'); + fetch(`/api/rooms/${roomId}/download-zip`, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + 'X-CSRFToken': csrfToken + }, + body: JSON.stringify({ items: selectedItems }) + }) + .then(response => { + if (!response.ok) { + throw new Error('Download failed'); + } + return response.blob(); + }) + .then(blob => { + // Create a download link and trigger it + const url = window.URL.createObjectURL(blob); + const a = document.createElement('a'); + a.href = url; + a.download = 'download.zip'; + document.body.appendChild(a); + a.click(); + window.URL.revokeObjectURL(url); + a.remove(); + }) + .catch(error => { + console.error('Error downloading files:', error); + document.getElementById('fileError').textContent = 'Failed to download files.'; + }); }); - - // Submit the request to download the zip - const csrfToken = document.querySelector('meta[name="csrf-token"]').getAttribute('content'); - fetch(`/api/rooms/${roomId}/download-zip`, { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - 'X-CSRFToken': csrfToken - }, - body: JSON.stringify({ items: selectedItems }) - }) - .then(response => { - if (!response.ok) { - throw new Error('Download failed'); - } - return response.blob(); - }) - .then(blob => { - // Create a download link and trigger it - const url = window.URL.createObjectURL(blob); - const a = document.createElement('a'); - a.href = url; - a.download = 'download.zip'; - document.body.appendChild(a); - a.click(); - window.URL.revokeObjectURL(url); - a.remove(); - }) - .catch(error => { - console.error('Error downloading files:', error); - document.getElementById('fileError').textContent = 'Failed to download files.'; - }); -}); +} // Add event listener for batch delete -document.getElementById('deleteSelectedBtn').addEventListener('click', function() { - const selectedCheckboxes = document.querySelectorAll('.select-item-checkbox:checked'); - if (selectedCheckboxes.length === 0) return; - - batchDeleteItems = Array.from(selectedCheckboxes).map(cb => { - const idx = parseInt(cb.dataset.idx); - return window.currentFiles[idx]; +if (canDelete === true || canDelete === 'true') { + document.getElementById('deleteSelectedBtn').addEventListener('click', function() { + const selectedCheckboxes = document.querySelectorAll('.select-item-checkbox:checked'); + if (selectedCheckboxes.length === 0) return; + + batchDeleteItems = Array.from(selectedCheckboxes).map(cb => { + const idx = parseInt(cb.dataset.idx); + return window.currentFiles[idx]; + }); + + // Get the modal element + const modalEl = document.getElementById('deleteConfirmModal'); + if (!modalEl) { + console.error('Delete modal element not found'); + return; + } + + // Initialize the modal if it hasn't been initialized + if (!deleteModal) { + deleteModal = new bootstrap.Modal(modalEl); + } + + // Update modal content + const fileNameEl = document.getElementById('deleteFileName'); + const labelEl = document.getElementById('deleteConfirmLabel'); + + if (fileNameEl) fileNameEl.textContent = `${selectedCheckboxes.length} item${selectedCheckboxes.length > 1 ? 's' : ''}`; + if (labelEl) labelEl.textContent = 'Move to Trash'; + + // Show the modal + deleteModal.show(); }); - - // Get the modal element - const modalEl = document.getElementById('deleteConfirmModal'); - if (!modalEl) { - console.error('Delete modal element not found'); - return; - } - - // Initialize the modal if it hasn't been initialized - if (!deleteModal) { - deleteModal = new bootstrap.Modal(modalEl); - } - - // Update modal content - const fileNameEl = document.getElementById('deleteFileName'); - const labelEl = document.getElementById('deleteConfirmLabel'); - - if (fileNameEl) fileNameEl.textContent = `${selectedCheckboxes.length} item${selectedCheckboxes.length > 1 ? 's' : ''}`; - if (labelEl) labelEl.textContent = 'Move to Trash'; - - // Show the modal - deleteModal.show(); -}); +} function deleteFileConfirmed() { const csrfToken = document.querySelector('meta[name="csrf-token"]').getAttribute('content'); @@ -1359,51 +1363,53 @@ document.addEventListener('DOMContentLoaded', function() { document.getElementById('confirmMoveBtn').addEventListener('click', moveFileConfirmed); // Add click handler for new folder button - document.getElementById('newFolderBtn').addEventListener('click', function() { - document.getElementById('folderNameInput').value = ''; - document.getElementById('folderError').textContent = ''; - newFolderModal.show(); - }); - - // Add click handler for create folder button - document.getElementById('createFolderBtn').addEventListener('click', function() { - const folderName = document.getElementById('folderNameInput').value.trim(); - if (!folderName) { - document.getElementById('folderError').textContent = 'Folder name is required.'; - return; - } - - const csrfToken = document.querySelector('meta[name="csrf-token"]').getAttribute('content'); - fetch(`/api/rooms/${roomId}/folders`, { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - 'X-CSRFToken': csrfToken - }, - body: JSON.stringify({ - name: folderName, - path: currentPath - }) - }) - .then(r => r.json()) - .then(res => { - if (res.success) { - newFolderModal.hide(); - fetchFiles(); - } else { - if (res.error === 'A folder with this name exists in the trash') { - document.getElementById('folderError').textContent = `Cannot create folder "${folderName}" because this name is currently in the trash. Please restore or permanently delete the trashed item first.`; - } else if (res.error === 'A folder with this name already exists in this location') { - document.getElementById('folderError').textContent = `A folder named "${folderName}" already exists in this location. Please choose a different name.`; - } else { - document.getElementById('folderError').textContent = res.error || 'Failed to create folder.'; - } - } - }) - .catch(() => { - document.getElementById('folderError').textContent = 'Failed to create folder.'; + if (canUpload === true || canUpload === 'true') { + document.getElementById('newFolderBtn').addEventListener('click', function() { + document.getElementById('folderNameInput').value = ''; + document.getElementById('folderError').textContent = ''; + newFolderModal.show(); }); - }); + + // Add click handler for create folder button + document.getElementById('createFolderBtn').addEventListener('click', function() { + const folderName = document.getElementById('folderNameInput').value.trim(); + if (!folderName) { + document.getElementById('folderError').textContent = 'Folder name is required.'; + return; + } + + const csrfToken = document.querySelector('meta[name="csrf-token"]').getAttribute('content'); + fetch(`/api/rooms/${roomId}/folders`, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + 'X-CSRFToken': csrfToken + }, + body: JSON.stringify({ + name: folderName, + path: currentPath + }) + }) + .then(r => r.json()) + .then(res => { + if (res.success) { + newFolderModal.hide(); + fetchFiles(); + } else { + if (res.error === 'A folder with this name exists in the trash') { + document.getElementById('folderError').textContent = `Cannot create folder "${folderName}" because this name is currently in the trash. Please restore or permanently delete the trashed item first.`; + } else if (res.error === 'A folder with this name already exists in this location') { + document.getElementById('folderError').textContent = `A folder named "${folderName}" already exists in this location. Please choose a different name.`; + } else { + document.getElementById('folderError').textContent = res.error || 'Failed to create folder.'; + } + } + }) + .catch(() => { + document.getElementById('folderError').textContent = 'Failed to create folder.'; + }); + }); + } if (canUpload === true || canUpload === 'true') { const uploadBtn = document.getElementById('uploadBtn');