1
0
Fork 0
mirror of https://github.com/mperham/sidekiq.git synced 2022-11-09 13:52:34 -05:00
mperham--sidekiq/web/assets/javascripts/application.js

50 lines
1.5 KiB
JavaScript
Raw Normal View History

//= require vendor/jquery
//= require vendor/jquery.timeago
//= require bootstrap
//= require_tree .
$(function() {
$.timeago.settings.allowFuture = true
$("time").timeago();
});
$(function() {
$('.check_all').live('click', function() {
var checked = $(this).attr('checked');
if (checked == 'checked') {
$('input[type=checkbox]', $(this).closest('table')).attr('checked', checked);
} else {
$('input[type=checkbox]', $(this).closest('table')).removeAttr('checked');
}
});
});
$(function() {
$('a[name=poll]').data('polling', false);
$('a[name=poll]').on('click', function(e) {
e.preventDefault();
var pollLink = $(this);
if (pollLink.data('polling')) {
clearInterval(pollLink.data('interval'));
pollLink.text('Live Poll');
$('.poll-status').text('');
}
else {
var href = pollLink.attr('href');
pollLink.data('interval', setInterval(function() {
$.get(href, function(data) {
var responseHtml = $(data);
$('.hero-unit').replaceWith(responseHtml.find('.hero-unit'));
$('.workers').replaceWith(responseHtml.find('.workers'));
});
var currentTime = new Date();
$('.poll-status').text('Last polled at: ' + currentTime.getHours() + ':' + currentTime.getMinutes() + ':' + currentTime.getSeconds());
}, 2000));
$('.poll-status').text('Starting to poll...');
pollLink.text('Stop Polling');
}
pollLink.data('polling', !pollLink.data('polling'));
})
});