mirror of
https://github.com/wavelog/wavelog.git
synced 2026-03-22 10:24:14 +00:00
js magic in cron edit
This commit is contained in:
@@ -34,6 +34,7 @@
|
||||
<?php
|
||||
// List of available Presets
|
||||
$presets = array(
|
||||
'' => 'Custom',
|
||||
'*/5 * * * *' => 'Every 5 Minutes',
|
||||
'*/15 * * * *' => 'Every 15 Minutes',
|
||||
'0 * * * *' => 'Every Hour',
|
||||
@@ -41,12 +42,11 @@
|
||||
'0 0 * * *' => 'Every Day at Midnight',
|
||||
'0 3 * * 1' => 'Every Monday at 03:00',
|
||||
'0 0 1 * *' => 'First Day of Every Month at midnight',
|
||||
'0 2 1 */2 *' => 'Every 2 Months at 02:00',
|
||||
'' => 'Custom'
|
||||
'0 2 1 */2 *' => 'Every 2 Months at 02:00'
|
||||
);
|
||||
?>
|
||||
|
||||
<select class="form-select mb-4" id="edit_cron_expression_dropdowm" name="edit_cron_expression_dropdowm">
|
||||
<select class="form-select mb-4" id="edit_cron_expression_dropdown" name="edit_cron_expression_dropdown">
|
||||
<?php foreach ($presets as $cron_preset => $label) : ?>
|
||||
<option value="<?php echo $cron_preset; ?>" <?php if ($cron->expression == $cron_preset) { echo " selected=\"selected\""; } ?>><?php echo $label; ?></option>
|
||||
<?php endforeach; ?>
|
||||
@@ -54,7 +54,8 @@
|
||||
|
||||
<p class="text-center"> - OR -</p>
|
||||
<p>Enter your own Cron Expression</p>
|
||||
<input type="text" class="form-control" style="font-family: Courier New;" name="edit_cron_expression_custom" id="edit_cron_expression_custom" value="<?php echo htmlspecialchars($cron->expression); ?>">
|
||||
<input type="text" class="form-control mb-1" style="font-family: Courier New;" name="edit_cron_expression_custom" id="edit_cron_expression_custom" value="<?php echo htmlspecialchars($cron->expression); ?>">
|
||||
<em id="exp_humanreadable" style="display: none;">TEST</em>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
|
||||
@@ -4,6 +4,7 @@ $(document).ready(function () {
|
||||
$(document).on('click', '.editCron', async function (e) { // Dynamic binding, since element doesn't exists when loading this JS
|
||||
editCronDialog(e);
|
||||
});
|
||||
|
||||
$(document).on('click', '.enableCronSwitch', async function (e) { // Dynamic binding, since element doesn't exists when loading this JS
|
||||
toggleEnableCronSwitch(e.currentTarget.id, this);
|
||||
});
|
||||
@@ -55,7 +56,21 @@ function init_datatable() {
|
||||
init_expression_tooltips();
|
||||
}
|
||||
|
||||
function modalEventListener() {
|
||||
$('#edit_cron_expression_custom').on('input change',function(e){
|
||||
console.log('changed custom');
|
||||
humanReadableInEditDialog()
|
||||
});
|
||||
|
||||
$('#edit_cron_expression_dropdown').change(function() {
|
||||
console.log('changed dropdown');
|
||||
humanReadableInEditDialog()
|
||||
});
|
||||
}
|
||||
|
||||
function editCronDialog(e) {
|
||||
$('#editCronModal').remove();
|
||||
|
||||
$.ajax({
|
||||
url: base_url + 'index.php/cron/editDialog',
|
||||
type: 'post',
|
||||
@@ -67,6 +82,7 @@ function editCronDialog(e) {
|
||||
|
||||
var editCronModal = new bootstrap.Modal(document.getElementById('editCronModal'));
|
||||
editCronModal.show();
|
||||
modalEventListener();
|
||||
},
|
||||
error: function (data) {
|
||||
|
||||
@@ -75,6 +91,34 @@ function editCronDialog(e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
function humanReadableInEditDialog() {
|
||||
var exp_inputID = $('#edit_cron_expression_custom');
|
||||
var exp_dropdownID = $('#edit_cron_expression_dropdown');
|
||||
var exp_humanreadableID = $('#exp_humanreadable');
|
||||
var humanReadable = '';
|
||||
|
||||
exp_inputID.on('input', function() {
|
||||
exp_dropdownID.val('');
|
||||
});
|
||||
|
||||
if (exp_dropdownID.val() == '') {
|
||||
exp_humanreadableID.show();
|
||||
|
||||
try {
|
||||
humanReadable = cronstrue.toString(exp_inputID.val());
|
||||
} catch (error) {
|
||||
humanReadable = 'waiting for complete expression...';
|
||||
}
|
||||
|
||||
exp_humanreadableID.text(humanReadable);
|
||||
} else {
|
||||
exp_humanreadableID.hide();
|
||||
|
||||
exp_inputID.val(exp_dropdownID.val());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function toggleEnableCronSwitch(id, thisvar) {
|
||||
$.ajax({
|
||||
url: base_url + 'index.php/cron/toogleEnableCronSwitch',
|
||||
|
||||
Reference in New Issue
Block a user