mirror of
https://github.com/AdrienHallet/HaitiWater.git
synced 2026-11-03 21:35:47 +00:00
110 lines
4.3 KiB
JavaScript
110 lines
4.3 KiB
JavaScript
function drawWaterElementTable(withManagers, withActions){
|
|
let baseURL = location.protocol+'//'+location.hostname+(location.port ? ':'+location.port: '');
|
|
let dataURL = baseURL + "/api/table/?name=water_element";
|
|
console.log("Request data from: " + dataURL);
|
|
$('#datatable-water_element').DataTable(getWaterDatatableConfiguration(dataURL, withManagers, withActions));
|
|
|
|
let table = $('#datatable-water_element').DataTable();
|
|
$('#datatable-water_element tbody').on( 'click', 'tr', function () {
|
|
if ( $(this).hasClass('selected') ) {
|
|
$(this).removeClass('selected');
|
|
}
|
|
else {
|
|
table.$('tr.selected').removeClass('selected');
|
|
$(this).addClass('selected');
|
|
}
|
|
});
|
|
|
|
$('#datatable-water_element tbody').on( 'click', '.remove-row', function () {
|
|
let data = $(this).parents('tr')[0].getElementsByTagName('td');
|
|
if (confirm("Voulez-vous supprimer: " + data[1].innerText + ' ' + data[2].innerText + ' ?')){
|
|
removeElement("water_element", data[0].innerText);
|
|
} else {}
|
|
} );
|
|
$('#datatable-water_element tbody').on( 'click', '.edit-row', function () {
|
|
let data = $(this).parents('tr')[0].getElementsByTagName('td');
|
|
editElement(data);
|
|
} );
|
|
prettifyHeader();
|
|
}
|
|
|
|
function editManager(data){
|
|
console.log(data[0].textContent);
|
|
}
|
|
|
|
function getWaterDatatableConfiguration(dataURL, withManagers, withActions){
|
|
let config = {
|
|
"sortable": true,
|
|
"processing": true,
|
|
"serverSide": true,
|
|
"responsive": false,
|
|
"autoWidth": false,
|
|
scrollX: true,
|
|
scrollCollapse: true,
|
|
paging: true,
|
|
fixedColumns: {
|
|
leftColumns: 1,
|
|
rightColumns: 1
|
|
},
|
|
"columnDefs": [
|
|
{
|
|
"targets": -1,
|
|
"data": null,
|
|
"defaultContent": getActionButtonsHTML(),
|
|
},
|
|
{
|
|
"targets": -2,
|
|
"defaultContent": 'Pas de gestionnaire',
|
|
"visible": withManagers,
|
|
}
|
|
],
|
|
"language": {
|
|
"sProcessing": "Chargement...",
|
|
"sSearch": "",
|
|
"sLengthMenu": "_MENU_ éléments",
|
|
"sInfo": "", //"Affichage de l'élement _START_ à _END_ sur _TOTAL_ éléments",
|
|
"sInfoEmpty": "Affichage de l'élement 0 à 0 sur 0 éléments",
|
|
"sInfoFiltered": "(filtré de _MAX_ éléments au total)",
|
|
"sInfoPostFix": "",
|
|
"sLoadingRecords": "Chargement en cours...",
|
|
"sZeroRecords": "Aucun élément à afficher",
|
|
"sEmptyTable": "Aucune donnée disponible dans le tableau",
|
|
"oPaginate": {
|
|
"sFirst": "Premier",
|
|
"sPrevious": "Précédent",
|
|
"sNext": "Suivant",
|
|
"sLast": "Dernier"
|
|
},
|
|
"oAria": {
|
|
"sSortAscending": ": activer pour trier la colonne par ordre croissant",
|
|
"sSortDescending": ": activer pour trier la colonne par ordre décroissant"
|
|
}
|
|
},
|
|
"ajax": {
|
|
url: dataURL
|
|
},
|
|
|
|
//Callbacks on fetched data
|
|
"createdRow": function (row, data, index) {
|
|
$('td', row).eq(5).addClass('text-center');
|
|
$('td', row).eq(6).addClass('text-center');
|
|
//Hide actions if column hidden
|
|
if ($("#datatable-ajax th:last-child, #datatable-ajax td:last-child").hasClass("hidden")){
|
|
$('td', row).eq(8).addClass('hidden');
|
|
}
|
|
if (withManagers) {
|
|
$('td', row).eq(7).addClass('text-center');
|
|
}
|
|
},
|
|
"initComplete": function(settings, json){
|
|
// Removes the last column (both header and body) if we cannot edit or if required by withAction argument
|
|
console.log(json['editable']);
|
|
if(!withActions || !(json.hasOwnProperty('editable') && json['editable'])){
|
|
$("#datatable-ajax th:last-child, #datatable-ajax td:last-child").addClass("hidden");
|
|
$("#datatable-ajax_wrapper tr:last-child th:last-child").addClass("hidden");
|
|
}
|
|
}
|
|
};
|
|
return config;
|
|
}
|