/* * 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 dispCurrent(card, current) { var url = card.data("apiurl"); $.post(url, { username: getuser(), password: getAPIKey(), action: "getactivejob" }, function (resp) { if (resp.status == "OK") { if (resp.job == false) { current.html('
None
'); } else { current.html('
' + resp.job.name + '
'); } } else { showmsg(resp.msg, "danger"); } }, "json").fail(function () { card.css("display", "none"); }); } $(".card_qwikclock_jobs").each(function () { var card = $(this); $(this).find(".card_title").prepend("Jobs | "); var btnbin = $(this).find(".btn-bin"); var current = $(this).find(".current-job"); var url = $(this).data("apiurl"); $.post(url, { username: getuser(), password: getAPIKey(), action: "getjobs" }, function (resp) { if (resp.status == "OK") { var jobs = resp.jobs; if (jobs.length > 0) { for (var job in jobs) { btnbin.append('
' + jobs[job]['name'] + '
'); } btnbin.append('
None
'); } else { btnbin.html('
No jobs available.
'); } } else { showmsg(resp.msg, "danger"); } }, "json").fail(function () { card.css("display", "none"); }); dispCurrent(card, current); setInterval(function () { dispCurrent(card, current) }, 2500); }); $(".card_qwikclock_jobs").on("click", ".job-btn", function () { var parent = $(this).parents(".card_app"); var current = parent.find(".current-job"); var url = parent.data("apiurl"); $.post(url, { username: getuser(), password: getAPIKey(), action: "setjob", job: $(this).data("jobid") }, function (resp) { if (resp.status == "OK") { showmsg(' ' + resp.msg, "success"); } else { showmsg(' ' + resp.msg, "danger"); } dispCurrent(parent, current); }, "json"); });