diff --git a/application/controllers/Cron.php b/application/controllers/Cron.php index 827bcdcd1..933e16328 100644 --- a/application/controllers/Cron.php +++ b/application/controllers/Cron.php @@ -59,6 +59,7 @@ class cron extends CI_Controller { 'timeZone' => null ); $this->load->library('CronExpression', $data); + $cronjob = $this->cronexpression; $dt = new DateTime(); $isdue = $cronjob->isMatching($dt); @@ -142,8 +143,27 @@ class cron extends CI_Controller { $expression = xss_clean($this->input->post('cron_expression',true)); $enabled = xss_clean($this->input->post('cron_enabled',true)); - $this->cron_model->edit_cron($id, $description, $expression, $enabled); + $data = array( + 'expression' => $expression, + 'timeZone' => null + ); + $this->load->library('CronExpression', $data); + $cron = $this->cronexpression; + if ($cron->isValid()) { + $this->cron_model->edit_cron($id, $description, $expression, $enabled); + $this->cronexpression = null; + + header("Content-type: application/json"); + echo json_encode(['success' => true, 'messagecategory' => 'success', 'message' => 'Changes saved for Cronjob "'.$id.'"']); + + } else { + $this->session->set_flashdata('error', 'The Cron Expression you entered is not valid'); + $this->cronexpression = null; + + header("Content-type: application/json"); + echo json_encode(['success' => false, 'messagecategory' => 'error', 'message' => 'The expression "'.$expression.'" is not valid. Please try again.']); + } } public function toogleEnableCronSwitch() { diff --git a/application/views/cron/index.php b/application/views/cron/index.php index 464fdfdab..f8910185a 100644 --- a/application/views/cron/index.php +++ b/application/views/cron/index.php @@ -1,6 +1,9 @@

+ + +
How it works @@ -70,16 +73,6 @@ - - - - - - - - - -
diff --git a/assets/js/sections/cron.js b/assets/js/sections/cron.js index 604ee8020..95152e0b9 100644 --- a/assets/js/sections/cron.js +++ b/assets/js/sections/cron.js @@ -66,6 +66,29 @@ function modalEventListener() { }); } +function displayMessages(category, message) { + var html_class; + var message_area = $('#cron_message_area'); + + if (category == 'success') { + html_class = 'alert alert-success'; + } else if (category == 'warning') { + html_class = 'alert alert-warning'; + } else if (category == 'error') { + html_class = 'alert alert-danger'; + } else { + html_class = 'alert alert-info'; + } + + message_area.show(); + message_area.addClass(html_class); + message_area.text(message); + + setTimeout(function() { + message_area.fadeOut(); + }, 7000); +} + function editCronDialog(e) { $('#editCronModal').remove(); @@ -105,12 +128,19 @@ function editCron() { cron_expression: $cron_expression, cron_enabled: $cron_enabled }, - success: function (data) { - reloadCrons(); - }, - error: function (data) { + success: function(response) { + if (response.success) { + reloadCrons(); + displayMessages(response.messagecategory,response.message); + } else { + displayMessages(response.messagecategory,response.message); + } }, + error: function(response) { + displayMessages('error','The query failed for a unknown reason'); + } }); + } function humanReadableInEditDialog() {