app/assets/javascripts/qujo/qujo.js in qujo-0.1.0 vs app/assets/javascripts/qujo/qujo.js in qujo-0.1.1
- old
+ new
@@ -1,53 +1,79 @@
var interval = null;
-function updateStatus() {
- console.log("update status");
+$(function () {
+ var queuestatus = $("#qujo_status").first();
+ var jobstatus = $("#jobs_status").first();
+ var resqstatus = $("#resque_status").first();
+ function qRun(){
+ queuestatus.addClass('label-inverse');
+ }
+ function qStop(){
+ queuestatus.removeClass('label-inverse');
+ }
+ function qFine(){
+ queuestatus.removeClass("label-important");
+ }
+ function qError(){
+ queuestatus.addClass("label-important");
+ }
+ function jFine(){
+ jobstatus.removeClass("badge-important");
+ }
+ function jError(){
+ jobstatus.addClass("badge-important");
+ }
+ function jText(v){
+ jobstatus.text(v);
+ }
+ function rFine(){
+ resqstatus.removeClass("badge-important");
+ }
+ function rError(){
+ resqstatus.addClass("badge-important");
+ }
+ function rText(v){
+ resqstatus.text(v);
+ }
- var q = $("#qujo_status").first();
- q.addClass('label-inverse');
- console.log("status: get");
+ function updateStatus() {
+ console.log("update status");
+ qRun();
- $.get("/jobs/status", function (d) {
- console.log("status: return");
- q.removeClass('label-inverse');
- q.removeClass("label-important");
+ console.log("status: get");
+ $.get("/jobs/status",function (d) {
+ console.log("status: return");
+ qStop();
+ qFine();
- 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")
- }
+ jFine();
+ jText(d["jobs"]["count"]);
- 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();
+ if (d["jobs"]["error"]) {
+ qError();
+ jError();
+ }
- var j = $("#jobs_status").first();
- j.addClass("badge-important");
- j.text('?');
+ rFine();
+ rText(d["resque"]["count"]);
+ if (d["resque"]["error"]) {
+ qError();
+ rError();
+ }
+ }).fail(function (d) {
+ console.log("status: fail: "+d);
+ qStop();
+ qError();
+ jError();
+ rError();
+ jText('!');
+ rText('!');
+ console.log("disable interval");
+ clearInterval(interval);
+ });
+ }
- 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()) {
+ if (jobstatus.size()) {
interval = setInterval(updateStatus, 2000);
}
$(".create_job").on("click", function () {
var c = $(this).attr("klass");
@@ -59,12 +85,12 @@
$(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(){
+ 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");
}