From 6f266567a19b097b8c8543869b46f8254058080c Mon Sep 17 00:00:00 2001
From: Andreas <6977712+AndreasK79@users.noreply.github.com>
Date: Sat, 23 Oct 2021 19:55:57 +0200
Subject: [PATCH] [Modes] Added buttons for activate / activate all
---
application/controllers/Mode.php | 16 ++++++
application/models/Modes.php | 20 ++++++++
application/views/mode/index.php | 6 ++-
assets/js/sections/mode.js | 87 ++++++++++++++++++++++++--------
4 files changed, 108 insertions(+), 21 deletions(-)
diff --git a/application/controllers/Mode.php b/application/controllers/Mode.php
index 258e1a22..e3eab2e6 100644
--- a/application/controllers/Mode.php
+++ b/application/controllers/Mode.php
@@ -103,4 +103,20 @@ class Mode extends CI_Controller {
echo json_encode(array('message' => 'OK'));
return;
}
+
+ public function activateall() {
+ $this->load->model('modes');
+ $this->modes->activateall();
+ header('Content-Type: application/json');
+ echo json_encode(array('message' => 'OK'));
+ return;
+ }
+
+ public function deactivateall() {
+ $this->load->model('modes');
+ $this->modes->deactivateall();
+ header('Content-Type: application/json');
+ echo json_encode(array('message' => 'OK'));
+ return;
+ }
}
\ No newline at end of file
diff --git a/application/models/Modes.php b/application/models/Modes.php
index 07d9ec28..531c43ad 100644
--- a/application/models/Modes.php
+++ b/application/models/Modes.php
@@ -102,6 +102,26 @@ class Modes extends CI_Model {
return true;
}
+ function activateall() {
+ $data = array(
+ 'active' => '1',
+ );
+
+ $this->db->update('adif_modes', $data);
+
+ return true;
+ }
+
+ function deactivateall() {
+ $data = array(
+ 'active' => '0',
+ );
+
+ $this->db->update('adif_modes', $data);
+
+ return true;
+ }
+
}
?>
\ No newline at end of file
diff --git a/application/views/mode/index.php b/application/views/mode/index.php
index 0cc7f30f..06c4936a 100644
--- a/application/views/mode/index.php
+++ b/application/views/mode/index.php
@@ -61,6 +61,10 @@
-
+
+
+
+
+
diff --git a/assets/js/sections/mode.js b/assets/js/sections/mode.js
index 7717736d..c84f5120 100644
--- a/assets/js/sections/mode.js
+++ b/assets/js/sections/mode.js
@@ -2,9 +2,9 @@ $('.modetable').DataTable({
"pageLength": 25,
responsive: false,
ordering: false,
- "scrollY": "500px",
+ "scrollY": "500px",
"scrollCollapse": true,
- "paging": false,
+ "paging": false,
"scrollX": true
});
@@ -12,7 +12,7 @@ function createModeDialog() {
$.ajax({
url: base_url + 'index.php/mode/create',
type: 'post',
- success: function(html) {
+ success: function (html) {
BootstrapDialog.show({
title: 'Create mode',
size: BootstrapDialog.SIZE_WIDE,
@@ -35,11 +35,13 @@ function createMode(form) {
$.ajax({
url: base_url + 'index.php/mode/create',
type: 'post',
- data: {'mode': form.mode.value,
+ data: {
+ 'mode': form.mode.value,
'submode': form.submode.value,
'qrgmode': form.qrgmode.value,
- 'active': form.active.value},
- success: function(html) {
+ 'active': form.active.value
+ },
+ success: function (html) {
location.reload();
}
});
@@ -50,11 +52,11 @@ function deactivateMode(modeid) {
$.ajax({
url: base_url + 'index.php/mode/deactivate',
type: 'post',
- data: {'id': modeid },
- success: function(html) {
+ data: { 'id': modeid },
+ success: function (html) {
$(".mode_" + modeid).text('not active');
- $('.btn_'+modeid).html('Activate');
- $('.btn_'+modeid).attr('onclick', 'activateMode('+modeid+')')
+ $('.btn_' + modeid).html('Activate');
+ $('.btn_' + modeid).attr('onclick', 'activateMode(' + modeid + ')')
}
});
}
@@ -63,11 +65,11 @@ function activateMode(modeid) {
$.ajax({
url: base_url + 'index.php/mode/activate',
type: 'post',
- data: {'id': modeid },
- success: function(html) {
- $('.mode_'+modeid).text('active');
- $('.btn_'+modeid).html('Deactivate');
- $('.btn_'+modeid).attr('onclick', 'deactivateMode('+modeid+')')
+ data: { 'id': modeid },
+ success: function (html) {
+ $('.mode_' + modeid).text('active');
+ $('.btn_' + modeid).html('Deactivate');
+ $('.btn_' + modeid).attr('onclick', 'deactivateMode(' + modeid + ')')
}
});
}
@@ -75,19 +77,20 @@ function activateMode(modeid) {
function deleteMode(id, mode) {
BootstrapDialog.confirm({
title: 'DANGER',
- message: 'Warning! Are you sure you want to delete the following mode: ' + mode + '?' ,
+ message: 'Warning! Are you sure you want to delete the following mode: ' + mode + '?',
type: BootstrapDialog.TYPE_DANGER,
closable: true,
draggable: true,
btnOKClass: 'btn-danger',
- callback: function(result) {
- if(result) {
+ callback: function (result) {
+ if (result) {
$.ajax({
url: base_url + 'index.php/mode/delete',
type: 'post',
- data: {'id': id
+ data: {
+ 'id': id
},
- success: function(data) {
+ success: function (data) {
$(".mode_" + id).parent("tr:first").remove(); // removes mode from table
}
});
@@ -95,3 +98,47 @@ function deleteMode(id, mode) {
}
});
}
+
+function activateAllModes() {
+ BootstrapDialog.confirm({
+ title: 'DANGER',
+ message: 'Warning! Are you sure you want to activate all modes?',
+ type: BootstrapDialog.TYPE_DANGER,
+ closable: true,
+ draggable: true,
+ btnOKClass: 'btn-danger',
+ callback: function (result) {
+ if (result) {
+ $.ajax({
+ url: base_url + 'index.php/mode/activateall',
+ type: 'post',
+ success: function (data) {
+ location.reload();
+ }
+ });
+ }
+ }
+ });
+}
+
+function deactivateAllModes() {
+ BootstrapDialog.confirm({
+ title: 'DANGER',
+ message: 'Warning! Are you sure you want to deactivate all modes?',
+ type: BootstrapDialog.TYPE_DANGER,
+ closable: true,
+ draggable: true,
+ btnOKClass: 'btn-danger',
+ callback: function (result) {
+ if (result) {
+ $.ajax({
+ url: base_url + 'index.php/mode/deactivateall',
+ type: 'post',
+ success: function (data) {
+ location.reload();
+ }
+ });
+ }
+ }
+ });
+}
\ No newline at end of file