Full calendar event.id undifined
I using Full calendar v1.6.4 plugin, and i have problem when new event is posted ant when you try to edit/remove it does not save in the database, if i refresh page after event post and try again it works fine, in first part i debugged and event.id is undefined, but i dont know why and how it can be fixed.
My all code, main problem is in the eventResize function.
- $(document).ready(function() {
- /* initialize the external events
- -----------------------------------------------------------------*/
- $('#external-events div.external-event').each(function() {
- // create an Event Object (http://arshaw.com/fullcalendar/docs/event_data/Event_Object/)
- // it doesn't need to have a start or end
- var eventObject = {
- title: $.trim($(this).text()) // use the element's text as the event title
- };
- // store the Event Object in the DOM element so we can get to it later
- $(this).data('eventObject', eventObject);
- // 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
- });
- });
- /* initialize the calendar
- -----------------------------------------------------------------*/
- var date = new Date();
- var d = date.getDate();
- var m = date.getMonth();
- var y = date.getFullYear();
- var baseURL = $('body').data('baseurl');
- var name_surname = $("[name='name_surname']").val();
-
- var calendar = $('#calendar').fullCalendar({
- defaultDate: '2015-04-01',
- header: {
- left: 'prev,next today',
- center: 'title',
- right: 'month,basicWeek,basicDay',
- },
- buttonText: {
- today: 'I dag',
- month: 'Måned',
- week: 'Uke',
- day: 'Dag',
- },
- monthNames: ['januar', 'februar', 'mars', 'april', 'mai', 'juni', 'juli', 'august', 'september', 'oktober', 'november', 'desember'],
- monthNamesShort: ['jan', 'feb', 'mar', 'abr', 'mai', 'jun', 'jul', 'aug', 'sep', 'okt', 'nov', 'des'],
- dayNames: ['søndag', 'mandag', 'tirsdag', 'onsdag', 'torsdag', 'fredag', 'lørdag'],
- dayNamesShort: ['søn', 'man', 'tirs', 'ons', 'tors', 'fre', 'lør'],
- weekNumberTitle: 'Uke',
- weekNumbers: true,
- firstDay: 1,
- editable: true,
- droppable: true, // this allows things to be dropped onto the calendar !!!
- drop: function(date, allDay) { // this function is called when something is dropped
-
- // retrieve the dropped element's stored Event Object
- var originalEventObject = $(this).data('eventObject');
- // we need to copy it, so that multiple events don't have a reference to the same object
- var copiedEventObject = $.extend({}, originalEventObject);
- // assign it the date that was reported
- copiedEventObject.start = date;
- copiedEventObject.allDay = allDay;
- // render the event on the calendar
- // the last `true` argument determines if the event "sticks" (http://arshaw.com/fullcalendar/docs/event_rendering/renderEvent/)
- $('#calendar').fullCalendar('renderEvent', copiedEventObject, true);
- // is the "remove after drop" checkbox checked?
- if ($('#drop-remove').is(':checked')) {
- // if so, remove the element from the "Draggable Events" list
- $(this).remove();
- }
- },
-
- events: baseURL + 'vacation/show/' + name_surname,
- selectable: true,
- selectHelper: true,
- select: function(start, end) {
- var title = prompt('Tittel:');
- if (title) {
- start = $.fullCalendar.formatDate(start, "yyyy-MM-dd");
- end = $.fullCalendar.formatDate(end, "yyyy-MM-dd");
- $.ajax({
- url: baseURL + 'vacation/save',
- data: 'name_surname='+ name_surname+ '&title='+ title+'&start='+ start +'&end='+ end,
- type: "POST",
- success: function(data)
- {
- updateBalance();
- }
- });
- calendar.fullCalendar('renderEvent',
- {
- title: title,
- start: start,
- end: end
- },
- true // make the event "stick"
- );
- }
- calendar.fullCalendar('unselect');
- },
-
- editable: true,
- eventDrop: function(event) {
- start = $.fullCalendar.formatDate(event.start, "yyyy-MM-dd");
- end = $.fullCalendar.formatDate(event.end, "yyyy-MM-dd");
- $.ajax({
- url: baseURL + 'vacation/update',
- data: 'title='+ event.title+'&start='+ start +'&end='+ end +'&id='+ event.id,
- type: "POST"
- });
- },
-
- eventResize: function(event) {
- start = $.fullCalendar.formatDate(event.start, "yyyy-MM-dd");
- end = $.fullCalendar.formatDate(event.end, "yyyy-MM-dd");
- if (end == 0000-00-00) {
- end = start;
- }
- $.ajax({
- url: baseURL + 'vacation/update',
- data: 'title='+ event.title+'&start='+ start +'&end='+ end +'&id='+ event.id,
- type: "POST",
- success: function(data)
- {
- updateBalance();
- }
- });
- },
- eventClick: function(event) {
- var decision = confirm("Er du sikker på at du vil slette?");
- if (decision) {
- $.ajax({
- type: "POST",
- url: baseURL + 'vacation/delete',
- data: "&id=" + event.id,
- success: function(data)
- {
- updateBalance();
- }
- });
- calendar.fullCalendar("removeEvents", event.id);
- } else {
- }
- }
- });
-
- function updateBalance()
- {
- $.getJSON( baseURL + 'vacation/balance/' + name_surname, function( data ) {
- $( ".balance" ).html( 'Feriedager igjen: ' + data );
- });
- }
-
- updateBalance();
-
- });