This commit is contained in:
2025-05-01 14:42:12 -06:00
parent 693d11c506
commit bd59f428ba
13 changed files with 288 additions and 124 deletions
+2 -63
View File
@@ -15,72 +15,11 @@
document.addEventListener('DOMContentLoaded', function() {
var todos = document.getElementsByClassName('todo_item');
var action_items = (document.getElementById('todo_actions')).querySelectorAll('button');
// General Modal handling
function handle_modal(modal) {
console.log('handling modal');
let modal_close = modal.querySelector('.modal_close');
let submit_button = modal.querySelector('input[type="submit"]');
modal.style.display = 'block';
modal_close.addEventListener('click', function() {
modal.style.display = "none";
});
submit_button.addEventListener('click', function(e) {
e.preventDefault();
let todo = {
'title': modal.querySelector('#title').value,
'description': modal.querySelector('#description'),
'priority': modal.querySelector('#priority'),
'due_date': modal.querySelector('#due_date'),
};
fetch('director.php', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
body: 'ajax_id=todo&action_id=create_update_todo&todo_id=' + this.todo_id + '&todo=' + encodeURIComponent(JSON.stringify(todo)),
})
.then(response => {
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
return response.json(); // Or handle other response formats
})
.then(responseData => {
console.log('Response received:', responseData);
// Handle the server's response
});
});
}
for (let i = 0; i < action_items.length; i++) {
let action = action_items[i];
action.addEventListener('click', function(e) {
e.preventDefault();
switch (action.value) {
case 'new':
let new_todo_item = document.querySelector('#new_todo_item');
handle_modal(new_todo_item);
break;
}
});
}
//var todos = document.querySelectorAll('todo_item');
for (let i = 0; i < todos.length; i++) {
let item = todos[i];
var item = todos[i];
// Detailed todo item view via a modal
let modal_button = item.querySelector('.modal_activation_area');
let modal = item.querySelector('.modal');
modal_button.addEventListener('click', () => handle_modal(modal));
// Checkboxes & AJAX for updating the DB
var checkbox = item.querySelector('input[type="checkbox"]');
checkbox.todo_id = item.querySelector('input[name="todo_id"]').value;
checkbox.is_checked = checkbox.checked;