webcron/assets/job/index.js

65 lines
2.1 KiB
JavaScript
Raw Normal View History

2021-07-20 18:54:07 +02:00
import { Modal } from 'bootstrap';
2021-05-24 14:08:30 +02:00
$(function() {
initDeleteButtons();
2021-06-01 20:21:47 +02:00
initRunNowButtons();
2021-05-24 14:08:30 +02:00
})
function initDeleteButtons() {
$('.delete-btn').on('click', function() {
let me = $(this)
let href = me.data('href');
let confirmation = me.data('confirmation');
if(confirm(confirmation)) {
$.ajax({
url: href,
method: 'DELETE',
success: function(data) {
window.location.href = data.return_path;
}
})
}
})
2021-06-01 20:21:47 +02:00
}
function initRunNowButtons() {
$('.runnow').on('click', function() {
let me = $(this)
let href = me.data('href');
$.ajax({
url: href,
method: 'GET',
success: function(data) {
let modal = $('#runnow_result');
modal.find('.modal-title').html(data.title);
if (data.status == 'deferred') {
modal.find('.modal-body').html(data.message);
me.addClass('disabled');
let td = me.parents('td');
td.find('.btn').each(function() {
let btn = $(this);
btn.addClass('btn-outline-success');
btn.removeClass('btn-outline-primary');
btn.removeClass('btn-outline-danger');
})
let tr = me.parents('tr');
tr.addClass('running');
2021-07-20 18:54:07 +02:00
tr.addClass('text-success');
tr.removeClass('norun');
2021-07-20 18:54:07 +02:00
tr.removeClass('text-danger');
2021-06-01 20:21:47 +02:00
} else if (data.status == 'ran') {
2021-07-02 21:03:21 +02:00
let content = '<p>Cronjob ran in ' + data.runtime.toFixed(3) + ' seconds with exit code ' + data.exitcode +'</p>'
2021-06-01 20:21:47 +02:00
content += '<pre>' + data.output + '</pre>'
modal.find('.modal-body').html(content);
}
2021-07-20 18:54:07 +02:00
var bsModal = new Modal('#runnow_result').show();//modal.modal({show: true})
2021-06-01 20:21:47 +02:00
}
})
})
2021-05-24 14:08:30 +02:00
}