edit dialog save

This commit is contained in:
HB9HIL
2024-04-26 14:05:39 +02:00
parent 9538d968ce
commit be33c3c059
4 changed files with 34 additions and 15 deletions

View File

@@ -137,12 +137,12 @@ class cron extends CI_Controller {
redirect('dashboard');
}
$id = xss_clean($this->input->post('id',true));
$description = xss_clean($this->input->post('description',true));
$expression = xss_clean($this->input->post('expression',true));
$enabled = xss_clean($this->input->post('enabled',true));
$id = xss_clean($this->input->post('cron_id',true));
$description = xss_clean($this->input->post('cron_description',true));
$expression = xss_clean($this->input->post('cron_expression',true));
$enabled = xss_clean($this->input->post('cron_enabled',true));
$this->cron_model->update_cron($id, $description, $expression, $enabled);
$this->cron_model->edit_cron($id, $description, $expression, $enabled);
}

View File

@@ -68,4 +68,18 @@ class Cron_model extends CI_Model
$this->set_modified($cron);
}
function edit_cron($id, $description, $expression, $enabled) {
$data = array (
'description' => $description,
'expression' => $expression,
'enabled' => ($enabled === 'true' ? 1 : 0)
);
$this->db->where('id', $id);
$this->db->update('cron', $data);
$this->set_modified($id);
}
}

View File

@@ -22,7 +22,7 @@
<th scope="row">Enabled</th>
<td>
<div class="form-check form-switch">
<input name="edit_acron_enable_switch" class="form-check-input" type="checkbox" role="switch" id="edit_a<?php echo $cron->id; ?>" <?php if ($cron->enabled ?? '0') {
<input name="edit_cron_enable_switch" class="form-check-input" type="checkbox" role="switch" id="edit_<?php echo $cron->id; ?>" <?php if ($cron->enabled ?? '0') {
echo 'checked';
} ?>>
</div>
@@ -31,7 +31,7 @@
<tr>
<th scope="row">Description</th>
<td>
<textarea class="form-control" name="edit_acron_description" id="edit_acron_description" maxlength="240" rows="2" style="width:100%;"><?php echo $cron->description; ?></textarea>
<textarea class="form-control" name="edit_cron_description" id="edit_cron_description" maxlength="240" rows="2" style="width:100%;"><?php echo $cron->description; ?></textarea>
</td>
</tr>
<tr>
@@ -72,7 +72,7 @@
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" data-bs-dismiss="modal"><?php echo lang('admin_save'); ?></button>
<button type="button" class="btn btn-primary" data-bs-dismiss="modal" onclick="editCron()" ><?php echo lang('admin_save'); ?></button>
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal"><?php echo lang('general_word_cancel'); ?></button>
</div>
</div>

View File

@@ -58,12 +58,10 @@ function init_datatable() {
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()
});
}
@@ -93,10 +91,11 @@ function editCronDialog(e) {
}
function editCron() {
var $cron_id = '';
var $cron_description = '';
var $cron_expression = '';
var $cron_enabled = '';
var $cron_id = $('#edit_cron_id').val();
var $cron_description = $('#edit_cron_description').val();
var $cron_expression = $('#edit_cron_expression_custom').val();
var $cron_enabled = $('#edit_' + $cron_id).is(':checked') ? '1' : '0';
$.ajax({
url: base_url + 'index.php/cron/edit',
method: 'POST',
@@ -105,7 +104,13 @@ function editCron() {
cron_description: $cron_description,
cron_expression: $cron_expression,
cron_enabled: $cron_enabled
}
},
success: function (data) {
reloadCrons();
console.log('edit success');
},
error: function (data) {
},
});
}