How to make events from one source render in background

Viewed 111

I have added events to my calendar from two sources. One source is a json object and other is a google calendar. Now, I want to make events from google calendar render as background events (nothing should happen if user clicks on it) and for json events I need to perform some action when user clicks on it.

This is my code:

document.addEventListener('DOMContentLoaded', function() {
  var calendarEl = document.getElementById('calendar');

  var calendar = new FullCalendar.Calendar(calendarEl, {
    googleCalendarApiKey: 'AIzaSyACMTvM6xtGLSgkyLZqKw2t4chXf-tw8u8',
    plugins: ['dayGrid', 'timeGrid', 'list', 'interaction', 'bootstrap', 'rrule', 'moment', 'googleCalendar'],
    themeSystem: 'bootstrap',
    timeZone: 'Asia/Colombo',
    height: 'auto',
    fixedWeekCount: false,
    slotDuration: '00:15:00',
    slotLabelInterval: '01:00:00',
    navLinks: true,
    nowIndicator: true,
    selectable: true,
    selectMirror: true,
    slotLabelFormat: {
      hour: 'numeric',
      minute: '2-digit',
      omitZeroMinute: false,
    },
    businessHours: {
      // days of week. an array of zero-based day of week integers (0=Sunday)
      daysOfWeek: [1, 2, 3, 4, 5, 6], // Monday - saturday

      startTime: '09:00', // a start time 
      endTime: '16:00', // an end time 
    },
    views: {
      listDay: {
        buttonText: 'Todays events'
      },
      listWeek: {
        buttonText: 'This week events'
      },
      listMonth: {
        buttonText: 'This month events'
      }
    },
    footer: {
      center: 'listDay listWeek listMonth'
    },
    header: {
      left: 'prevYear,prev,next,nextYear today',
      center: 'title',
      right: 'dayGridMonth,timeGridWeek,timeGridDay'
    },
    eventSources: [
      // your event source
      {
        events: {!!$ce!!
        },
        color: 'blue',
        editable: true
      },
      {

        googleCalendarId: 'en.lk#holiday@group.v.calendar.google.com',
        rendering: 'background',
        color: 'yellow',
        editable: false

      }
    ],

    select: function(info) {
      alert('selected ' + info.startStr + ' to ' + info.endStr);
    }

    /* @can('isManager')
        events: 'https://fullcalendar.io/demo-events.json'
      @endcan */
  });

  calendar.render();
});
<div class="container-fluid mt--7">
  <div class="row">
    <div class="col-xl-12 mb-5 mb-xl-0">
      <div class="card bg-white shadow">
        <div class="card-body">
          <div id="calendar" style="height: 800px;"></div>
        </div>
      </div>
    </div>
  </div>
</div>

But my google calendar events don't show as background events. I try to add ids for each event sources like below and it makes my entire calendar disappear:

eventSources: [
      // your event source
      {
        id='a',
        events:{!! $ce !!},
        color: 'blue',
        editable:true
      },
      { 
        id='b',
        googleCalendarId: 'en.lk#holiday@group.v.calendar.google.com',
        rendering: 'background',
        color: 'yellow',
        editable:false
      }
],

Now I need at least a way to identify events from each source separately.

I also tried

info.event.source

and

info.event.source.id

and even

info.event.color

to use as my identifier, but info.event.source shows as an object and info.source.id, info.source.color show as undefined properties

also this is how I pass JSON to my laravel view from controller'

<?php

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\DB;


class HomeController extends Controller
{
    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('auth');
    }

    /**
     * Show the application dashboard.
     *
     * @return \Illuminate\View\View
     */
    public function index()
    {
        
        $calender_events = DB::table('calender_events')->get();

        $ce = $calender_events->toJson();
        
       
        
        return view('dashboard', compact('ce'));
       
    }
}

Please help.

1 Answers

I found answer my self,

<script>


document.addEventListener('DOMContentLoaded', function() {
        var calendarEl = document.getElementById('calendar');

        var calendar = new FullCalendar.Calendar(calendarEl, {
          googleCalendarApiKey: 'AIzaSyACMTvM6xtGLSgkyLZqKw2t4chXf-tw8u8',
    plugins: [ 'dayGrid', 'timeGrid', 'list','interaction','bootstrap','rrule','moment','googleCalendar'  ],
    themeSystem: 'bootstrap',
    timeZone: 'Asia/Colombo',
    height: 'auto',
    fixedWeekCount:false,
    slotDuration: '00:15:00',
    slotLabelInterval:'01:00:00',
    navLinks:true,
    nowIndicator: true,
    selectable: true,
    selectMirror:true,
    slotLabelFormat:{
  hour: 'numeric',
  minute: '2-digit',
  omitZeroMinute: false,
  
},
businessHours: {
// days of week. an array of zero-based day of week integers (0=Sunday)
daysOfWeek: [ 1, 2, 3, 4, 5, 6 ], // Monday - saturday

startTime: '09:00', // a start time 
endTime: '16:00', // an end time 
},
    views: {
      listDay: { buttonText: 'Todays events' },
      listWeek: { buttonText: 'This week events' },
      listMonth: { buttonText: 'This month events' }
    },
    footer:{
      center: 'listDay listWeek listMonth'
    },
    header: {
      left: 'prevYear,prev,next,nextYear today',
      center: 'title',
      right: 'dayGridMonth,timeGridWeek,timeGridDay'
    },

     eventSources: [

// your event source
{
events:{!! $ce !!},
id:'personal',

},
{ 

googleCalendarId: 'en.lk#holiday@group.v.calendar.google.com',
id:'google',

}
],


eventClick: function(info) {
info.jsEvent.preventDefault(); // don't let the browser navigate
if(info.event.source.id=='google'){
  alert('Event: google ');
}else{
  alert('Event: personal ');
}
 

},
        });
        
        calendar.render();
      });
      
                  
                  

    
</script>
I just missed a comma near

googleCalendarId: 'en.lk#my@group.v.calendar.google.com',
id:'google',

and

events:{!! $ce !!},
id:'personal',

and for background rendering , full-calendar event source object doesn't have option "rendering" (only single events can render in background)

anyway thanks for your help!.

Related