From efcd8f99084e1e6374b128625b30f0aaffe73c12 Mon Sep 17 00:00:00 2001 From: maxim Date: Mon, 13 Sep 2021 12:09:56 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A3=D0=BB=D1=83=D1=87=D1=88=D0=B8=D0=BB=20?= =?UTF-8?q?=D0=B2=D0=B8=D0=B4=D0=B6=D0=B5=D1=82,=20=D0=B4=D0=BE=D0=B4?= =?UTF-8?q?=D0=B5=D0=BB=D0=B0=D0=BB=20=D0=BA=D0=B0=D0=BB=D0=B5=D0=BD=D0=B4?= =?UTF-8?q?=D0=B0=D1=80=D1=8C=20=D0=B4=D0=BD=D0=B5=D0=B9=20=D1=80=D0=BE?= =?UTF-8?q?=D0=B6=D0=B4=D0=B5=D0=BD=D0=B8=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controllers/CalendarController.php | 6 +- .../calendar/views/calendar/calendar.php | 59 +++++++ .../modules/calendar/views/calendar/index.php | 2 +- backend/widgets/Calendar.php | 158 ++---------------- .../Calendar/assets/js/src/CalendarHelper.js | 44 ++++- 5 files changed, 118 insertions(+), 151 deletions(-) create mode 100644 backend/modules/calendar/views/calendar/calendar.php diff --git a/backend/modules/calendar/controllers/CalendarController.php b/backend/modules/calendar/controllers/CalendarController.php index c6760bd..78ed1ec 100644 --- a/backend/modules/calendar/controllers/CalendarController.php +++ b/backend/modules/calendar/controllers/CalendarController.php @@ -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() diff --git a/backend/modules/calendar/views/calendar/calendar.php b/backend/modules/calendar/views/calendar/calendar.php new file mode 100644 index 0000000..ca050c5 --- /dev/null +++ b/backend/modules/calendar/views/calendar/calendar.php @@ -0,0 +1,59 @@ +title = 'Календарь ДР'; +?> + '.success{color: orange;}', + + 'button' => Html::a(' Назад', + 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 = ` + + + + + + + + `; + 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 += `` + html += `` + html += `` + html += `` + html += CalendarHelper._getActionColumn(`secure/calendar/calendar`,model[`id`]) + html += `` + } + } + html += `
#ФИОДата рождения 
${i}${model["fio"]}${model["dob"]}
` + if (flag) return html; + return "empty" + }' +]) ?> + + diff --git a/backend/modules/calendar/views/calendar/index.php b/backend/modules/calendar/views/calendar/index.php index 18a1223..1783f5f 100644 --- a/backend/modules/calendar/views/calendar/index.php +++ b/backend/modules/calendar/views/calendar/index.php @@ -27,7 +27,7 @@ use yii\widgets\Pjax;

