Улучшил виджет, доделал календарь дней рождений

This commit is contained in:
maxim
2021-09-13 12:09:56 +03:00
parent 125bddde21
commit efcd8f9908
5 changed files with 118 additions and 151 deletions

View File

@ -42,12 +42,10 @@ class CalendarController extends Controller
* Renders the index view for the module
* @return string
*/
public function actionAlternative(){
public function actionCalendar(){
$searchModel = new UserCardSearch();
$dataProvider = $searchModel->search(['month'=>date('m', strtotime('2019-07-03'))]);
return $this->render('alternative', [
'dataProvider' => $dataProvider
]);
return $this->render('calendar');
}
public function actionIndex()

View File

@ -0,0 +1,59 @@
<?php
use yii\helpers\Html;
$this->title = 'Календарь ДР';
?>
<?= \backend\widgets\Calendar::widget([
'css' => '.success{color: orange;}',
'button' => Html::a('<i class="fas fa-long-arrow-alt-left"></i> Назад',
Yii::$app->request->referrer, ['class' => 'btn btn-primary',]),
'runBuild' => "function (date, content){
this.build(date, content)
}",
'updateContent' => "function(date){
let monthNumber = date.substr(5, 2);
return fetch('../ajax/get-birthday-by-month?' +
'month=' + monthNumber)
.then((res) => {
return res.json()
})
}",
'getColor' => "function (date, dates = null) {
for (let contentDate of dates) {
if (contentDate['dob'].substr(8, 2) == DateHelper.intToDate(date.getDate())) {
return 'success';
}
}
}",
'getHtmlContentForDate' => 'function (content, date) {
let flag = false
let html = `<table class="table table-striped table-bordered">
<thead>
<tr>
<th>#</th>
<th>ФИО</th>
<th>Дата рождения</th>
<th class="action-column">&nbsp;</th>
</tr>
</thead><tbody>`;
for (let i = 1; i <= content.length; i++) {
let model = content[i - 1];
if (model["dob"].substr(8, 2) == date.substr(8, 2)) {
flag = true;
html += `<tr data-key="${model["id"]}">`
html += `<td>${i}</td>`
html += `<td>${model["fio"]}</td>`
html += `<td>${model["dob"]}</td>`
html += CalendarHelper._getActionColumn(`secure/calendar/calendar`,model[`id`])
html += `</tr>`
}
}
html += `</tbody></table>`
if (flag) return html;
return "empty"
}'
]) ?>

View File

@ -27,7 +27,7 @@ use yii\widgets\Pjax;
</select>
</p>
<?=Html::a('Календарь дней рождений '.Html::tag('i', null, ['class' => 'far fa-calendar-alt']),
['alternative'], ['class' => 'btn btn-success', 'style' => 'margin-left: 10px'])?>
['calendar'], ['class' => 'btn btn-success', 'style' => 'margin-left: 10px'])?>
</div>
<?php
Pjax::begin(['id' => 'reload']);