diff --git a/Controller/NotesController.php b/Controller/NotesController.php index 2168046..76f31c7 100644 --- a/Controller/NotesController.php +++ b/Controller/NotesController.php @@ -88,8 +88,12 @@ class NotesController public function deleteNote() { - $noteId = $_GET['id']; - $this->notesModel->deleteNote($noteId, $_SESSION['user_id']); + if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['note_id'])) { + $noteId = $_POST['note_id']; + $this->notesModel->deleteNote($noteId, $_SESSION['user_id']); + } + header("Location: ?controller=Notes&page=showNotes&do=showNotes"); + exit(); } } \ No newline at end of file diff --git a/JavaScript/script.js b/JavaScript/script.js index 17ec5b2..d3d87c0 100644 --- a/JavaScript/script.js +++ b/JavaScript/script.js @@ -1,4 +1,3 @@ -// public/script.js document.addEventListener('DOMContentLoaded', () => { // --- Password Strength Checker for Registration --- const passwordInput = document.getElementById('password'); @@ -58,60 +57,7 @@ document.addEventListener('DOMContentLoaded', () => { if(passwordInput.value) passwordInput.dispatchEvent(new Event('input')); } - // --- Delete Note Confirmation and AJAX --- - document.querySelectorAll('.delete-note-btn').forEach(button => { - button.addEventListener('click', function(e) { - e.preventDefault(); - if (confirm('Are you sure you want to delete this note?')) { - const noteId = this.dataset.noteId; - - // Create a temporary form to submit for delete - const tempForm = document.createElement('form'); - tempForm.method = 'POST'; - tempForm.style.display = 'none'; - - const actionInput = document.createElement('input'); - actionInput.type = 'hidden'; - actionInput.name = 'action'; - actionInput.value = 'delete_note'; - tempForm.appendChild(actionInput); - - const noteIdInput = document.createElement('input'); - noteIdInput.type = 'hidden'; - noteIdInput.name = 'note_id'; - noteIdInput.value = noteId; - tempForm.appendChild(noteIdInput); - - document.body.appendChild(tempForm); // Form must be in DOM to submit - - // Use handleAjaxForm for consistency - const formData = new FormData(tempForm); - fetch('?controller=Notes&do=showNotes', { - method: 'POST', - body: formData - }) - .then(response => response.json()) - .then(data => { - displayMessage(data.message, data.success ? 'success' : 'danger'); - if (data.success) { - // Refresh page or remove row dynamically for better UX - // For simplicity, reload. A more advanced way is to find and remove table row. - setTimeout(() => { window.location.reload(); }, 1000); - } - }) - .catch(error => { - console.error('Error:', error); - displayMessage('An error occurred during deletion.', 'danger'); - }) - .finally(() => { - document.body.removeChild(tempForm); // Clean up - }); - } - }); - }); - // --- Drag and Drop File Upload --- - // ... (no changes from previous, ensure it's present) const dropZone = document.getElementById('drop-zone'); const noteTitleInput = document.getElementById('title'); const noteContentInput = document.getElementById('content'); diff --git a/Views/Notes/showNotes.phtml b/Views/Notes/showNotes.phtml index 667448f..2eb3a13 100644 --- a/Views/Notes/showNotes.phtml +++ b/Views/Notes/showNotes.phtml @@ -56,7 +56,12 @@