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);
|
||||
|
||||
// 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');
|
||||
|
||||
Reference in New Issue
Block a user