ZwiiCampus/core/module/course/view/usersAdd/usersAdd.js.php

92 lines
3.0 KiB
PHP
Raw Normal View History

2023-10-07 18:30:43 +02:00
/**
* This file is part of Zwii.
* For full copyright and license information, please see the LICENSE
* file that was distributed with this source code.
*
* @author Rémi Jean <remi.jean@outlook.com>
* @copyright Copyright (C) 2008-2018, Rémi Jean
* @author Frédéric Tempez <frederic.tempez@outlook.com>
* @copyright Copyright (C) 2018-2023, Frédéric Tempez
* @license CC Attribution-NonCommercial-NoDerivatives 4.0 International
* @link http://zwiicms.fr/
*/
2023-10-12 19:18:29 +02:00
$(document).ready((function () {
2023-11-22 14:09:07 +01:00
2023-11-25 15:10:10 +01:00
$('#courseUserAddSelectAll').on('click', function() {
$('.checkboxSelect').prop('checked', true);
saveCheckboxState();
});
$('#courseUserAddSelectNone').on('click', function() {
$('.checkboxSelect').prop('checked', false);
saveCheckboxState();
});
2023-10-12 19:37:13 +02:00
$("#courseFilterGroup, #courseFilterFirstName, #courseFilterLastName").change(function () {
2023-11-22 10:57:01 +01:00
saveCheckboxState();
2023-11-23 11:25:42 +01:00
$("#courseUsersAddForm").submit();
2023-10-12 19:37:13 +02:00
});
2023-11-23 15:08:19 +01:00
2023-11-22 10:57:01 +01:00
var table = $('#dataTables').DataTable({
2023-10-15 14:53:20 +02:00
language: {
url: "core/vendor/datatables/french.json"
},
"columnDefs": [
{
2023-11-25 15:10:10 +01:00
target: 0,
2023-10-21 13:55:14 +02:00
orderable: false,
2023-11-21 19:42:46 +01:00
searchable: false,
}
]
2023-10-15 14:53:20 +02:00
});
2023-11-22 10:57:01 +01:00
2023-11-22 14:09:07 +01:00
// Handle checkbox change event
$('.checkboxSelect').on('change', function () {
// Save checkbox state to cookies or local storage
saveCheckboxState();
});
2023-11-22 10:57:01 +01:00
// Handle checkbox state on DataTables draw event
table.on('draw', function () {
// Restore checkbox state from cookies or local storage
restoreCheckboxState();
});
2023-11-23 13:59:27 +01:00
// Empty local storage after submit
$("#courseUsersAddSubmit").on("click", function () {
localStorage.setItem('checkboxState', JSON.stringify({}));
});
2023-11-22 10:57:01 +01:00
2023-11-22 14:09:07 +01:00
// Restore checkbox state on page load
restoreCheckboxState();
2023-11-22 10:57:01 +01:00
function saveCheckboxState() {
2023-11-22 14:09:07 +01:00
// Récupérer d'abord les données existantes dans le localStorage
var existingData = JSON.parse(localStorage.getItem('checkboxState')) || {};
// Ajouter ou mettre à jour les données actuelles
2023-11-22 10:57:01 +01:00
$('.checkboxSelect').each(function () {
2023-11-22 14:09:07 +01:00
var checkboxId = $(this).attr('id');
var checked = $(this).prop('checked');
existingData[checkboxId] = checked;
2023-11-22 10:57:01 +01:00
});
2023-11-22 14:09:07 +01:00
// Sauvegarder les données mises à jour dans le localStorage
localStorage.setItem('checkboxState', JSON.stringify(existingData));
2023-11-22 10:57:01 +01:00
}
// Function to restore checkbox state
function restoreCheckboxState() {
2023-11-22 14:09:07 +01:00
var checkboxState = JSON.parse(localStorage.getItem('checkboxState')) || {};
// console.log(checkboxState);
for (var checkboxId in checkboxState) {
if (checkboxState.hasOwnProperty(checkboxId)) {
var checked = checkboxState[checkboxId];
// Update checkbox state based on stored information
$('#' + checkboxId).prop('checked', checked);
}
}
2023-11-22 10:57:01 +01:00
}
2023-10-08 14:46:44 +02:00
}));