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-13 16:40:37 +03:00
|
|
|
public $dayUpdate;
|
2021-09-13 12:09:56 +03:00
|
|
|
|
2021-09-13 16:40:37 +03:00
|
|
|
public $monthUpdate;
|
2021-09-13 12:09:56 +03:00
|
|
|
|
2021-09-13 16:40:37 +03:00
|
|
|
public $colorClasses = ['accept' => 'access', 'default' => 'danger', 'offDay' => ''];
|
2021-09-13 12:09:56 +03:00
|
|
|
|
2021-09-13 16:40:37 +03:00
|
|
|
public $offDaysShow = 1;
|
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('
|
2021-09-13 16:40:37 +03:00
|
|
|
CalendarHelper._getDayContent = async function(date){
|
|
|
|
let url = `'.$this->dayUpdate['url'].'?`;
|
|
|
|
'.(isset($this->dayUpdate['data'])?'
|
|
|
|
let data = '.json_encode($this->dayUpdate['data']):'
|
|
|
|
let data = {};
|
|
|
|
').'
|
|
|
|
if(Object.keys(data).length){
|
|
|
|
for (let key in data){
|
|
|
|
url += key+`=`+ data[key]+`&`
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return fetch(url+
|
|
|
|
`date=` + DateHelper.dateToString(date))
|
|
|
|
.then((res) => {
|
|
|
|
return res.text()
|
|
|
|
})
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
CalendarHelper._getMonth = async function(month, year){
|
|
|
|
let url = `'.$this->monthUpdate['url'].'?`;
|
|
|
|
'.(isset($this->monthUpdate['data'])?'
|
|
|
|
let data = '.json_encode($this->monthUpdate['data']):'
|
|
|
|
let data = {};
|
|
|
|
').'
|
|
|
|
if(Object.keys(data).length){
|
|
|
|
for (let key in data){
|
|
|
|
url += key+`=`+ data[key]+`&`
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return fetch(url+
|
|
|
|
`&month=` + month +
|
|
|
|
`&year=` + year)
|
|
|
|
.then((res) => {
|
|
|
|
return res.json()
|
|
|
|
})
|
|
|
|
};
|
|
|
|
|
|
|
|
CalendarHelper._getColor = function (date, dates = null) {
|
|
|
|
if ('.$this->offDaysShow.')
|
|
|
|
if ([6, 0].includes(date.getDay()))
|
|
|
|
return `'.$this->colorClasses['offDay'].'`;
|
|
|
|
|
|
|
|
for (let i = 0; i<dates.length; i++){
|
|
|
|
if (dates[i] == DateHelper.dateToString(date)){
|
|
|
|
return `'.$this->colorClasses['accept'].'`
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return `'.$this->colorClasses['default'].'`;
|
|
|
|
}
|
|
|
|
|
2021-09-10 17:39:40 +03:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
?>
|
|
|
|
|