]> git repositories - QuestLog.git/commitdiff
edit task feature done
authorbochard <mail@tenkyuu.dev>
Wed, 11 Jun 2025 09:55:01 +0000 (17:55 +0800)
committerbochard <mail@bochard.net>
Thu, 17 Jul 2025 11:41:16 +0000 (19:41 +0800)
Classes/Tasks.php
TODO.TXT
includes/edit_task.php
js/tasks.js

index 236d7bf5991c4a91c13bf77310cecf6df7919114..0089e3a835e354376100b1f94f6ab96b2deb4a72 100644 (file)
@@ -35,9 +35,10 @@ class Tasks extends DbConn {
   }
 
   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();
   }
 
index d8e941aadf2effb699dbbae43e89335daa2bca4b..76f2474ac6ba2839cb4bd77ed3c43e8598be885f 100644 (file)
--- a/TODO.TXT
+++ b/TODO.TXT
@@ -1,8 +1,7 @@
-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
index 0c8001e38a5745fbe1a7b1cc91045dee9c568471..48e8e5fce6190ac430bd5160476d90d3b47ea706 100644 (file)
@@ -10,8 +10,10 @@ require_once __DIR__ . '/../Classes/Tasks.php';
 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();
@@ -19,15 +21,24 @@ if($_SERVER['REQUEST_METHOD'] === 'POST'){
     
     $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}");
   }
index 893fa8d4221e4e71b13c1cb5bb53392dc7bc5da7..927d2d395caa3a111a5c5a6b3de68bd12db04358 100644 (file)
@@ -121,20 +121,23 @@ function addTask(){
 
 //===== 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);
@@ -145,7 +148,8 @@ function editTask(){
     setTimeout(function(){
     loadTasks();
     }, 500);
-    // setDisabledAttributesOnEditBtn();
+    setDisabledAttributesOnEditBtn();
+    popupEditTaskClose();
   })
   .catch(function(error){
     console.error(error);
@@ -187,7 +191,7 @@ function resetTaskInputPlaceholderForAddBtn(){
 function resetTaskInputPlaceholderForEditBtn(){
   const taskInput = document.getElementById('edit-input-task-name');
   setTimeout(function(){
-    taskInput.placeholder = 'New task...';
+    taskInput.placeholder = 'Edit task...';
   }, 200);
 }