philippfrenzel / yii2fullcalendar

JQuery Fullcalendar Yii2 Extension
GNU General Public License v2.0
133 stars 97 forks source link

Auto Update Event #78

Closed nagaokashi closed 7 years ago

nagaokashi commented 7 years ago

For example: A user is opening a calendar. B user is also opening sane calendar as A user. When A has just created an event, I want to calendar of B user auto update event which A created without do anything. How to do it?

My view:

    <?= \yii2fullcalendar\yii2fullcalendar::widget(array(
        'options' => [
        ],
        'clientOptions' => [
            'allDaySlot' => false,
            'selectHelper' => true,
            'eventClick' => new JsExpression($JSEventClick),
            'dayClick' => new JsExpression($JSDayClick),
            'eventMouseover' =>new JsExpression($JSDayMouseover),
            'eventMouseout' =>new JsExpression($JSDayMouseout),
            'defaultView' => 'agendaWeek',
            'longPressDelay' => 2000, // để cho mobile
            'firstDay' => date('w'), //Lấy ngày hiện tai làm ngày đàu tiên của tuần   // Sunday=0, Monday=1, Tuesday=2, etc.
            'defaultDate' => $defaultDate,  // Show đúng ngày mà đã chỉ định
            'height' => MyHelpers::checkMobileAccess() ? 400 : 570,
            'header' => [
                'center'=>'prev,next today',
                'left'=>'', //'title',
                'right'=>'agendaDay,agendaWeek,month',
            ],
            'businessHours' => [
                // days of week. an array of zero-based day of week integers (0=Sunday)
                'dow' => [ 0, 1, 2, 3, 4, 5, 6 ], // Sunday - Saturday
                'start' => explode(" - ", $modelSanChu->gioHoatDong)[0], //'5:00'
                'end' => explode(" - ", $modelSanChu->gioHoatDong)[1], // '18:00'
            ],
            'navLinks'=> true,
        ],
        //'events'=> $events,   // Dung khi goi action index
        'ajaxEvents' => Url::to(['/datsan/jsoncalendar', 'id_sanCon'=>$modelSanCon->id, 'id_datSan'=>$id_datSan])
    ));
    ?>
philippfrenzel commented 7 years ago

Hey, I recommend you implement something like a client timer that checks for new calender entries all 5 seconds - otherwise if you really wanna "push" a calender entry you need to use a websocket connection that allows you to add the event upon a server message!

nagaokashi commented 7 years ago

Could you teach me how to implement a setting that create an ajaxEvent to update data without refresh browser ?

nagaokashi commented 7 years ago

I just do as below:

<script>
setInterval(function(){ $('#w0').fullCalendar('refetchEvents'); }, 5000);
</script>