2

How to check event is already exist for a day while using renderEvent method.

I have found may answer in in stack for dayClick with clientEvents, I am not sure how it use for renderEvent.

var diffDay = 5; 
for (var i = 0; i < diffDay; i++) {
    var copiedEventObject = $.extend({}, originalEventObject);
    var newDay = new Date(event.start);
    copiedEventObject.start = newDay;
    $inlineCalendar.fullCalendar('renderEvent', copiedEventObject, true);                       
}

I am looking a if condition like below or any other solution

if(....Condition?....){
    $inlineCalendar.fullCalendar('renderEvent', copiedEventObject, true);                       
}
Adeel
  • 2,901
  • 7
  • 24
  • 34
Jaison James
  • 4,414
  • 4
  • 42
  • 54

3 Answers3

0

My solution is compare the .start of EventObject.

Update: after discussion, seems we had opposite understanding before, I update my code

So the Condition at my solution is:

var allevents = $inlineCalendar.fullCalendar( 'clientEvents');

for(var i=0;i<allevents.length;i++ ){
var currentevent=allevents[i];
if((
(copiedEventObject.allDay && copiedEventObject.start == currentevent.start) 
|| HasSameDate(currentevent.start,copiedEventObject.start)
) == false){
    $inlineCalendar.fullCalendar('renderEvent', copiedEventObject, true);                       
}
}

function HasSameDate(date1,date2)
{
   return $inlineCalendar.fullCalendar.formatDate(date1, 'yyyyMMdd') == $inlineCalendar.fullCalendar.formatDate(date2, 'yyyyMMdd');
}
Weimin Ye
  • 665
  • 4
  • 15
  • Thank you for your quick replay, I'll test you answer soon and make it acceptable if its for me. – Jaison James May 07 '14 at 13:03
  • Currently its not working for me, always invoking to else case, I am checking if any error from my side, also can you specify me what you meant "currentevent.start" – Jaison James May 07 '14 at 13:21
  • I have tried out your updated code, but its always getting else case. – Jaison James May 08 '14 at 04:44
  • So interesting! It works at my side. Seems my answer has 5 votes, not sure if work at their side. By the way, what errors at your side? – Weimin Ye May 08 '14 at 04:48
  • Its always getting else case and found condition result like this "true : Wed May 14 2014 00:00:00 GMT+0530 (India Standard Time) : undefined : false". It means "currentevent.start" is undefined. – Jaison James May 08 '14 at 04:50
  • So interesting... What are the value of allevents and the 1st currentevent? – Weimin Ye May 08 '14 at 04:54
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/52254/discussion-between-jaison-and-billy-yeah) – Jaison James May 08 '14 at 05:01
0

Unfortunately above answer is not working in my scenario. So I found one solution from my own way. May it will help someone, but not sure its a right way.

var allevents = $inlineCalendar.fullCalendar('clientEvents');
                var arrAlleventsDate = [];

                for(i in allevents){
                    if(arrAlleventsDate.indexOf($.fullCalendar.formatDate(allevents[i].start, 'yyyyMMdd')) == -1){
                        arrAlleventsDate.push($.fullCalendar.formatDate(allevents[i].start, 'yyyyMMdd'));
                    }
                }
if(arrAlleventsDate.indexOf($.fullCalendar.formatDate(newDay, 'yyyyMMdd')) == -1){
                        $inlineCalendar.fullCalendar('renderEvent', copiedEventObject, true); 
                    }

If you wish work for each event, add event id as a prefix for date.

Jaison James
  • 4,414
  • 4
  • 42
  • 54
0

In agenda-view, I check in "select" if there are others event in the selected period; the cheks is on limit number, a field (es: title or custom field) and time period:

 select: function(start, end, jsEvent) {
   var maxEvent = 2;
   var allEvents = $('#calendar').fullCalendar( 'clientEvents');
   var xst = moment(start);
   var xen = moment(end);
   var eventsCount = 0;
   var collideEvent;
   var tempField;
   for(var i=0;i<allEvents.length;i++ ) {
     var currentEvent=allEvents[i];
     if(xst.isBetween(currentevent.start,currentevent.end,null, '[)') || 
        xen.isBetween(currentevent.start,currentevent.end,null, '(]')) {
         eventsCount++;
         if(eventsCount>=maxEvent && tempField != currentEvent.field) {
           alert("!");
           $('#calendar').fullCalendar('unselect');
           return false;
           break;
         }
         collideEvent = currentEvent;
         tempField = collideEvent.field;                                
      }
   //proceed!
}