'far fa-calendar-alt']), - ['alternative'], ['class' => 'btn btn-success', 'style' => 'margin-left: 10px'])?> + ['calendar'], ['class' => 'btn btn-success', 'style' => 'margin-left: 10px'])?> 'reload']); diff --git a/backend/widgets/Calendar.php b/backend/widgets/Calendar.php index 59ac6c8..3c922dd 100644 --- a/backend/widgets/Calendar.php +++ b/backend/widgets/Calendar.php @@ -5,158 +5,40 @@ namespace backend\widgets; use yii\base\Widget; use yii\helpers\Html; -use yii\helpers\Url; class Calendar extends Widget { public $button; + + public $css; + public $runBuild = 'function (date, content){ this.build(date, content) }'; + public $updateContent = "function(){ + return []; + /* + Example, return [model1, model2, model3 , ...] : + let monthNumber = date.substr(5, 2); return fetch('../ajax/get-birthday-by-month?' + 'month=' + monthNumber) .then((res) => { return res.json() - }) + })*/ }"; + public $getColor = "function (date, dates = null) { - for (let contentDate of dates) { - if (contentDate['dob'].substr(8, 2) == DateHelper.intToDate(date.getDate())) { - return 'success'; - } - } - }"; + return `className`; + }"; + public $getHtmlContentForDate = 'function (content, date) { - console.log(content) - let flag = false - let html = ` - - - - - - - - `; - 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 += `` - html += `` - html += `` - html += `` - html += `` - html += `` - } - } - html += `
#ФИОДата рождения 
${i}${model["fio"]}${model["dob"]} - - - - - - -
` - if (flag) return html; - return "empty" + return `
${content}
`; }'; - /* - - CalendarHelper._updateContent = async function(){ - let monthNumber = date.substr(5, 2); - return fetch('../ajax/get-birthday-by-month?' + - 'month=' + monthNumber) - .then((res) => { - return res.json() - }) - } - - CalendarHelper._getColor = function (date, dates = null) { - for (let contentDate of dates) { - if (contentDate['dob'].substr(8, 2) == DateHelper.intToDate(date.getDate())) { - return 'success'; - } - } - } - - CalendarHelper._getHtmlContentForDate = function (content, date) { - console.log(content) - let flag = false - - let html = ` - - - - - - - `; - 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 += `` - html += `` - html += `` - html += `` - html += `` - html += `` - } - } - html += `
#ФИО - Дата рождения 
${i}${model['fio']}${model['dob']} - - - - - - -
` - if (flag) return html; - return "empty" - } - */ + public $script = 'CalendarHelper.main()'; public function init() { @@ -167,7 +49,6 @@ class Calendar extends Widget public function run() { - echo Html::beginTag('section', ['class' => 'calendar-contain']); echo Html::beginTag('aside', ['class' => 'calendar__sidebar']); echo Html::beginTag('section', ['class' => 'title-bar']); @@ -188,16 +69,11 @@ class Calendar extends Widget CalendarHelper._updateContent = async ' . $this->updateContent . '; CalendarHelper._getColor = ' . $this->getColor . '; - CalendarHelper.main()' + '.$this->script ); + $this->view->registerCss($this->css); } } - - ?> - diff --git a/backend/widgets/Calendar/assets/js/src/CalendarHelper.js b/backend/widgets/Calendar/assets/js/src/CalendarHelper.js index aa8dbc7..fac6766 100644 --- a/backend/widgets/Calendar/assets/js/src/CalendarHelper.js +++ b/backend/widgets/Calendar/assets/js/src/CalendarHelper.js @@ -57,6 +57,9 @@ class CalendarHelper { let days = document.querySelectorAll('.calendar__day ') for (let i = 0; i < days.length; i++) { + if (parseInt(days[i].textContent)===parseInt(datePicker.value.substr(8,2))){ + days[i].classList.add('active_day') + } else if (days[i].classList.contains('active_day')) days[i].classList.remove('active_day') } @@ -87,12 +90,11 @@ class CalendarHelper { for (let i = 0; i < Object.keys(days).length; i++) { let dateDay = parseInt(days[i].textContent); - if (day) { - if (parseInt(day.textContent) == dateDay && !days[i].classList.contains('inactive')) { - days[i].classList.add('active_day') - } + if (parseInt(datePicker.value.substr(8,2)) == dateDay && !days[i].classList.contains('inactive')) { + days[i].classList.add('active_day') } + if (days[i].classList.contains('inactive')) { days[i].onclick = function () { let date = CalendarHelper._getFutureDate(datePicker.value, parseInt(days[i].textContent)) @@ -103,7 +105,6 @@ class CalendarHelper { days[i].onclick = function () { datePicker.value = datePicker.value.substr(0, 8) + DateHelper.intToDate(dateDay); datePicker.onchange(this) - days[i].classList.add('active_day') } } } @@ -183,4 +184,37 @@ class CalendarHelper { } + static _getActionColumn(url, id) { + + return ` + + + + + + + + + + + `; + } + }