Skip to content

Instantly share code, notes, and snippets.

@mgerasimchuk
Last active October 26, 2016 15:32
Show Gist options
  • Save mgerasimchuk/9efd2b6b761482ffb0d63348069b012e to your computer and use it in GitHub Desktop.
Save mgerasimchuk/9efd2b6b761482ffb0d63348069b012e to your computer and use it in GitHub Desktop.
FullCalendar js plugin + ajax in view
<?php
use common\models\Project;
/* @var $this yii\web\View */
/* @var $model Project */
$this->title = Yii::t('app', 'General statistic');
$this->params['breadcrumbs'][] = $this->title;
\backend\assets\FullCalendarAsset::register($this);
$times = \yii\helpers\Json::encode($times);
$js = <<<JS
$('#calendar').fullCalendar({
lang: 'ru',
timezone: 'Asia/Krasnoyarsk',
firstDay: 1,
allDaySlot: false,
minTime: '10:00:00',
maxTime: '21:00:00',
slotEventOverlap: false,
contentHeight: 'false',
header: {
left: 'prev,next today',
center: 'title',
},
editable: false,
eventLimit: false, // allow "more" link when too many events
events: $times,
height: 500,
eventClick: function(calEvent, jsEvent, view) {
var result = "RES";
var checkDate = calEvent.start;
$.ajax({
type: "GET",
url: "get-work-log-info",
data:{date:checkDate.year() + '-' + (checkDate.month() + 1) + '-' + checkDate.date()},
success: function(result) {
$('.modal-title').text('Статистика на ' + checkDate.format('DD.MM.Y') + ', часы: ' + calEvent.title);
$("#work-log-info-content").html(result);
$("#work-log-info").modal('show');
}
});
},
eventMouseover: function(calEvent, jsEvent, view) {
$(this).css('background-color', 'green');
$(this).css('border-color', 'green');
},
eventMouseout: function(calEvent, jsEvent, view) {
$(this).css('background-color', '#3a87ad');
$(this).css('border-color', '#3a87ad');
},
});
JS;
$this->registerJs($js);
?>
<div class="project-index">
<div id='calendar'></div>
<div class="modal fade" tabindex="-1" role="dialog" id="work-log-info">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
aria-hidden="true">&times;</span></button>
<h4 class="modal-title">text</h4>
</div>
<div class="modal-body">
<div id='work-log-info-content'></div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal"><?= Yii::t('app',
"Close") ?></button>
</div>
</div>
</div>
</div>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment