Compare commits

...

24 Commits

Author SHA1 Message Date
6f6c605cc9 Fix a few bugs and edge cases in conditional logic 2026-11-22 14:38:34 -05:00
c09ab3c48e Make sure a task object is returned when setting completion state 2026-11-22 14:30:52 -05:00
34af4254a2 Make sure the form_id value starts at 0 2026-11-22 14:24:44 -05:00
e3b7d9351f Add error handling if there is a problem getting the task list 2026-11-22 14:24:26 -05:00
445dae586e Disable completion buttons during ajax calls to back-end 2026-11-22 14:21:02 -05:00
7cf29a7607 Make completion logic more robust and readable 2026-11-22 14:18:03 -05:00
6b16ddfc31 Ensure show all tasks checkbox stays in better sync with the server 2026-11-22 14:05:23 -05:00
a9a4667231 block consecutive task submissions until the previous click has resolved 2026-11-22 13:54:21 -05:00
54baa5c305 Clean up conditional logic 2026-11-22 13:50:51 -05:00
13e1607d40 Delete legacy manual form reset and only use the dedicated function for resetting 2026-11-22 13:50:11 -05:00
fdea1600f3 Make a document level event handler for clicking on tasks in the list instead of rebuilding it every refresh 2026-11-22 13:22:21 -05:00
dc52cc86f6 Change show all checkbox to watch for change instead of click 2026-11-22 13:13:19 -05:00
39678d34c1 Change to let/const instead of var 2026-11-22 13:06:12 -05:00
5b4118f20d Fix setting form_createdate with text() instead of val() 2026-11-22 13:04:42 -05:00
db2e8ede95 Improve spacing on task tab 2026-11-22 13:03:08 -05:00
176fc0736b Fix display of completion date if task is completed when editing 2026-11-22 13:01:10 -05:00
8f47e90251 Fix the completed boolean of tasks in the class and set the toast accordingly 2026-11-22 12:51:51 -05:00
6222ca71a4 Reset form_id to 0 value string instead of empty string to improve validation checks 2026-11-22 12:40:48 -05:00
d4a53f0844 Fix reference to form_createdate instead of the incorrect form_createrow 2026-11-22 12:38:27 -05:00
18b9a73cc7 Fix toastr reference bug. Type is warning, not warn 2026-11-22 12:31:50 -05:00
f3e32d4d92 Switch click event definitions to the more modern style 2026-11-22 12:26:05 -05:00
c59df02d6f Configure ajax calls to use POST type where appropriate 2026-11-22 12:24:03 -05:00
5514113103 Update task list when tasks tab is clicked 2026-11-22 11:58:05 -05:00
cd3b1dbe7a Switch back to inverted colors with new BW display 2026-11-22 11:42:25 -05:00
6 changed files with 72 additions and 48 deletions

View File

@ -10,7 +10,7 @@ $data["error"] = false;
if ( !isset($_REQUEST['id']) ) pushData("Invalid completion request"); if ( !isset($_REQUEST['id']) ) pushData("Invalid completion request");
$task = new Task(intval($_REQUEST['id'])); $task = new Task(intval($_REQUEST['id']));
if ( $task->getID() == 0 ) pushData("Task not found"); if ( $task->getID() == 0 ) pushData("Task not found");
if ( isset($_REQUEST['incomplete']) && ($_REQUEST['incomplete'] == "1") ) { if ( isset($_REQUEST['complete']) && ($_REQUEST['complete'] == "0") ) {
$task->setCompleteTime(Task::INCOMPLETE); $task->setCompleteTime(Task::INCOMPLETE);
} else { } else {
$task->setCompleteTime(Task::NOW); $task->setCompleteTime(Task::NOW);

View File

@ -58,12 +58,13 @@ class Task implements JsonSerializable {
} }
public function getCompleted($flag = 0) { public function getCompleted($flag = 0) {
$completed = (is_null($this->getCompleteTime())) ? false : true;
switch ($flag) { switch ($flag) {
case AppDB::BOOLEANDB: case AppDB::BOOLEANDB:
return ($this->completed) ? "true" : "false"; return ($completed) ? "true" : "false";
break; break;
default: default:
return $this->completed; return $completed;
break; break;
} }
} }
@ -220,6 +221,7 @@ class Task implements JsonSerializable {
'createdate' => $this->getCreateTime(SHORTDATE), 'createdate' => $this->getCreateTime(SHORTDATE),
'duetime' => $this->getDueTime(), 'duetime' => $this->getDueTime(),
'duedate' => $this->getDueTime(SHORTDATE), 'duedate' => $this->getDueTime(SHORTDATE),
'completed' => $this->getCompleted(),
'completetime' => $this->getCompleteTime(), 'completetime' => $this->getCompleteTime(),
'completedate' => $this->getCompleteTime(SHORTDATE) 'completedate' => $this->getCompleteTime(SHORTDATE)
]; ];

