113 lines
3.4 KiB
JavaScript
113 lines
3.4 KiB
JavaScript
formulaire = $('.formulaire')
|
|
date = Date.now()
|
|
|
|
$(document).ready(function () {
|
|
|
|
$('#motifInter').change(function (e) {
|
|
let nbPompier = $(this).find(":selected").attr('data-effectif');
|
|
$('#nbPompierCons').html("Nombre de pompiers conseillé: " + nbPompier);
|
|
});
|
|
|
|
|
|
$('#caserneInter').change(function () {
|
|
caserne = $(this).val();
|
|
//cis
|
|
$.ajax({
|
|
url: "./../controleurs/c_interventions.php?action=listePompier&cis=" + caserne,
|
|
method: "POST", // Méthode HTTP (GET, POST, etc.)
|
|
dataType: "json", // Type de données attendu
|
|
error: function (status, error) {
|
|
// Gérer les erreurs de la requête AJAX
|
|
console.error("Erreur lors de la requête AJAX :", status, error);
|
|
},
|
|
success: function (result) {
|
|
$('#pompierDispo').html(' ');
|
|
result.forEach(element => {
|
|
var ligne = '<div id='
|
|
+ element['pId']
|
|
+ ' class="' + element['pLibelle']
|
|
+ '" data-intervention="' + element['enIntervention']
|
|
+ '" style = "background-color: ' + element['pValeur'] + ';" draggable = "true" ondragstart = "dragstartHandler(event)" >'
|
|
+ element['pPrenom'] + ' ' + element['pNom']
|
|
+ ' (' + element['statut'] + ')'
|
|
+ '</div> ';
|
|
|
|
$('#pompierDispo').append(ligne)
|
|
|
|
});
|
|
}
|
|
});
|
|
});
|
|
|
|
});
|
|
|
|
function dragstartHandler(ev) {
|
|
// Add the target element's id to the data transfer object
|
|
ev.dataTransfer.setData("application/my-app", ev.target.id);
|
|
ev.dataTransfer.effectAllowed = "move";
|
|
}
|
|
function dragoverHandler(ev) {
|
|
ev.preventDefault();
|
|
ev.dataTransfer.dropEffect = "move";
|
|
}
|
|
function dropHandler(ev) {
|
|
ev.preventDefault();
|
|
// Get the id of the target and add the moved element to the target's DOM
|
|
const data = ev.dataTransfer.getData("application/my-app");
|
|
if (ev.target.id === "target" || ev.target.parentNode.id === "target") {
|
|
trgt = document.getElementById('target');
|
|
} else if (ev.target.id === "pompierDispo" || ev.target.parentNode.id === "pompierDispo") {
|
|
trgt = document.getElementById('pompierDispo');
|
|
}
|
|
trgt.appendChild(document.getElementById(data));
|
|
}
|
|
|
|
|
|
/**
|
|
* PREPARATION DE L'ENVOIE DU FORMULAIRE
|
|
*/
|
|
$(document).on('submit', '#formulaireInter', function(e){
|
|
e.preventDefault();
|
|
})
|
|
|
|
$(document).on('click', '#sendInter', function(e){
|
|
e.preventDefault();
|
|
|
|
//var data = $('#formulaireInter').serialize();
|
|
var data = {
|
|
motif: $('#formulaireInter select[name=motif]').val(),
|
|
adresse: $('#formulaireInter input[name=adresse]').val(),
|
|
caserne: $('#formulaireInter select[name=caserne]').val(),
|
|
commentaire: $('#formulaireInter textarea[name=commentaire]').val()
|
|
};
|
|
|
|
let listePompier = [];
|
|
$('.pompierIntervenant div').each(function(index){
|
|
num = $(this).attr('id');
|
|
dispo = $(this).attr('data-intervention');
|
|
|
|
var obj = {};
|
|
obj[num] = dispo
|
|
listePompier.push(obj)
|
|
})
|
|
|
|
var sendingData = {
|
|
"dataForm" : data,
|
|
"listePompier" : listePompier
|
|
};
|
|
|
|
$.ajax({
|
|
url: "./../controleurs/c_interventions.php?action=nouvelleInter",
|
|
method: "POST", // Méthode HTTP (GET, POST, etc.)
|
|
data: sendingData,
|
|
dataType: "json", // Type de données attendu
|
|
error: function (status, error) {
|
|
// Gérer les erreurs de la requête AJAX
|
|
console.error("Erreur lors de la requête AJAX :", status, error);
|
|
},
|
|
success: function (result) {
|
|
//COMPLETE
|
|
}
|
|
});
|
|
|
|
}) |