diff --git a/application/views/cron/edit.php b/application/views/cron/edit.php index dca0b21d9..cb7c44e39 100644 --- a/application/views/cron/edit.php +++ b/application/views/cron/edit.php @@ -34,6 +34,7 @@ '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' ); ?> - $label) : ?> @@ -54,7 +54,8 @@

- OR -

Enter your own Cron Expression

- + + diff --git a/assets/js/sections/cron.js b/assets/js/sections/cron.js index 46f0f0fc3..59b5ecc46 100644 --- a/assets/js/sections/cron.js +++ b/assets/js/sections/cron.js @@ -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',