/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
function loadTaskCards() {
$(".card_taskfloor_viewtasks").each(function () {
var card = $(this);
if (!$(this).find(".card_title").text().startsWith("Tasks | ")) {
$(this).find(".card_title").prepend("Tasks | ");
}
var tasklist = $(this).find(".task-list");
var url = $(this).data("apiurl");
$.post(url, {
username: getuser(),
password: getAPIKey(),
action: "gettasks"
}, function (resp) {
if (resp.status == "OK") {
tasklist.html("");
var tasks = resp.tasks;
for (var i = 0; i < tasks.length; i++) {
var taskhtml =
'
'
+ '
'
+ '
' + tasks[i]['title'] + '
'
+ ''
+ '
' + tasks[i]['description'] + '
'
+ '
';
if (tasks[i]['status'] == "0") {
taskhtml += '
Start
';
} else if (tasks[i]['status'] == "1") {
taskhtml += '
Finish
';
taskhtml += '
Pause
';
taskhtml += '
Problem
';
} else if (tasks[i]['status'] == "3" || tasks[i]['status'] == "4") {
taskhtml += '
Continue
';
}
taskhtml += '
\n
';
tasklist.append(taskhtml);
}
} else {
showmsg(resp.msg, "danger");
}
}, "json").fail(function () {
card.css("display", "none");
});
});
}
loadTaskCards();
$(".card_taskfloor_viewtasks").on("click", ".status-btn", function () {
var cardapp = $(this).parents(".card_app");
var taskitem = $(this).parents(".task");
var url = cardapp.data("apiurl");
$.post(url, {
username: getuser(),
password: getAPIKey(),
action: "updatetask",
taskid: taskitem.data("taskid"),
status: $(this).data("status")
}, function (resp) {
if (resp.status == "OK") {
showmsg(' ' + resp.msg, "success");
} else {
showmsg(' ' + resp.msg, "danger");
}
loadTaskCards();
}, "json");
});