2021-09-10 17:39:40 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace backend\widgets;
|
|
|
|
|
|
|
|
|
|
|
|
use yii\base\Widget;
|
|
|
|
use yii\helpers\Html;
|
|
|
|
|
|
|
|
|
|
|
|
class Calendar extends Widget
|
|
|
|
{
|
|
|
|
public $button;
|
2021-09-13 12:09:56 +03:00
|
|
|
|
|
|
|
public $css;
|
|
|
|
|
2021-09-10 17:39:40 +03:00
|
|
|
public $runBuild = 'function (date, content){
|
|
|
|
this.build(date, content)
|
|
|
|
}';
|
2021-09-13 12:09:56 +03:00
|
|
|
|
2021-09-10 17:39:40 +03:00
|
|
|
public $updateContent = "function(){
|
2021-09-13 12:09:56 +03:00
|
|
|
return [];
|
|
|
|
/*
|
|
|
|
Example, return [model1, model2, model3 , ...] :
|
|
|
|
|
2021-09-10 17:39:40 +03:00
|
|
|
let monthNumber = date.substr(5, 2);
|
|
|
|
return fetch('../ajax/get-birthday-by-month?' +
|
|
|
|
'month=' + monthNumber)
|
|
|
|
.then((res) => {
|
|
|
|
return res.json()
|
2021-09-13 12:09:56 +03:00
|
|
|
})*/
|
2021-09-10 17:39:40 +03:00
|
|
|
}";
|
2021-09-13 12:09:56 +03:00
|
|
|
|
2021-09-10 17:39:40 +03:00
|
|
|
public $getColor = "function (date, dates = null) {
|
2021-09-13 12:09:56 +03:00
|
|
|
return `className`;
|
|
|
|
}";
|
|
|
|
|
2021-09-10 17:39:40 +03:00
|
|
|
public $getHtmlContentForDate = 'function (content, date) {
|
2021-09-13 12:09:56 +03:00
|
|
|
return `<div class="content">${content}</div>`;
|
2021-09-10 17:39:40 +03:00
|
|
|
}';
|
|
|
|
|
2021-09-13 12:09:56 +03:00
|
|
|
public $script = 'CalendarHelper.main()';
|
2021-09-10 17:39:40 +03:00
|
|
|
|
|
|
|
public function init()
|
|
|
|
{
|
|
|
|
parent::init();
|
|
|
|
$view = $this->getView();
|
|
|
|
AppAsset::register($view);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function run()
|
|
|
|
{
|
|
|
|
echo Html::beginTag('section', ['class' => 'calendar-contain']);
|
|
|
|
echo Html::beginTag('aside', ['class' => 'calendar__sidebar']);
|
|
|
|
echo Html::beginTag('section', ['class' => 'title-bar']);
|
|
|
|
echo $this->button;
|
|
|
|
echo Html::input('date', null, date('Y-m-d'), ['class' => 'form-control', 'id' => 'date',]);
|
|
|
|
echo Html::endTag('section');
|
|
|
|
echo Html::tag('h2', date('l') . '<br>' . date('F d'), ['class' => 'sidebar__heading']);
|
|
|
|
echo Html::beginTag('ul', ['class' => 'sidebar__list']);
|
|
|
|
echo Html::endTag('ul');
|
|
|
|
echo Html::endTag('aside');
|
|
|
|
echo Html::beginTag('section', ['class' => 'calendar__days']);
|
|
|
|
echo Html::endTag('section');
|
|
|
|
echo Html::endTag('section');
|
|
|
|
|
|
|
|
$this->view->registerJs('
|
|
|
|
CalendarHelper._runBuild = ' . $this->runBuild . ';
|
|
|
|
CalendarHelper._getHtmlContentForDate = ' . $this->getHtmlContentForDate . ';
|
|
|
|
CalendarHelper._updateContent = async ' . $this->updateContent . ';
|
|
|
|
CalendarHelper._getColor = ' . $this->getColor . ';
|
|
|
|
|
2021-09-13 12:09:56 +03:00
|
|
|
'.$this->script
|
2021-09-10 17:39:40 +03:00
|
|
|
);
|
2021-09-13 12:09:56 +03:00
|
|
|
$this->view->registerCss($this->css);
|
2021-09-10 17:39:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
?>
|
|
|
|
|