Full calendar event.id undifined

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.

  1.     $(document).ready(function() {
  2.     /* initialize the external events
  3.          -----------------------------------------------------------------*/
  4.     $('#external-events div.external-event').each(function() {
  5.         // create an Event Object (http://arshaw.com/fullcalendar/docs/event_data/Event_Object/)
  6.         // it doesn't need to have a start or end
  7.         var eventObject = {
  8.             title: $.trim($(this).text()) // use the element's text as the event title
  9.         };
  10.         // store the Event Object in the DOM element so we can get to it later
  11.         $(this).data('eventObject', eventObject);
  12.         // make the event draggable using jQuery UI
  13.         $(this).draggable({
  14.             zIndex: 999,
  15.             revert: true,      // will cause the event to go back to its
  16.             revertDuration: 0  //  original position after the drag
  17.         });
  18.     });
  19.     /* initialize the calendar
  20.      -----------------------------------------------------------------*/
  21.     var date = new Date();
  22.     var d = date.getDate();
  23.     var m = date.getMonth();
  24.     var y = date.getFullYear();
  25.     var baseURL = $('body').data('baseurl');
  26.     var name_surname = $("[name='name_surname']").val();
  27.    
  28.     var calendar = $('#calendar').fullCalendar({
  29.         defaultDate: '2015-04-01',
  30.         header: {
  31.             left: 'prev,next today',
  32.             center: 'title',
  33.             right: 'month,basicWeek,basicDay',
  34.         },
  35.         buttonText: {
  36.         today: 'I dag',
  37.         month: 'Måned',
  38.         week: 'Uke',
  39.         day: 'Dag',
  40.         },
  41.         monthNames: ['januar', 'februar', 'mars', 'april', 'mai', 'juni', 'juli', 'august', 'september', 'oktober', 'november', 'desember'],
  42.         monthNamesShort: ['jan', 'feb', 'mar', 'abr', 'mai', 'jun', 'jul', 'aug', 'sep', 'okt', 'nov', 'des'],
  43.         dayNames: ['søndag', 'mandag', 'tirsdag', 'onsdag', 'torsdag', 'fredag', 'lørdag'],
  44.         dayNamesShort: ['søn', 'man', 'tirs', 'ons', 'tors', 'fre', 'lør'],
  45.         weekNumberTitle: 'Uke',
  46.         weekNumbers: true,
  47.         firstDay: 1,
  48.         editable: true,
  49.         droppable: true, // this allows things to be dropped onto the calendar !!!
  50.         drop: function(date, allDay) { // this function is called when something is dropped
  51.        
  52.             // retrieve the dropped element's stored Event Object
  53.             var originalEventObject = $(this).data('eventObject');
  54.             // we need to copy it, so that multiple events don't have a reference to the same object
  55.             var copiedEventObject = $.extend({}, originalEventObject);
  56.             // assign it the date that was reported
  57.             copiedEventObject.start = date;
  58.             copiedEventObject.allDay = allDay;
  59.             // render the event on the calendar
  60.             // the last `true` argument determines if the event "sticks" (http://arshaw.com/fullcalendar/docs/event_rendering/renderEvent/)
  61.             $('#calendar').fullCalendar('renderEvent', copiedEventObject, true);
  62.             // is the "remove after drop" checkbox checked?
  63.             if ($('#drop-remove').is(':checked')) {
  64.                 // if so, remove the element from the "Draggable Events" list
  65.                 $(this).remove();
  66.             }
  67.         },
  68.        
  69.         events: baseURL + 'vacation/show/' + name_surname,
  70.         selectable: true,
  71.         selectHelper: true,
  72.         select: function(start, end) {
  73.          var title = prompt('Tittel:');
  74.          if (title) {
  75.          start = $.fullCalendar.formatDate(start, "yyyy-MM-dd");
  76.          end = $.fullCalendar.formatDate(end, "yyyy-MM-dd");
  77.          $.ajax({
  78.          url: baseURL + 'vacation/save',
  79.          data: 'name_surname='+ name_surname+ '&title='+ title+'&start='+ start +'&end='+ end,
  80.          type: "POST",
  81.          success: function(data)
  82.          {
  83.              updateBalance();
  84.          }
  85.          });
  86.          calendar.fullCalendar('renderEvent',
  87.          {
  88.          title: title,
  89.          start: start,
  90.          end: end
  91.          },
  92.          true // make the event "stick"
  93.          );
  94.          }
  95.          calendar.fullCalendar('unselect');
  96.         },
  97.        
  98.         editable: true,
  99.         eventDrop: function(event) {
  100.          start = $.fullCalendar.formatDate(event.start, "yyyy-MM-dd");
  101.          end = $.fullCalendar.formatDate(event.end, "yyyy-MM-dd");
  102.          $.ajax({
  103.          url: baseURL + 'vacation/update',
  104.          data: 'title='+ event.title+'&start='+ start +'&end='+ end +'&id='+ event.id,
  105.          type: "POST"
  106.          });
  107.         },
  108.        
  109.         eventResize: function(event) {
  110.          start = $.fullCalendar.formatDate(event.start, "yyyy-MM-dd");
  111.          end = $.fullCalendar.formatDate(event.end, "yyyy-MM-dd");
  112.          if (end == 0000-00-00) {
  113.          end = start;
  114.          }
  115.          $.ajax({
  116.          url: baseURL + 'vacation/update',
  117.          data: 'title='+ event.title+'&start='+ start +'&end='+ end +'&id='+ event.id,
  118.          type: "POST",
  119.          success: function(data)
  120.          {
  121.              updateBalance();
  122.          }
  123.          });
  124.         },
  125.         eventClick: function(event) {
  126.          var decision = confirm("Er du sikker på at du vil slette?");
  127.          if (decision) {
  128.          $.ajax({
  129.          type: "POST",
  130.          url: baseURL + 'vacation/delete',
  131.          data: "&id=" + event.id,
  132.          success: function(data)
  133.          {
  134.              updateBalance();
  135.          }
  136.          });
  137.          calendar.fullCalendar("removeEvents", event.id);
  138.          } else {
  139.          }
  140.         }
  141.      });
  142.              
  143.      function updateBalance()
  144.      {
  145.          $.getJSON( baseURL + 'vacation/balance/' + name_surname, function( data ) {
  146.              $( ".balance" ).html( 'Feriedager igjen: ' + data );
  147.          });
  148.      }
  149.      
  150.      updateBalance();
  151.      
  152.     });