From 93b6cba00ea63898706c69ec7e5e72b733ca36fb Mon Sep 17 00:00:00 2001
From: Andreas <6977712+AndreasK79@users.noreply.github.com>
Date: Sat, 23 Oct 2021 19:44:41 +0200
Subject: [PATCH] [Contests] Added buttons for activate/deactivate all
---
application/controllers/Contesting.php | 16 +++++
application/models/Contesting_model.php | 20 ++++++
application/views/contesting/add.php | 6 +-
assets/js/sections/contestingnames.js | 89 +++++++++++++++++++------
4 files changed, 109 insertions(+), 22 deletions(-)
diff --git a/application/controllers/Contesting.php b/application/controllers/Contesting.php
index 6beb4edf3..bcb9f46e1 100644
--- a/application/controllers/Contesting.php
+++ b/application/controllers/Contesting.php
@@ -134,4 +134,20 @@ class Contesting extends CI_Controller {
echo json_encode(array('message' => 'OK'));
return;
}
+
+ public function deactivateall() {
+ $this->load->model('Contesting_model');
+ $this->Contesting_model->deactivateall();
+ header('Content-Type: application/json');
+ echo json_encode(array('message' => 'OK'));
+ return;
+ }
+
+ public function activateall() {
+ $this->load->model('Contesting_model');
+ $this->Contesting_model->activateall();
+ header('Content-Type: application/json');
+ echo json_encode(array('message' => 'OK'));
+ return;
+ }
}
diff --git a/application/models/Contesting_model.php b/application/models/Contesting_model.php
index a3832258e..b026e7594 100644
--- a/application/models/Contesting_model.php
+++ b/application/models/Contesting_model.php
@@ -122,4 +122,24 @@ class Contesting_model extends CI_Model {
$this->db->where('id', $id);
$this->db->update('contest', $data);
}
+
+ function activateall() {
+ $data = array(
+ 'active' => '1',
+ );
+
+ $this->db->update('contest', $data);
+
+ return true;
+ }
+
+ function deactivateall() {
+ $data = array(
+ 'active' => '0',
+ );
+
+ $this->db->update('contest', $data);
+
+ return true;
+ }
}
diff --git a/application/views/contesting/add.php b/application/views/contesting/add.php
index 661b68307..e62b95960 100644
--- a/application/views/contesting/add.php
+++ b/application/views/contesting/add.php
@@ -59,6 +59,10 @@
-
+
+
+
+
+
diff --git a/assets/js/sections/contestingnames.js b/assets/js/sections/contestingnames.js
index 9e06db281..25f49fe56 100644
--- a/assets/js/sections/contestingnames.js
+++ b/assets/js/sections/contestingnames.js
@@ -2,9 +2,9 @@ $('.contesttable').DataTable({
"pageLength": 25,
responsive: false,
ordering: false,
- "scrollY": "400px",
+ "scrollY": "400px",
"scrollCollapse": true,
- "paging": false,
+ "paging": false,
"scrollX": true,
dom: 'Bfrtip',
buttons: [
@@ -13,7 +13,7 @@ $('.contesttable').DataTable({
});
// using this to change color of csv-button if dark mode is chosen
-var background = $('body').css( "background-color");
+var background = $('body').css("background-color");
if (background != ('rgb(255, 255, 255)')) {
$(".buttons-csv").css("color", "white");
@@ -23,7 +23,7 @@ function createContestDialog() {
$.ajax({
url: base_url + 'index.php/contesting/create',
type: 'post',
- success: function(html) {
+ success: function (html) {
BootstrapDialog.show({
title: 'Add Contest',
size: BootstrapDialog.SIZE_WIDE,
@@ -46,9 +46,11 @@ function createContest(form) {
$.ajax({
url: base_url + 'index.php/contesting/create',
type: 'post',
- data: {'name': form.contestname.value,
- 'adifname': form.adifcontestname.value},
- success: function(html) {
+ data: {
+ 'name': form.contestname.value,
+ 'adifname': form.adifcontestname.value
+ },
+ success: function (html) {
location.reload();
}
});
@@ -59,11 +61,11 @@ function deactivateContest(contestid) {
$.ajax({
url: base_url + 'index.php/contesting/deactivate',
type: 'post',
- data: {'id': contestid },
- success: function(html) {
+ data: { 'id': contestid },
+ success: function (html) {
$(".contest_" + contestid).text('not active');
- $('.btn_'+contestid).html('Activate');
- $('.btn_'+contestid).attr('onclick', 'activateContest('+contestid+')')
+ $('.btn_' + contestid).html('Activate');
+ $('.btn_' + contestid).attr('onclick', 'activateContest(' + contestid + ')')
}
});
}
@@ -72,11 +74,11 @@ function activateContest(contestid) {
$.ajax({
url: base_url + 'index.php/contesting/activate',
type: 'post',
- data: {'id': contestid },
- success: function(html) {
- $('.contest_'+contestid).text('active');
- $('.btn_'+contestid).html('Deactivate');
- $('.btn_'+contestid).attr('onclick', 'deactivateContest('+contestid+')')
+ data: { 'id': contestid },
+ success: function (html) {
+ $('.contest_' + contestid).text('active');
+ $('.btn_' + contestid).html('Deactivate');
+ $('.btn_' + contestid).attr('onclick', 'deactivateContest(' + contestid + ')')
}
});
}
@@ -84,19 +86,20 @@ function activateContest(contestid) {
function deleteContest(id, contest) {
BootstrapDialog.confirm({
title: 'DANGER',
- message: 'Warning! Are you sure you want to delete the following contest: ' + contest + '?' ,
+ message: 'Warning! Are you sure you want to delete the following contest: ' + contest + '?',
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/contesting/delete',
type: 'post',
- data: {'id': id
+ data: {
+ 'id': id
},
- success: function(data) {
+ success: function (data) {
$(".contest_" + id).parent("tr:first").remove(); // removes mode from table
}
});
@@ -104,3 +107,47 @@ function deleteContest(id, contest) {
}
});
}
+
+function activateAllContests() {
+ BootstrapDialog.confirm({
+ title: 'DANGER',
+ message: 'Warning! Are you sure you want to activate all contests?',
+ type: BootstrapDialog.TYPE_DANGER,
+ closable: true,
+ draggable: true,
+ btnOKClass: 'btn-danger',
+ callback: function (result) {
+ if (result) {
+ $.ajax({
+ url: base_url + 'index.php/contesting/activateall',
+ type: 'post',
+ success: function (data) {
+ location.reload();
+ }
+ });
+ }
+ }
+ });
+}
+
+function deactivateAllContests() {
+ BootstrapDialog.confirm({
+ title: 'DANGER',
+ message: 'Warning! Are you sure you want to deactivate all contests?',
+ type: BootstrapDialog.TYPE_DANGER,
+ closable: true,
+ draggable: true,
+ btnOKClass: 'btn-danger',
+ callback: function (result) {
+ if (result) {
+ $.ajax({
+ url: base_url + 'index.php/contesting/deactivateall',
+ type: 'post',
+ success: function (data) {
+ location.reload();
+ }
+ });
+ }
+ }
+ });
+}
\ No newline at end of file