[Bands] Added edit band

这个提交包含在:
Andreas 2022-09-06 20:18:17 +02:00
父节点 7326c7ec35
当前提交 1114973f8d
共有 5 个文件被更改,包括 98 次插入26 次删除

查看文件

@ -46,37 +46,30 @@ class Band extends CI_Controller {
}
}
public function edit($id)
public function edit()
{
$this->load->library('form_validation');
$this->load->model('bands');
$item_id_clean = $this->security->xss_clean($id);
$item_id_clean = $this->security->xss_clean($this->input->post('id'));
$mode_query = $this->bands->mode($item_id_clean);
$band_query = $this->bands->getband($item_id_clean);
$data['my_mode'] = $mode_query->row();
$data['my_band'] = $band_query->row();
$data['page_title'] = "Edit Mode";
$data['page_title'] = "Edit Band";
$this->form_validation->set_rules('mode', 'Mode', 'required');
$this->form_validation->set_rules('qrgmode', 'QRG-Mode', 'required');
if ($this->form_validation->run() == FALSE)
{
$this->load->view('interface_assets/header', $data);
$this->load->view('mode/edit');
$this->load->view('interface_assets/footer');
}
else
{
$this->bands->edit();
$this->load->view('bands/edit', $data);
}
$data['notice'] = "Mode ".$this->security->xss_clean($this->input->post('mode', true))." Updated";
public function saveupdatedband() {
$this->load->model('bands');
redirect('mode');
}
$id = $this->security->xss_clean($this->input->post('id', true));
$band = $this->security->xss_clean($this->input->post('band', true));
$this->bands->saveupdatedband($id, $band);
echo json_encode(array('message' => 'OK'));
return;
}
public function delete() {

查看文件

@ -257,6 +257,23 @@ class Bands extends CI_Model {
$this->db->query("insert into bandxuser (bandid, userid, active, cq, dok, dxcc, iota, sig, sota, uscounties, was, vucc)
select bands.id, " . $this->session->userdata('user_id') . ", 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 from bands where band ='".$data['band']."' and not exists (select 1 from bandxuser where userid = " . $this->session->userdata('user_id') . " and bandid = bands.id);");
}
function getband($id) {
$this->db->where('id', $id);
return $this->db->get('bands');
}
function saveupdatedband($id, $band) {
$data = array(
'band' => $band,
);
$this->db->where('bands.id', $id);
$this->db->update('bands', $data);
return true;
}
}
?>

查看文件

@ -0,0 +1,14 @@
<div class="container" id="edit_band_dialog">
<form>
<input type="hidden" name="id" value="<?php echo $my_band->id; ?>">
<div class="form-group">
<label for="modeInput">Band</label>
<input type="text" class="form-control" name="band" id="bandInput" aria-describedby="bandInputHelp" value="<?php if(set_value('band') != "") { echo set_value('band'); } else { echo $my_band->band; } ?>" required>
<small id="bandInputHelp" class="form-text text-muted">Name of band</small>
</div>
<button type="button" onclick="saveUpdatedBand(this.form);" class="btn btn-primary"><i class="fas fa-plus-square"></i> Update band</button>
</form>
</div>

查看文件

@ -58,7 +58,7 @@
<td class='was_<?php echo $band->id ?>'><input type="checkbox" <?php if ($band->was == 1) {echo 'checked';}?>></td>
<td class='vucc_<?php echo $band->id ?>'><input type="checkbox" <?php if ($band->vucc == 1) {echo 'checked';}?>></td>
<td>
<a href="javascript:editBand('<?php echo $band->id ?>');" class="btn btn-outline-primary btn-sm"><i class="fas fa-edit"></i> Edit</a>
<a href="javascript:editBandDialog('<?php echo $band->bandid ?>');" class="btn btn-outline-primary btn-sm"><i class="fas fa-edit"></i> Edit</a>
</td>
<td>
<a href="javascript:deleteBand('<?php echo $band->id . '\',\'' . $band->band ?>');" class="btn btn-danger btn-sm" ><i class="fas fa-trash-alt"></i> Delete</a>

查看文件

@ -15,7 +15,7 @@ function createBandDialog() {
success: function (html) {
BootstrapDialog.show({
title: 'Create band',
size: BootstrapDialog.SIZE_WIDE,
size: BootstrapDialog.SIZE_NORMAL,
cssClass: 'create-band-dialog',
nl2br: false,
message: html,
@ -31,7 +31,11 @@ function createBandDialog() {
}
function createBand(form) {
if (form.band.value != '') {
$(".alert").remove();
if (form.band.value == "") {
$('#create_mode').prepend('<div class="alert alert-danger" role="alert"><a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>Please enter a band!</div>');
}
else {
$.ajax({
url: base_url + 'index.php/band/create',
type: 'post',
@ -45,6 +49,50 @@ function createBand(form) {
}
}
function editBandDialog(id) {
$.ajax({
url: base_url + 'index.php/band/edit',
type: 'post',
data: {
'id': id
},
success: function (html) {
BootstrapDialog.show({
title: 'Edit band',
size: BootstrapDialog.SIZE_NORMAL,
cssClass: 'edit-band-dialog',
nl2br: false,
message: html,
buttons: [{
label: 'Close',
action: function (dialogItself) {
dialogItself.close();
}
}]
});
}
});
}
function saveUpdatedBand(form) {
$(".alert").remove();
if (form.band.value == "") {
$('#edit_band_dialog').prepend('<div class="alert alert-danger" role="alert"><a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>Please enter a band!</div>');
}
else {
$.ajax({
url: base_url + 'index.php/band/saveupdatedband',
type: 'post',
data: {'id': form.id.value,
'band': form.band.value
},
success: function (html) {
location.reload();
}
});
}
}
function deleteBand(id, band) {
BootstrapDialog.confirm({
title: 'DANGER',
@ -62,7 +110,7 @@ function deleteBand(id, band) {
'id': id
},
success: function (data) {
$(".band_" + id).parent("tr:first").remove(); // removes mode from table
$(".band_" + id).parent("tr:first").remove(); // removes band from table
}
});
}