267 lines
8.6 KiB
JavaScript
267 lines
8.6 KiB
JavaScript
let chart;
|
|
const TASKCOMPLETE = true;
|
|
const TASKINCOMPLETE = false;
|
|
|
|
$(document).ready(function() {
|
|
$("#tabs").tabs({ active: 0 });
|
|
$("#form_duedate").datepicker();
|
|
$("#form_submit").on("click", function() { submitTask(); });
|
|
$("#form_delete").on("click", function() { deleteTask(); });
|
|
$("#form_showall").on("change", function() { toggleShowAll(); });
|
|
$("#form_setcomplete").on("click", function() { setTaskCompleteState(TASKCOMPLETE); });
|
|
$("#form_setincomplete").on("click", function() { setTaskCompleteState(TASKINCOMPLETE); });
|
|
$("#form_cancel").on("click", function() { resetForm(true); });
|
|
$("#filter_reset").on("click", function() { $("#form_filter").val(""); });
|
|
$("#panelimg").on("click", function() { updateImage(); });
|
|
$("#tab-tasks").on("click", function() { getTasks(); });
|
|
$("#tasklist").on("click", ".task", function() { editTask(this.dataset.id); });
|
|
getTasks();
|
|
let chartOptions = {
|
|
chart: {
|
|
type: 'bar',
|
|
height: 550
|
|
},
|
|
plotOptions: {
|
|
bar: {
|
|
horizontal: false,
|
|
columnWidth: '80%',
|
|
endingShape: 'rounded'
|
|
}
|
|
},
|
|
dataLabels: {
|
|
enabled: false
|
|
},
|
|
xaxis: {
|
|
categories: ['6','5','4','3','2','1']
|
|
},
|
|
yaxis: {
|
|
title: {
|
|
text: 'Task Count'
|
|
}
|
|
},
|
|
series: [],
|
|
noData: {
|
|
text: 'Loading...'
|
|
}
|
|
}
|
|
chart = new ApexCharts($("#chart")[0], chartOptions);
|
|
chart.render();
|
|
updateChart();
|
|
});
|
|
|
|
function updateImage() {
|
|
console.log("Getting image...");
|
|
$("#panelimg").attr("src", "image.php?"+(Math.floor(Math.random()*100000)));
|
|
updateChart();
|
|
}
|
|
|
|
function updateChart() {
|
|
$.ajax({
|
|
url: 'ajax/task-getstats.php',
|
|
dataType: 'json',
|
|
success: function(data, stat, jqo) {
|
|
chart.updateSeries([{
|
|
name: 'Created',
|
|
data: data.createdtasks
|
|
},{
|
|
name: 'Completed',
|
|
data: data.completedtasks
|
|
}])
|
|
},
|
|
error: function(jqo, stat, error) {
|
|
toastr.error("Could not communicate with server!", "Server Error");
|
|
}
|
|
});
|
|
}
|
|
|
|
function deleteTask() {
|
|
if ( $("#form_id").val() == "0" ) return;
|
|
const doDelete = confirm("Are you certain you wish to delete this task?\n\nIf so then click 'OK'.")
|
|
if ( !doDelete ) return;
|
|
$.ajax({
|
|
url: 'ajax/task-delete.php',
|
|
type: 'POST',
|
|
dataType: 'json',
|
|
data: {
|
|
id: $("#form_id").val(),
|
|
},
|
|
success: function(data, stat, jqo) {
|
|
if ( data.error ) {
|
|
toastr.error(data.message, "Submission Error");
|
|
} else {
|
|
toastr.success(data.message, "Task Deleted");
|
|
getTasks();
|
|
updateImage();
|
|
resetForm(true);
|
|
}
|
|
},
|
|
error: function(jqo, stat, error) {
|
|
toastr.error("Could not communicate with server!", "Server Error");
|
|
}
|
|
});
|
|
}
|
|
|
|
function setTaskCompleteState(complete = TASKCOMPLETE) {
|
|
if ( $("#form_id").val() == "0" ) return;
|
|
$.ajax({
|
|
url: 'ajax/task-setcomplete.php',
|
|
type: 'POST',
|
|
dataType: 'json',
|
|
data: {
|
|
id: $("#form_id").val(),
|
|
complete: (complete) ? 1 : 0
|
|
},
|
|
success: function(data, stat, jqo) {
|
|
if ( data.error ) {
|
|
toastr.error(data.message, "Submission Error");
|
|
return;
|
|
}
|
|
toastr.success(data.message, (data.task.completed) ? "Task Complete" : "Task Incomplete");
|
|
getTasks();
|
|
updateImage();
|
|
resetForm(true);
|
|
},
|
|
error: function(jqo, stat, error) {
|
|
toastr.error("Could not communicate with server!", "Server Error");
|
|
}
|
|
});
|
|
}
|
|
|
|
function toggleShowAll() {
|
|
const previousValue = ! $("#form_showall").prop('checked');
|
|
$.ajax({
|
|
url: 'ajax/toggleshowall.php',
|
|
type: 'POST',
|
|
dataType: 'json',
|
|
data: {
|
|
showall: ($("#form_showall").prop('checked')) ? 1 : 0,
|
|
},
|
|
success: function(data, stat, jqo) {
|
|
if ( data.error ) {
|
|
toastr.error(data.message, "Form Data Error");
|
|
$("#form_showall").prop('checked', previousValue);
|
|
return;
|
|
}
|
|
$("#form_showall").prop('checked', data.showall);
|
|
toastr.success(data.message, "Task List");
|
|
getTasks();
|
|
},
|
|
error: function(jqo, stat, error) {
|
|
toastr.error("Could not communicate with server!", "Server Error");
|
|
$("#form_showall").prop('checked', previousValue);
|
|
}
|
|
});
|
|
}
|
|
|
|
function submitTask() {
|
|
$("#form_submit").prop("disabled", true);
|
|
$.ajax({
|
|
url: 'ajax/task-submit.php',
|
|
type: 'POST',
|
|
dataType: 'json',
|
|
data: {
|
|
id: $("#form_id").val(),
|
|
title: $("#form_title").val(),
|
|
description: $("#form_description").val(),
|
|
priority: $("#form_priority").val(),
|
|
duedate: $("#form_duedate").val()
|
|
},
|
|
success: function(data, stat, jqo) {
|
|
if ( data.error ) {
|
|
toastr.error(data.message, "Form Data Error");
|
|
} else {
|
|
toastr.success(data.message, "Success");
|
|
getTasks();
|
|
resetForm(true);
|
|
updateImage();
|
|
}
|
|
},
|
|
error: function(jqo, stat, error) {
|
|
toastr.error("Could not communicate with server!", "Server Error");
|
|
},
|
|
complete: function() {
|
|
$("#form_submit").prop("disabled", false);
|
|
}
|
|
});
|
|
}
|
|
|
|
function resetForm(backToTasks = false) {
|
|
if ( backToTasks ) $("#tabs").tabs("option", "active", 0);
|
|
$("#form_id").val("0");
|
|
$("#form_title").val("");
|
|
$("#form_description").val("");
|
|
$("#form_createdate").text("Now");
|
|
$("#form_duedate").val("");
|
|
$("#form_completedate").html("");
|
|
$("#form_completerow").addClass("noshow");
|
|
$("#column_deletebutton").addClass("noshow");
|
|
$("#column_incompletebutton").addClass("noshow");
|
|
$("#column_completebutton").addClass("noshow");
|
|
}
|
|
|
|
function getTasks() {
|
|
$.ajax({
|
|
url: 'ajax/task-list.php',
|
|
dataType: 'json',
|
|
success: function(data, stat, jqo) {
|
|
$("#form_showall").prop('checked', data.showalltasks);
|
|
let show = "";
|
|
data.tasks.forEach(function(task, index) {
|
|
show += "<div class='task' data-id='" + task.id + "'>";
|
|
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'>Priority: </span>" + task.priority + "</div>";
|
|
show += "<div><span class='strongtext'>Created On: </span>" + task.createdate + "</div>";
|
|
show += "<div><span class='strongtext'>Due Date: </span>" + task.duedate + "</div>";
|
|
show += "<div><span class='strongtext'>Days Left: </span>" + task.daysleft + "</div>";
|
|
show += "</div>";
|
|
});
|
|
$("#tasklist").html(show);
|
|
},
|
|
error: function(jqo, stat, error) {
|
|
toastr.error("Could not communicate with server!", "Server Error");
|
|
}
|
|
});
|
|
}
|
|
|
|
function editTask(taskId) {
|
|
$.ajax({
|
|
url: 'ajax/task-get.php',
|
|
dataType: 'json',
|
|
data: {
|
|
id: taskId
|
|
},
|
|
success: function(data, stat, jqo) {
|
|
if ( !data.error ) {
|
|
$("#form_id").val(data.task.id);
|
|
$("#form_title").val(data.task.title);
|
|
$("#form_description").val(data.task.description);
|
|
$("#form_priority").val(data.task.priority);
|
|
$("#form_duedate").val(data.task.duedate);
|
|
$("#form_createdate").text(data.task.createdate);
|
|
if ( data.task.completed ) {
|
|
$("#form_completedate").text(data.task.completedate);
|
|
$("#form_completerow").removeClass("noshow");
|
|
$("#column_incompletebutton").removeClass("noshow");
|
|
$("#column_completebutton").addClass("noshow");
|
|
} else {
|
|
$("#form_completedate").text("");
|
|
$("#form_completerow").addClass("noshow");
|
|
$("#column_incompletebutton").addClass("noshow");
|
|
$("#column_completebutton").removeClass("noshow");
|
|
}
|
|
$("#column_deletebutton").removeClass("noshow");
|
|
$("#tabs").tabs("option", "active", 1);
|
|
updateImage();
|
|
} else {
|
|
toastr.warning("Task not found!", "Task Error");
|
|
}
|
|
},
|
|
error: function(jqo, stat, error) {
|
|
toastr.error("Could not communicate with server!", "Server Error");
|
|
}
|
|
});
|
|
}
|
|
|
|
// vim: ts=3 sw=3:
|