You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Station/www/cards/js/qwikclock_jobs.js

78 lines
2.7 KiB
JavaScript

/*
* 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('<div class="btn btn-default btn-sm">None</div>');
} else {
current.html('<div class="btn btn-' + resp.job.color + ' btn-sm">' + resp.job.name + '</div>');
}
} 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('<div class="btn bin-btn btn-' + jobs[job]['color'] + '" data-jobid="' + jobs[job]['id'] + '">' + jobs[job]['name'] + '</div>');
}
btnbin.append('<div class="btn bin-btn btn-red" data-jobid="-1"><i class="fas fa-times"></i> None</div>');
} else {
btnbin.html('<div class="alert alert-primary"><i class="fas fa-info-circle"></i> No jobs available.</div>');
}
} 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('<i class="fas fa-check"></i> ' + resp.msg, "success");
} else {
showmsg('<i class="fas fa-times"></i> ' + resp.msg, "danger");
}
dispCurrent(parent, current);
}, "json");
});