fixed eventlistener setups based on permissions
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -983,80 +983,84 @@ function showDeleteModal(filename, path = '') {
|
|||||||
document.getElementById('confirmDeleteBtn').addEventListener('click', deleteFileConfirmed);
|
document.getElementById('confirmDeleteBtn').addEventListener('click', deleteFileConfirmed);
|
||||||
|
|
||||||
// Add event listener for download selected
|
// Add event listener for download selected
|
||||||
document.getElementById('downloadSelectedBtn').addEventListener('click', function() {
|
if (canDownload === true || canDownload === 'true') {
|
||||||
const selectedCheckboxes = document.querySelectorAll('.select-item-checkbox:checked');
|
document.getElementById('downloadSelectedBtn').addEventListener('click', function() {
|
||||||
if (selectedCheckboxes.length === 0) return;
|
const selectedCheckboxes = document.querySelectorAll('.select-item-checkbox:checked');
|
||||||
|
if (selectedCheckboxes.length === 0) return;
|
||||||
|
|
||||||
const selectedItems = Array.from(selectedCheckboxes).map(cb => {
|
const selectedItems = Array.from(selectedCheckboxes).map(cb => {
|
||||||
const idx = parseInt(cb.dataset.idx);
|
const idx = parseInt(cb.dataset.idx);
|
||||||
return window.currentFiles[idx];
|
return window.currentFiles[idx];
|
||||||
});
|
});
|
||||||
|
|
||||||
// Submit the request to download the zip
|
// Submit the request to download the zip
|
||||||
const csrfToken = document.querySelector('meta[name="csrf-token"]').getAttribute('content');
|
const csrfToken = document.querySelector('meta[name="csrf-token"]').getAttribute('content');
|
||||||
fetch(`/api/rooms/${roomId}/download-zip`, {
|
fetch(`/api/rooms/${roomId}/download-zip`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
'X-CSRFToken': csrfToken
|
'X-CSRFToken': csrfToken
|
||||||
},
|
},
|
||||||
body: JSON.stringify({ items: selectedItems })
|
body: JSON.stringify({ items: selectedItems })
|
||||||
})
|
})
|
||||||
.then(response => {
|
.then(response => {
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
throw new Error('Download failed');
|
throw new Error('Download failed');
|
||||||
}
|
}
|
||||||
return response.blob();
|
return response.blob();
|
||||||
})
|
})
|
||||||
.then(blob => {
|
.then(blob => {
|
||||||
// Create a download link and trigger it
|
// Create a download link and trigger it
|
||||||
const url = window.URL.createObjectURL(blob);
|
const url = window.URL.createObjectURL(blob);
|
||||||
const a = document.createElement('a');
|
const a = document.createElement('a');
|
||||||
a.href = url;
|
a.href = url;
|
||||||
a.download = 'download.zip';
|
a.download = 'download.zip';
|
||||||
document.body.appendChild(a);
|
document.body.appendChild(a);
|
||||||
a.click();
|
a.click();
|
||||||
window.URL.revokeObjectURL(url);
|
window.URL.revokeObjectURL(url);
|
||||||
a.remove();
|
a.remove();
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
console.error('Error downloading files:', error);
|
console.error('Error downloading files:', error);
|
||||||
document.getElementById('fileError').textContent = 'Failed to download files.';
|
document.getElementById('fileError').textContent = 'Failed to download files.';
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
|
|
||||||
// Add event listener for batch delete
|
// Add event listener for batch delete
|
||||||
document.getElementById('deleteSelectedBtn').addEventListener('click', function() {
|
if (canDelete === true || canDelete === 'true') {
|
||||||
const selectedCheckboxes = document.querySelectorAll('.select-item-checkbox:checked');
|
document.getElementById('deleteSelectedBtn').addEventListener('click', function() {
|
||||||
if (selectedCheckboxes.length === 0) return;
|
const selectedCheckboxes = document.querySelectorAll('.select-item-checkbox:checked');
|
||||||
|
if (selectedCheckboxes.length === 0) return;
|
||||||
|
|
||||||
batchDeleteItems = Array.from(selectedCheckboxes).map(cb => {
|
batchDeleteItems = Array.from(selectedCheckboxes).map(cb => {
|
||||||
const idx = parseInt(cb.dataset.idx);
|
const idx = parseInt(cb.dataset.idx);
|
||||||
return window.currentFiles[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() {
|
function deleteFileConfirmed() {
|
||||||
const csrfToken = document.querySelector('meta[name="csrf-token"]').getAttribute('content');
|
const csrfToken = document.querySelector('meta[name="csrf-token"]').getAttribute('content');
|
||||||
@@ -1359,51 +1363,53 @@ document.addEventListener('DOMContentLoaded', function() {
|
|||||||
document.getElementById('confirmMoveBtn').addEventListener('click', moveFileConfirmed);
|
document.getElementById('confirmMoveBtn').addEventListener('click', moveFileConfirmed);
|
||||||
|
|
||||||
// Add click handler for new folder button
|
// Add click handler for new folder button
|
||||||
document.getElementById('newFolderBtn').addEventListener('click', function() {
|
if (canUpload === true || canUpload === 'true') {
|
||||||
document.getElementById('folderNameInput').value = '';
|
document.getElementById('newFolderBtn').addEventListener('click', function() {
|
||||||
document.getElementById('folderError').textContent = '';
|
document.getElementById('folderNameInput').value = '';
|
||||||
newFolderModal.show();
|
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.';
|
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
// 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') {
|
if (canUpload === true || canUpload === 'true') {
|
||||||
const uploadBtn = document.getElementById('uploadBtn');
|
const uploadBtn = document.getElementById('uploadBtn');
|
||||||
|
|||||||
Reference in New Issue
Block a user