1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
| $(document).ready(function () {
/* initialize the external events
-----------------------------------------------------------------*/
$('#external-events .fc-event').each(function () {
// store data so the calendar knows to render an event upon drop
$(this).data('event', {
title: $.trim($(this).text()), // use the element's text as the event title
stick: true // maintain when user navigates (see docs on the renderEvent method)
});
// make the event draggable using jQuery UI
$(this).draggable({
zIndex: 999,
revert: true, // will cause the event to go back to its
revertDuration: 0 // original position after the drag
});
});
// les modifications c'est à partir d'ici
const UNDEFINED = "undefined";
// fonctions commmunes
function formatDate(date) {
return $.fullCalendar.formatDate(date, "Y-MM-DD HH:mm:ss");
}
/**
* @param {String} url - fichier serveur appelé
* @param {Object} param - objet contenant les données à transmettre
* @param {String} msg - message affiché dans la console
*/
function sendDatas(url, param, msg) {
console.log("param : %o\n%s", param, JSON.stringify(param, null, 2))
$.ajax({
url: url,
type: "POST",
data: param
})
.done (function () {
calendar.fullCalendar('refetchEvents');
console.log( "Succes :", msg);
})
.fail(function (error, textStatus) {
console.log("Error : %s\n%o", textStatus, error);
})
.always(function () {
console.log( "Always :", msg);
})
}
/**
* initialize the calendar
*/
var calendar = $('#calendar').fullCalendar({
editable: true,
droppable: true,
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
events: 'load.php',
//--
eventReceive: function (start, end, allDay) {
console.log("eventReceive :", arguments);
const data = {
"title": start.title || UNDEFINED,
"start": start.start ? formatDate(start.start) : UNDEFINED,
"end": end.end ? formatDate(end.end) : UNDEFINED
};
sendDatas("insert.php", data, "Added Successfully");
},
//--
eventResize: function (event) {
console.log("eventResize :", event);
const data = {
"title": event.title || UNDEFINED,
"start": event.start ? formatDate(event.start) : UNDEFINED,
"end": event.end ? formatDate(event.end) : UNDEFINED,
"id": event.id || UNDEFINED
};
sendDatas("update.php", data, "Event Update");
},
//--
eventDrop: function (event) {
console.log("eventDrop :", event);
const data = {
"title": event.title || UNDEFINED,
"start": event.start ? formatDate(event.start) : UNDEFINED,
"end": event.end ? formatDate(event.end) : UNDEFINED,
"id": event.id || UNDEFINED
};
sendDatas("update.php", data, "Event Update");
},
//--
eventClick: function (event) {
console.log("eventClick :", event);
if (confirm("Are you sure you want to remove it?")) {
const data = {
"id": event.id || UNDEFINED
};
sendDatas("delete.php", data, "Event Removed");
}
},
});
}); |
Partager