Fix trash
This commit is contained in:
@@ -400,16 +400,31 @@ function emptyTrash() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
fetch('/api/rooms/empty-trash', {
|
// Get all trashed files to get their room IDs
|
||||||
|
fetch('/api/rooms/trash')
|
||||||
|
.then(r => r.json())
|
||||||
|
.then(files => {
|
||||||
|
// Get unique room IDs
|
||||||
|
const roomIds = [...new Set(files.map(file => file.room_id))];
|
||||||
|
|
||||||
|
// Create an array of promises for emptying trash in each room
|
||||||
|
const emptyPromises = roomIds.map(roomId =>
|
||||||
|
fetch(`/api/rooms/${roomId}/trash/empty`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
'X-CSRFToken': csrfToken
|
'X-CSRFToken': csrfToken
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.then(r => r.json())
|
);
|
||||||
.then(res => {
|
|
||||||
if (res.success) {
|
// Execute all promises
|
||||||
|
return Promise.all(emptyPromises);
|
||||||
|
})
|
||||||
|
.then(responses => {
|
||||||
|
// Check if all responses were successful
|
||||||
|
const allSuccessful = responses.every(r => r.ok);
|
||||||
|
if (allSuccessful) {
|
||||||
// Clear all files from the current view
|
// Clear all files from the current view
|
||||||
currentFiles = [];
|
currentFiles = [];
|
||||||
renderFiles(currentFiles);
|
renderFiles(currentFiles);
|
||||||
@@ -417,7 +432,7 @@ function emptyTrash() {
|
|||||||
const modal = bootstrap.Modal.getInstance(document.getElementById('emptyTrashModal'));
|
const modal = bootstrap.Modal.getInstance(document.getElementById('emptyTrashModal'));
|
||||||
modal.hide();
|
modal.hide();
|
||||||
} else {
|
} else {
|
||||||
console.error('Failed to empty trash:', res.error);
|
console.error('Failed to empty trash in some rooms');
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
|
|||||||
@@ -1,10 +1,85 @@
|
|||||||
let currentView = 'grid';
|
let currentView = 'grid';
|
||||||
|
|
||||||
|
// Make functions globally available
|
||||||
|
window.showEmptyTrashModal = function() {
|
||||||
|
console.log('Showing Empty Trash Modal');
|
||||||
|
const modalEl = document.getElementById('emptyTrashModal');
|
||||||
|
console.log('Modal Element:', modalEl);
|
||||||
|
|
||||||
|
if (!modalEl) {
|
||||||
|
console.error('Empty Trash Modal element not found');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const modal = new bootstrap.Modal(modalEl);
|
||||||
|
console.log('Modal instance created:', modal);
|
||||||
|
modal.show();
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error showing modal:', error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
window.emptyTrash = function() {
|
||||||
|
console.log('Emptying Trash');
|
||||||
|
const csrfToken = document.querySelector('meta[name="csrf-token"]').getAttribute('content');
|
||||||
|
if (!csrfToken) {
|
||||||
|
console.error('CSRF token not available');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get all trashed files to get their room IDs
|
||||||
|
fetch('/api/rooms/trash')
|
||||||
|
.then(r => r.json())
|
||||||
|
.then(files => {
|
||||||
|
// Get unique room IDs
|
||||||
|
const roomIds = [...new Set(files.map(file => file.room_id))];
|
||||||
|
|
||||||
|
// Create an array of promises for emptying trash in each room
|
||||||
|
const emptyPromises = roomIds.map(roomId =>
|
||||||
|
fetch(`/api/rooms/${roomId}/trash/empty`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'X-CSRFToken': csrfToken
|
||||||
|
}
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
// Execute all promises
|
||||||
|
return Promise.all(emptyPromises);
|
||||||
|
})
|
||||||
|
.then(responses => {
|
||||||
|
// Check if all responses were successful
|
||||||
|
const allSuccessful = responses.every(r => r.ok);
|
||||||
|
if (allSuccessful) {
|
||||||
|
// Clear all files from the current view
|
||||||
|
window.currentFiles = [];
|
||||||
|
// Update the grid directly
|
||||||
|
const grid = document.getElementById('fileGrid');
|
||||||
|
grid.innerHTML = '<div class="col"><div class="text-muted">No items found.</div></div>';
|
||||||
|
// Close the modal
|
||||||
|
const modal = bootstrap.Modal.getInstance(document.getElementById('emptyTrashModal'));
|
||||||
|
modal.hide();
|
||||||
|
} else {
|
||||||
|
console.error('Failed to empty trash in some rooms');
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
console.error('Error emptying trash:', error);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
document.addEventListener('DOMContentLoaded', function() {
|
document.addEventListener('DOMContentLoaded', function() {
|
||||||
|
console.log('DOM Content Loaded');
|
||||||
|
|
||||||
// Add event listener for the empty trash button
|
// Add event listener for the empty trash button
|
||||||
const emptyTrashBtn = document.getElementById('emptyTrashBtn');
|
const emptyTrashBtn = document.getElementById('emptyTrashBtn');
|
||||||
|
console.log('Empty Trash Button:', emptyTrashBtn);
|
||||||
|
|
||||||
if (emptyTrashBtn) {
|
if (emptyTrashBtn) {
|
||||||
emptyTrashBtn.addEventListener('click', function(e) {
|
emptyTrashBtn.addEventListener('click', function(e) {
|
||||||
|
console.log('Empty Trash Button Clicked');
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
showEmptyTrashModal();
|
showEmptyTrashModal();
|
||||||
});
|
});
|
||||||
@@ -12,8 +87,10 @@ document.addEventListener('DOMContentLoaded', function() {
|
|||||||
|
|
||||||
// Add event listener for the confirm empty trash button
|
// Add event listener for the confirm empty trash button
|
||||||
const confirmEmptyTrashBtn = document.getElementById('confirmEmptyTrash');
|
const confirmEmptyTrashBtn = document.getElementById('confirmEmptyTrash');
|
||||||
|
console.log('Confirm Empty Trash Button:', confirmEmptyTrashBtn);
|
||||||
|
|
||||||
if (confirmEmptyTrashBtn) {
|
if (confirmEmptyTrashBtn) {
|
||||||
confirmEmptyTrashBtn.addEventListener('click', emptyTrash);
|
confirmEmptyTrashBtn.addEventListener('click', window.emptyTrash);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize view
|
// Initialize view
|
||||||
|
|||||||
@@ -16,7 +16,8 @@
|
|||||||
{% if button_url == "#" %}
|
{% if button_url == "#" %}
|
||||||
<button id="emptyTrashBtn"
|
<button id="emptyTrashBtn"
|
||||||
class="btn {{ button_class if button_class else '' }}"
|
class="btn {{ button_class if button_class else '' }}"
|
||||||
style="{{ 'background-color: var(--primary-color); color: white;' if not button_class else '' }}{{ '; ' + button_style if button_style else '' }}">
|
style="{{ 'background-color: var(--primary-color); color: white;' if not button_class else '' }}{{ '; ' + button_style if button_style else '' }}"
|
||||||
|
onclick="showEmptyTrashModal()">
|
||||||
{% if button_icon %}
|
{% if button_icon %}
|
||||||
<i class="fas {{ button_icon }} me-1"></i>
|
<i class="fas {{ button_icon }} me-1"></i>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|||||||
Reference in New Issue
Block a user