Save tasks in JSON pretty print, and fixed todo.html addtask()
This commit is contained in:
parent
a701c2974c
commit
34e0f341ef
|
@ -1,2 +1,3 @@
|
|||
/tos.html-old
|
||||
/sitemap.xml
|
||||
/staff/tasks.json
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?php
|
||||
// Load tasks from the flat-file database (tasks.txt)
|
||||
$tasks = file_exists("tasks.txt") ? explode("\n", file_get_contents("tasks.txt")) : [];
|
||||
// Load tasks from the flat-file database (tasks.json)
|
||||
$tasks = file_exists("tasks.json") ? json_decode(file_get_contents("tasks.json")) : [];
|
||||
echo json_encode($tasks);
|
||||
?>
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
<?php
|
||||
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
||||
$data = json_decode(file_get_contents("php://input"), true);
|
||||
|
||||
var_dump($data);
|
||||
// Store tasks in a flat-file database (tasks.txt)
|
||||
file_put_contents("tasks.txt", implode("\n", $data["tasks"]));
|
||||
$ret = file_put_contents("tasks.json", json_encode($data["tasks"], JSON_PRETTY_PRINT));
|
||||
var_dump($ret);
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -57,8 +57,35 @@
|
|||
|
||||
<script>
|
||||
function addTask() {
|
||||
// Existing addTask function remains the same
|
||||
var taskInput = document.getElementById("taskInput");
|
||||
var assigneeInput = document.getElementById("assigneeInput");
|
||||
var taskList = document.getElementById("taskList");
|
||||
|
||||
if (taskInput.value.trim() === "") {
|
||||
alert("Please enter a task!");
|
||||
return;
|
||||
}
|
||||
|
||||
var listItem = document.createElement("li");
|
||||
listItem.className = "taskItem";
|
||||
|
||||
var taskText = document.createTextNode(taskInput.value + " - Assigned to: " + assigneeInput.value);
|
||||
listItem.appendChild(taskText);
|
||||
|
||||
var deleteButton = document.createElement("span");
|
||||
deleteButton.className = "deleteButton";
|
||||
deleteButton.innerHTML = "Delete";
|
||||
deleteButton.onclick = function() {
|
||||
taskList.removeChild(listItem);
|
||||
saveTasks(); // Save tasks after deleting one
|
||||
};
|
||||
|
||||
listItem.appendChild(deleteButton);
|
||||
|
||||
taskList.appendChild(listItem);
|
||||
|
||||
taskInput.value = "";
|
||||
assigneeInput.value = "";
|
||||
saveTasks(); // Save tasks after adding one
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue