var interval = null; function updateStatus() { console.log("update status"); var q = $("#qujo_status").first(); q.addClass('label-inverse'); console.log("status: get"); $.get("/jobs/status", function (d) { console.log("status: return"); q.removeClass('label-inverse'); q.removeClass("label-important"); var j = $("#jobs_status").first(); j.removeClass("badge-important"); j.text(d["jobs"]["count"]); if (d["jobs"]["error"]) { q.addClass("label label-important"); j.addClass("badge-important") } var r = $("#resque_status").first(); r.removeClass("badge-important"); r.text(d["resque"]["count"]); if (d["resque"]["error"]) { q.addClass("label-important"); r.addClass("badge-important") } }).fail(function(d){ var q = $("#qujo_status").first(); var j = $("#jobs_status").first(); j.addClass("badge-important"); j.text('?'); var r = $("#resque_status").first(); r.addClass("badge-important"); r.text('?'); q.addClass("label-important"); console.log("disable interval"); clearInterval(interval); }); } $(function () { if ($("#jobs_status").size()) { interval = setInterval(updateStatus, 2000); } $(".create_job").on("click", function () { var c = $(this).attr("klass"); console.log("create job"); $.post("/jobs", {job: {_type: c}}, function (d) { console.log("create job returned") }); }); $(document).delegate(".job_cancel", "click", function (e) { e.preventDefault(); var id = $(this).attr("data-id"); var tr = $(this).parent("td").parent("tr"); var u = "/jobs/"+id+".json"; console.log("job_cancel:"+u); $.post(u, { _method: "DELETE" }, function(){ console.log("returned"); if (tr) { // $(tr).fadeOut(500, function(){ $(this).remove();}) $(tr).addClass("deleting"); } }); }); $(document).delegate(".job_retry", "click", function (e) { e.preventDefault(); var id = $(this).attr("data-id"); if ($(this).hasClass("disabled")) { console.log("job " + id + "clicked, but disabled"); } else { console.log("job " + id + " sending retry"); $(this).addClass("disabled"); $.post("/jobs/" + id + "/refresh.json", {}, function () { console.log("refresh sent"); }); } }); $(document).delegate(".job_accept", "click", function (e) { e.preventDefault(); var id = $(this).attr("data-id"); var tp = $(this).attr("data-type"); var tr = $(this).parent("td").parent("tr"); if (id != "nil" && tp != "unknown") { var u = "/jobs/" + id + "/accept.json"; console.log("accept_me:" + u); $.post(u, {}, function () { console.log("returned"); if (tr) { // $(tr).fadeOut(500, function(){ $(this).remove();}) $(tr).addClass("deleting"); } }); } }); $(document).delegate(".job_accept_all", "click", function (e) { e.preventDefault(); var id = $(this).attr("data-id"); var tp = $(this).attr("data-type"); var tr = $(this).parent("td").parent("tr"); if (id != "nil" && tp != "unknown") { var u = "/jobs/all/accept.json"; console.log("accept_me:" + u); $.post(u, {}, function () { console.log("returned"); if (tr) { // $(tr).fadeOut(500, function(){ $(this).remove();}) $(tr).addClass("deleting"); } }); } }); });