View File

@ -46,6 +46,7 @@ div.mainbody {
flex-basis: 100%; flex-basis: 100%;
flex: 2; flex: 2;
text-align: left; text-align: left;
padding-left: 0.75em;
} }
.inline { .inline {
display: inline; display: inline;

View File

@ -11,6 +11,8 @@ $deg = html_entity_decode("°");
$image = imagecreate(480, 800); $image = imagecreate(480, 800);
$white = imagecolorallocate($image, 0, 0, 0); $white = imagecolorallocate($image, 0, 0, 0);
$black = imagecolorallocate($image, 255, 255, 255); $black = imagecolorallocate($image, 255, 255, 255);
//$white = imagecolorallocate($image, 255, 255, 255);
//$black = imagecolorallocate($image, 0, 0, 0);
//$red = imagecolorallocate($image, 255, 0, 0); //$red = imagecolorallocate($image, 255, 0, 0);
$red = $black; $red = $black;
$transparent = imagecolorallocatealpha($image, 255, 255, 255, 127); $transparent = imagecolorallocatealpha($image, 255, 255, 255, 127);

View File

@ -10,7 +10,7 @@ include "htmlheader.php";
<div id='mainbody' class='mainbody'> <div id='mainbody' class='mainbody'>
<div id="tabs"> <div id="tabs">
<ul> <ul>
<li><a href="#tasks">Tasks</a></li> <li id="tab-tasks"><a href="#tasks">Tasks</a></li>
<li><a href="#newtask">New Task</a></li> <li><a href="#newtask">New Task</a></li>
<li><a href="#stats">Stats</a></li> <li><a href="#stats">Stats</a></li>
<li><a href="#panel">Img</a></li> <li><a href="#panel">Img</a></li>
@ -44,7 +44,7 @@ include "htmlheader.php";
</div> </div>
<div id="newtask"> <div id="newtask">
<p>Editing/Creating Tasks</p> <p>Editing/Creating Tasks</p>
<div class="noshow"><input id="form_id" type="text"></div> <div class="noshow"><input id="form_id" type="text" value="0"></div>
<div class="row"> <div class="row">
<div class="column-left"> <div class="column-left">
Title: Title:

View File

@ -1,19 +1,22 @@
var chart; let chart;
const TASKCOMPLETE = true;
const TASKINCOMPLETE = false;
$(document).ready(function() { $(document).ready(function() {
$("#tabs").tabs({ active: 0 }); $("#tabs").tabs({ active: 0 });
$("#form_duedate").datepicker(); $("#form_duedate").datepicker();
$("#form_submit").click(function() { submitTask(); }); $("#form_submit").on("click", function() { submitTask(); });
$("#form_delete").click(function() { deleteTask(); }); $("#form_delete").on("click", function() { deleteTask(); });
$("#form_showall").click(function() { toggleShowAll(); }); $("#form_showall").on("change", function() { toggleShowAll(); });
$("#form_setcomplete").click(function() { setTaskComplete(); }); $("#form_setcomplete").on("click", function() { setTaskCompleteState(TASKCOMPLETE); });
$("#form_setincomplete").click(function() { setTaskComplete(true); }); $("#form_setincomplete").on("click", function() { setTaskCompleteState(TASKINCOMPLETE); });
$("#form_cancel").click(function() { resetForm(true); }); $("#form_cancel").on("click", function() { resetForm(true); });
$("#filter_reset").click(function() { $("#form_filter").val(""); }); $("#filter_reset").on("click", function() { $("#form_filter").val(""); });
$("#panelimg").click(function() { updateImage(); }); $("#panelimg").on("click", function() { updateImage(); });
//$("#tabs").on("tabsactivate", function(event, ui) { console.log($("#tabs").tabs('option', 'active')); }); $("#tab-tasks").on("click", function() { getTasks(); });
$("#tasklist").on("click", ".task", function() { editTask(this.dataset.id); });
getTasks(); getTasks();
var chartOptions = { let chartOptions = {
chart: { chart: {
type: 'bar', type: 'bar',
height: 550 height: 550
@ -73,10 +76,12 @@ function updateChart() {
function deleteTask() { function deleteTask() {
if ( $("#form_id").val() == "0" ) return; if ( $("#form_id").val() == "0" ) return;
var doDelete = confirm("Are you certain you wish to delete this task?\n\nIf so then click 'OK'.") const doDelete = confirm("Are you certain you wish to delete this task?\n\nIf so then click 'OK'.")
if ( !doDelete ) return; if ( !doDelete ) return;
$("#form_delete").prop("disabled", true);
$.ajax({ $.ajax({
url: 'ajax/task-delete.php', url: 'ajax/task-delete.php',
type: 'POST',
dataType: 'json', dataType: 'json',
data: { data: {
id: $("#form_id").val(), id: $("#form_id").val(),
@ -93,38 +98,52 @@ function deleteTask() {
}, },
error: function(jqo, stat, error) { error: function(jqo, stat, error) {
toastr.error("Could not communicate with server!", "Server Error"); toastr.error("Could not communicate with server!", "Server Error");
},
complete: function() {
$("#form_delete").prop("disabled", false);
} }
}); });
} }
function setTaskComplete(incomplete = false) { function setTaskCompleteState(complete = TASKCOMPLETE) {
if ( $("#form_id").val() == "0" ) return; if ( $("#form_id").val() == "0" ) return;
$("#form_setcomplete, #form_setincomplete").prop("disabled", true);
$.ajax({ $.ajax({
url: 'ajax/task-setcomplete.php', url: 'ajax/task-setcomplete.php',
type: 'POST',
dataType: 'json', dataType: 'json',
data: { data: {
id: $("#form_id").val(), id: $("#form_id").val(),
incomplete: (incomplete) ? 1 : 0 complete: (complete) ? 1 : 0
}, },
success: function(data, stat, jqo) { success: function(data, stat, jqo) {
if ( data.error ) { if ( data.error ) {
toastr.error(data.message, "Submission Error"); toastr.error(data.message, "Submission Error");
} else { return;
toastr.success(data.message, "Task Complete");
getTasks();
updateImage();
resetForm(true);
} }
if ( !data.task ) {
toastr.error("No task returned", "API Error);
return;
}
toastr.success(data.message, (data.task.completed) ? "Task Complete" : "Task Incomplete");
getTasks();
updateImage();
resetForm(true);
}, },
error: function(jqo, stat, error) { error: function(jqo, stat, error) {
toastr.error("Could not communicate with server!", "Server Error"); toastr.error("Could not communicate with server!", "Server Error");
},
complete: function() {
$("#form_setcomplete, #form_setincomplete").prop("disabled", false);
} }
}); });
} }
function toggleShowAll() { function toggleShowAll() {
const previousValue = ! $("#form_showall").prop('checked');
$.ajax({ $.ajax({
url: 'ajax/toggleshowall.php', url: 'ajax/toggleshowall.php',
type: 'POST',
dataType: 'json', dataType: 'json',
data: { data: {
showall: ($("#form_showall").prop('checked')) ? 1 : 0, showall: ($("#form_showall").prop('checked')) ? 1 : 0,
@ -132,21 +151,25 @@ function toggleShowAll() {
success: function(data, stat, jqo) { success: function(data, stat, jqo) {
if ( data.error ) { if ( data.error ) {
toastr.error(data.message, "Form Data Error"); toastr.error(data.message, "Form Data Error");
} else { $("#form_showall").prop('checked', previousValue);
toastr.success(data.message, "Task List"); return;
getTasks();
} }
$("#form_showall").prop('checked', data.showall); $("#form_showall").prop('checked', data.showall);
toastr.success(data.message, "Task List");
getTasks();
}, },
error: function(jqo, stat, error) { error: function(jqo, stat, error) {
toastr.error("Could not communicate with server!", "Server Error"); toastr.error("Could not communicate with server!", "Server Error");
$("#form_showall").prop('checked', previousValue);
} }
}); });
} }
function submitTask() { function submitTask() {
$("#form_submit").prop("disabled", true);
$.ajax({ $.ajax({
url: 'ajax/task-submit.php', url: 'ajax/task-submit.php',
type: 'POST',
dataType: 'json', dataType: 'json',
data: { data: {
id: $("#form_id").val(), id: $("#form_id").val(),
@ -162,31 +185,24 @@ function submitTask() {
toastr.success(data.message, "Success"); toastr.success(data.message, "Success");
getTasks(); getTasks();
resetForm(true); resetForm(true);
$("#form_id").val("");
$("#form_title").val("");
$("#form_description").val("");
$("#form_createdate").val("Now");
$("#form_duedate").val("");
$("#form_completedate").html("");
$("#form_completerow").addClass("noshow");
$("#column_deletebutton").addClass("noshow");
$("#column_incompletebutton").addClass("noshow");
$("#column_completebutton").addClass("noshow");
updateImage(); updateImage();
} }
}, },
error: function(jqo, stat, error) { error: function(jqo, stat, error) {
toastr.error("Could not communicate with server!", "Server Error"); toastr.error("Could not communicate with server!", "Server Error");
},
complete: function() {
$("#form_submit").prop("disabled", false);
} }
}); });
} }
function resetForm(backToTasks = false) { function resetForm(backToTasks = false) {
if ( backToTasks ) $("#tabs").tabs("option", "active", 0); if ( backToTasks ) $("#tabs").tabs("option", "active", 0);
$("#form_id").val(""); $("#form_id").val("0");
$("#form_title").val(""); $("#form_title").val("");
$("#form_description").val(""); $("#form_description").val("");
$("#form_createdate").val("Now"); $("#form_createdate").text("Now");
$("#form_duedate").val(""); $("#form_duedate").val("");
$("#form_completedate").html(""); $("#form_completedate").html("");
$("#form_completerow").addClass("noshow"); $("#form_completerow").addClass("noshow");
@ -200,10 +216,14 @@ function getTasks() {
url: 'ajax/task-list.php', url: 'ajax/task-list.php',
dataType: 'json', dataType: 'json',
success: function(data, stat, jqo) { success: function(data, stat, jqo) {
if ( data.error ) {
toastr.error(data.message, "Error retrieving task list");
return;
}
$("#form_showall").prop('checked', data.showalltasks); $("#form_showall").prop('checked', data.showalltasks);
var show = ""; let show = "";
data.tasks.forEach(function(task, index) { data.tasks.forEach(function(task, index) {
show += "<div class='task' id='task_" + task.id + "'>"; show += "<div class='task' data-id='" + task.id + "'>";
show += "<div><span class='strongtext'>Title: </span>" + task.title_safe + "</div>"; show += "<div><span class='strongtext'>Title: </span>" + task.title_safe + "</div>";
show += "<div><span class='strongtext'>Description: </span>" + task.description_safe + "</div>"; show += "<div><span class='strongtext'>Description: </span>" + task.description_safe + "</div>";
show += "<div><span class='strongtext'>Priority: </span>" + task.priority + "</div>"; show += "<div><span class='strongtext'>Priority: </span>" + task.priority + "</div>";
@ -213,11 +233,6 @@ function getTasks() {
show += "</div>"; show += "</div>";
}); });
$("#tasklist").html(show); $("#tasklist").html(show);
data.tasks.forEach(function(task, index) {
$("#task_"+task.id).click(function() {
editTask(task.id);
});
});
}, },
error: function(jqo, stat, error) { error: function(jqo, stat, error) {
toastr.error("Could not communicate with server!", "Server Error"); toastr.error("Could not communicate with server!", "Server Error");
@ -241,17 +256,21 @@ function editTask(taskId) {
$("#form_duedate").val(data.task.duedate); $("#form_duedate").val(data.task.duedate);
$("#form_createdate").text(data.task.createdate); $("#form_createdate").text(data.task.createdate);
if ( data.task.completed ) { if ( data.task.completed ) {
$("#form_createrow").removeClass("noshow"); $("#form_completedate").text(data.task.completedate);
$("#form_completerow").removeClass("noshow");
$("#column_incompletebutton").removeClass("noshow"); $("#column_incompletebutton").removeClass("noshow");
$("#column_completebutton").addClass("noshow"); $("#column_completebutton").addClass("noshow");
} else { } else {
$("#form_completedate").text("");
$("#form_completerow").addClass("noshow");
$("#column_incompletebutton").addClass("noshow");
$("#column_completebutton").removeClass("noshow"); $("#column_completebutton").removeClass("noshow");
} }
$("#column_deletebutton").removeClass("noshow"); $("#column_deletebutton").removeClass("noshow");
$("#tabs").tabs("option", "active", 1); $("#tabs").tabs("option", "active", 1);
updateImage(); updateImage();
} else { } else {
toastr.warn("Task not found!", "Task Error"); toastr.warning("Task not found!", "Task Error");
} }
}, },
error: function(jqo, stat, error) { error: function(jqo, stat, error) {