Search code examples
fullcalendarfullcalendar-scheduler

Highlight some custom events on first load Full Calendar


I am using fullCalendar in my project. My issue is I want to prepopulte the calendar, I am using these settings as

initScheduleCalendar = ->
  scheduleCalendar = $('#cloud-recording-calendar').fullCalendar
    axisFormat: 'HH'
    allDaySlot: false
    columnFormat: 'ddd'
    defaultDate: '1970-01-01'
    slotDuration: '00:60:00'
    defaultView: 'agendaWeek'
    dayNamesShort: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]
    eventColor: '#428bca'
    editable: true

and the days I want to highlight are

fullWeekSchedule =
  "Monday": ["08:00-17:30"]
  "Tuesday": ["08:00-17:30"]
  "Wednesday": ["08:00-17:30"]
  "Thursday": ["08:00-17:30"]
  "Friday": ["08:00-17:30"]
  "Saturday": []
  "Sunday": []

I want those days pre highlighted on first page load. I dont know whic option is going to be used for this? any help will be appreciated thanks


Solution

  • renderEvents = ->
      schedule = fullWeekSchedule
      days = _.keys(schedule)
      calendarWeek = currentCalendarWeek()
    
      _.forEach days, (weekDay) ->
        day = schedule[weekDay]
        unless day.length == 0
          _.forEach day, (event) ->
            start = event.split("-")[0]
            end = event.split("-")[1]
            event =
              start: moment("#{calendarWeek[weekDay]} #{start}", "YYYY-MM-DD HH:mm")
              end: moment("#{calendarWeek[weekDay]} #{end}", "YYYY-MM-DD HH:mm")
            scheduleCalendar.fullCalendar('renderEvent', event, true)
    
    currentCalendarWeek = ->
      calendarWeek = {}
      weekStart = scheduleCalendar.fullCalendar('getView').start
      weekEnd = scheduleCalendar.fullCalendar('getView').end
      day = weekStart
      while day.isBefore(weekEnd)
        weekDay = day.format("dddd")
        calendarWeek[weekDay] = day.format('YYYY-MM-DD')
        day.add 1, 'days'
      calendarWeek
    

    I did this way.. if anyone interested to know..