}
public function editTask($pdo, $taskId, $newInput){
- $query = 'UPDATE tasks SET task = WHERE task_id = ;taskId;';
+ $query = 'UPDATE tasks SET task = :newInput WHERE task_id = :taskId;';
$stmt = $pdo->prepare($query);
$stmt->bindParam(':taskId', $taskId);
+ $stmt->bindParam(':newInput', $newInput);
$stmt->execute();
}
-1. encrypt passwords on signup
-2. add a session timer when user logged in
-3. don't give direct access to paths esp. when usr. is not logged in or that path must not be accessible
-4. add a short animation loading progress bar when user did some actions to a task
-6. create 'editing task' feature
-7. create 'task sorting' feature
-8. create 'task search' feature
-9. when popup is open, the main window will be unaccessible
\ No newline at end of file
+-encrypt passwords on signup
+-add a session timer when user logged in
+-don't give direct access to paths esp. when usr. is not logged in or that path must not be accessible
+-add a short animation loading progress bar when user did some actions to a task
+-create 'task sorting' feature
+-create 'task search' feature
+-when popup is open, the main window will be unaccessible
\ No newline at end of file
header('Content-Type: application/json');
if($_SERVER['REQUEST_METHOD'] === 'POST'){
- $taskIds = json_decode(file_get_contents('php://input'), true);
- $newInput = null;
+ $input = json_decode(file_get_contents('php://input'), true);
+
+ $taskId = $input['taskId'] ?? null;
+ $newInput = $input['newInput'] ?? null;
try{
$dbconn = new DbConn();
$userId = $_SESSION['user_data']['user_id'];
$tasks = new Tasks($pdo, $userId);
- $error = $tasks->error;
-
- foreach($taskIds as $taskId){
- $tasks->isInputEmpty($taskId);
- if(empty($error)){
- $tasks->editTask($pdo, $taskId, $newInput);
- }
+
+ $tasks->isInputEmpty($newInput);
+
+ if(empty($tasks->error)){
+ $tasks->editTask($pdo, $taskId, $newInput);
+ $response = [
+ 'status' => 'success',
+ 'message' => 'Task deleted successfully!',
+ ];
+ } else {
+ $response = [
+ 'status' => 'failed',
+ 'message' => 'Failed to delete task.',
+ ];
}
+ echo json_encode($response);
+
} catch(PDOException $e){
die("Query failed: {$e}");
}
//===== EDIT TASK =====//
function editTask(){
- const taskInput = document.getElementById('edit-input-task-name');
- const formData = new FormData(editTaskForm);
- const taskName = formData.get('edit-input-task-name').trim();
+ const taskName = document.getElementById('edit-input-task-name').value.trim();
// replace placeholder text when no input
if(!taskName){
- taskInput.placeholder = 'Please fill this input...';
+ document.getElementById('edit-input-task-name').placeholder = 'Please fill this input...';
return;
}
+ const payload = {
+ taskId: isCheckedArray[0],
+ newInput: taskName
+ };
+
fetch('./includes/edit_task.php', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
- body: JSON.stringify(isCheckedArray)
+ body: JSON.stringify(payload)
})
.then(function(response){
console.log(response);
setTimeout(function(){
loadTasks();
}, 500);
- // setDisabledAttributesOnEditBtn();
+ setDisabledAttributesOnEditBtn();
+ popupEditTaskClose();
})
.catch(function(error){
console.error(error);
function resetTaskInputPlaceholderForEditBtn(){
const taskInput = document.getElementById('edit-input-task-name');
setTimeout(function(){
- taskInput.placeholder = 'New task...';
+ taskInput.placeholder = 'Edit task...';
}, 200);
}