feat: Add edit functionality for marketing files and update handling

This commit is contained in:
“VeLiTi”
2026-01-12 10:51:55 +01:00
parent 2520fb2b75
commit be6f73b19c
12 changed files with 222 additions and 1 deletions

BIN
assets/.DS_Store vendored

Binary file not shown.

Binary file not shown.

View File

@@ -100,6 +100,11 @@ class MarketingFileManager {
this.deleteFile(this.selectedFile);
}
});
// Save edit
document.getElementById('saveEdit')?.addEventListener('click', () => {
this.saveEdit();
});
}
bindUploadEvents() {
@@ -359,6 +364,9 @@ class MarketingFileManager {
<button class="download-btn" title="Download">
<i class="fa fa-download"></i>
</button>
<button class="edit-btn" title="Edit">
<i class="fa fa-edit"></i>
</button>
</div>
</div>
<div class="file-info">
@@ -385,6 +393,10 @@ class MarketingFileManager {
this.downloadFile(file);
});
fileElement.querySelector('.edit-btn').addEventListener('click', () => {
this.editFile(file);
});
fileElement.addEventListener('dblclick', () => {
this.previewFile(file);
});
@@ -870,6 +882,96 @@ class MarketingFileManager {
return iconMap[fileType.toLowerCase()] || 'fa-file';
}
// Edit file functionality
editFile(file) {
this.selectedFile = file;
this.showEditModal();
this.populateEditModal(file);
}
showEditModal() {
const modal = document.getElementById('editModal');
if (modal) {
this.showModal(modal);
}
}
populateEditModal(file) {
// Populate title
const titleInput = document.getElementById('editTitle');
if (titleInput) {
titleInput.value = file.title || '';
}
// Populate folder select
const folderSelect = document.getElementById('editFolder');
if (folderSelect) {
folderSelect.innerHTML = '<option value="">Root Folder</option>';
this.addFolderOptions(folderSelect, this.folders);
// Select current folder
if (file.folder_id) {
folderSelect.value = file.folder_id;
}
}
// Populate tags
const tagsInput = document.getElementById('editTags');
if (tagsInput) {
tagsInput.value = file.tags ? file.tags.join(', ') : '';
}
}
saveEdit() {
if (!this.selectedFile) return;
const title = document.getElementById('editTitle').value.trim();
const folderId = document.getElementById('editFolder').value;
const tags = document.getElementById('editTags').value.trim();
// Prepare update data
const updateData = {
file_id: this.selectedFile.id,
title: title || null,
folder_id: folderId || null,
tags: tags ? tags.split(',').map(tag => tag.trim()).filter(tag => tag) : []
};
// Show loading state
const saveBtn = document.getElementById('saveEdit');
const originalText = saveBtn.innerHTML;
saveBtn.innerHTML = '<i class="fa fa-spinner fa-spin"></i> Saving...';
saveBtn.disabled = true;
// Send update request
fetch('./marketing.php?action=update_file', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(updateData)
})
.then(response => response.json())
.then(data => {
if (data.success) {
this.showToast('File updated successfully!', 'success');
this.closeModal(document.getElementById('editModal'));
this.loadFiles(); // Reload to show changes
} else {
throw new Error(data.message || 'Failed to update file');
}
})
.catch(error => {
console.error('Update error:', error);
this.showToast('Error updating file: ' + error.message, 'error');
})
.finally(() => {
// Restore button state
saveBtn.innerHTML = originalText;
saveBtn.disabled = false;
});
}
updateQueueItem(index, item) {
const queueItems = document.querySelectorAll('.upload-item');
if (queueItems[index]) {