From 30a5f72a35e5d07b69a7a5e3dd665d5a140cf275 Mon Sep 17 00:00:00 2001 From: Thayol Date: Mon, 5 Jul 2021 16:55:48 +0200 Subject: [PATCH] Add more timestamps and details. --- index.php | 46 +++++++++++++++++++++++++++++++++++++--- templates/add-form.html | 7 +++--- templates/main-item.html | 10 +++++++++ templates/script.js | 39 +++++++++++++++++++++++++++------- 4 files changed, 88 insertions(+), 14 deletions(-) diff --git a/index.php b/index.php index a5677b9..dc3f6f0 100644 --- a/index.php +++ b/index.php @@ -285,6 +285,12 @@ else if (!empty($_POST["action"])) } $now = time(); + $created = $now; + + if (!empty($id_to_edit) && !empty($model["list"][$id_to_edit]) && !empty($model["list"][$id_to_edit]["created"])) + { + $created = $model["list"][$id_to_edit]["created"]; + } if (empty($model["list"])) { @@ -296,7 +302,7 @@ else if (!empty($_POST["action"])) "description" => $description, "deadline" => $deadline, "category" => $category, - "created" => $now, + "created" => $created, "modified" => $now, ); @@ -503,10 +509,44 @@ function todo_list(array $model = []) : string $te->set_block_template("MAIN_ITEM_SUMMARY", "MAIN_ITEM_SUMMARY_DESC"); } + unset($deadline); + $deadline = date("Y-m-d", intval($item["deadline"])); + if (empty($deadline)) + { + $deadline = "N/A"; + } + + unset($created); + $created = date("Y-m-d", intval($item["created"])); + if (empty($created)) + { + $created = "N/A"; + } + + unset($modified); + $modified = date("Y-m-d", intval($item["modified"])); + if (empty($modified)) + { + $modified = "N/A"; + } + + unset($category); + $category = $item["category"]; + $category_raw = $item["category"]; + if (empty($category)) + { + $category = "Uncategorized"; + } + $te->append_argumented_block("MAIN_CATEGORY_ITEMS", "MAIN_ITEM", [ "MAIN_ITEM_ID" => $key, - "MAIN_ITEM_TITLE" => $item["title"], - "MAIN_ITEM_DESCRIPTION" => $item["description"], + "MAIN_ITEM_TITLE" => str_replace([ "\"", "'" ], [ """, "'" ], $item["title"]), + "MAIN_ITEM_DESCRIPTION" => str_replace([ "\"", "'" ], [ """, "'" ], $item["description"]), + "MAIN_ITEM_CATEGORY" => str_replace([ "\"", "'" ], [ """, "'" ], $category), + "MAIN_ITEM_CATEGORY_RAW" => $category_raw, + "MAIN_ITEM_DEADLINE" => $deadline, + "MAIN_ITEM_CREATED" => $created, + "MAIN_ITEM_MODIFIED" => $modified, ]); } diff --git a/templates/add-form.html b/templates/add-form.html index 92ab5f5..e1754e6 100644 --- a/templates/add-form.html +++ b/templates/add-form.html @@ -1,8 +1,9 @@
- New + New
- + +

{{ ADD_NOTICE }}

@@ -30,7 +31,7 @@
- +
diff --git a/templates/main-item.html b/templates/main-item.html index 6d59364..bf1d88d 100644 --- a/templates/main-item.html +++ b/templates/main-item.html @@ -2,6 +2,12 @@
{{ MAIN_ITEM_SUMMARY }} + Created: {{ MAIN_ITEM_CREATED }}
+ Modified: {{ MAIN_ITEM_MODIFIED }}
+ Deadline: {{ MAIN_ITEM_DEADLINE }}
+ Category: {{ MAIN_ITEM_CATEGORY }}
+
+
@@ -35,6 +41,10 @@
+ + +
+
diff --git a/templates/script.js b/templates/script.js index 78d29e3..6feabd9 100644 --- a/templates/script.js +++ b/templates/script.js @@ -1,16 +1,39 @@ +var autoClose = true; + document.addEventListener("DOMContentLoaded", function(){ // Fetch all the details element. const details = document.querySelectorAll("details"); // Add the onclick listeners. details.forEach((targetDetail) => { - targetDetail.addEventListener("click", () => { - // Close all the details that are not targetDetail. - details.forEach((detail) => { - if (detail !== targetDetail) { - detail.removeAttribute("open"); - } + targetDetail.addEventListener("click", () => { + // Close all the details that are not targetDetail. + if (autoClose) { + details.forEach((detail) => { + if (detail !== targetDetail) { + detail.removeAttribute("open"); + } + }); + } }); - }); }); -}); \ No newline at end of file +}); + +function editNote(id, title, description, deadline, category) { + document.getElementById("add_form_action").value = "edit"; + document.getElementById("add_form_button").value = "Edit"; + + document.getElementById("todo_item_id").value = id.toString(); + document.getElementById("todo_title").value = title; + document.getElementById("todo_description").value = description; + document.getElementById("todo_deadline").value = deadline; + document.getElementById("todo_category").value = category; + + setTimeout( + function() { + document.getElementById("addFormSummary").click(); + }, + 5); + + // document.getElementById("addFormSummary").click(); +} \ No newline at end of file