diff --git a/common/models/Support.php b/common/models/Support.php new file mode 100644 index 0000000..2fe9381 --- /dev/null +++ b/common/models/Support.php @@ -0,0 +1,90 @@ + null, + ], + [ + [ + 'book_id', + 'sum', + 'status', + ], + 'integer', + ], + ['email', 'email'], + [ + [ 'email', 'name' ], + 'string', + 'max' => 255, + ], + [ + [ 'book_id' ], + 'exist', + 'skipOnError' => true, + 'targetClass' => Book::className(), + 'targetAttribute' => [ 'book_id' => 'id' ], + ], + [ + ['email', 'sum'], 'required' + ] + ]; + } + + /** + * {@inheritdoc} + */ + public function attributeLabels() + { + return [ + 'id' => Yii::t('app', 'ID'), + 'book_id' => Yii::t('app', 'Book ID'), + 'email' => Yii::t('app', 'Email'), + 'sum' => Yii::t('app', 'Sum'), + 'status' => Yii::t('app', 'Status'), + ]; + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getBook() + { + return $this->hasOne(Book::className(), [ 'id' => 'book_id' ]); + } + } diff --git a/console/migrations/m180614_103157_create_support_table.php b/console/migrations/m180614_103157_create_support_table.php new file mode 100644 index 0000000..9988443 --- /dev/null +++ b/console/migrations/m180614_103157_create_support_table.php @@ -0,0 +1,41 @@ +createTable('support', [ + 'id' => $this->primaryKey(), + 'book_id' => $this->integer(), + 'name' => $this->string(), + 'email' => $this->string(), + 'sum' => $this->integer(), + 'status' => $this->integer() + ]); + + $this->addForeignKey('support_book_fk', + 'support', + 'book_id', + 'book', + 'id', + 'CASCADE', + 'CASCADE'); + } + + /** + * {@inheritdoc} + */ + public function safeDown() + { + $this->dropForeignKey('support_book_fk', 'support'); + $this->dropTable('support'); + } +} diff --git a/frontend/controllers/SupportController.php b/frontend/controllers/SupportController.php new file mode 100644 index 0000000..3621d53 --- /dev/null +++ b/frontend/controllers/SupportController.php @@ -0,0 +1,32 @@ + $book_id, + 'status' => 0 + ]); + $book = Book::find()->with('author')->where(['id' => $book_id])->one(); + if ($model->load(\Yii::$app->request->post()) and $model->save()){ + \Yii::$app->session->setFlash('success', 'Дякуємо за ваш запит. Найближчим часом, наш менеджер зв\'яжеться з Вами для уточнення деталей'); + return $this->redirect(['site/index']); + } + return $this->render('index', [ + 'model' => $model, + 'book' => $book + ]); + } + } \ No newline at end of file diff --git a/frontend/views/book/_book.php b/frontend/views/book/_book.php index ad29a8f..15b25a2 100644 --- a/frontend/views/book/_book.php +++ b/frontend/views/book/_book.php @@ -19,7 +19,7 @@ price == null){?>
- Підтримати + Підтримати
вартість price?> грн.
diff --git a/frontend/views/book/view.php b/frontend/views/book/view.php index 189a463..15a6c78 100644 --- a/frontend/views/book/view.php +++ b/frontend/views/book/view.php @@ -67,7 +67,7 @@

460 підтримувачів

- Підтримати + Підтримати
@@ -83,9 +83,9 @@

поділитися в соціальних мережах

diff --git a/frontend/views/layouts/main.php b/frontend/views/layouts/main.php index 638e6ee..129ccf2 100755 --- a/frontend/views/layouts/main.php +++ b/frontend/views/layouts/main.php @@ -47,6 +47,14 @@ ] ); $module = \Yii::$app->getModule('feedback'); + + if (\Yii::$app->session->hasFlash('success')) { + $message = \Yii::$app->session->getFlash('success'); + $js = <<registerJs($js, View::POS_READY); + } ?> beginPage() ?> diff --git a/frontend/views/support/index.php b/frontend/views/support/index.php new file mode 100644 index 0000000..e2dc226 --- /dev/null +++ b/frontend/views/support/index.php @@ -0,0 +1,46 @@ + +
+
+
+
+
Підтримати
+
+
+
+ +
+
+ +
title?>
+
Автор: author->name?> author->secondname?>
+
+ field($model, 'name')->label('Ім\'я')?> +
+
+ field($model, 'email')->label('Пошта')?> +
+ +
+
+ field($model, 'sum')->label('Cума в гривнях')?> +
+
+ field($model, 'book_id')->hiddenInput()->label(false);?> + field($model, 'status')->hiddenInput()->label(false);?> +
+ +
+ +
+
+
+
+
diff --git a/frontend/web/js/script.js b/frontend/web/js/script.js index 4e80a04..1f5b8c1 100644 --- a/frontend/web/js/script.js +++ b/frontend/web/js/script.js @@ -97,12 +97,12 @@ $(document).ready(function() { block.addClass('vis_'); $('body, html').animate({scrollTop:block.offset().top - 36},500) - }) - $('body').on('click','.hidden-comments-form-card button', function () { - $('.hidden-comments-form-card').removeClass('vis_'); - - alert('thiiiis') - }) + }); +// $('body').on('click','.hidden-comments-form-card button', function () { +// $('.hidden-comments-form-card').removeClass('vis_'); +// +// alert('thiiiis') +// }) } @@ -252,23 +252,47 @@ $(document).ready(function() { } //после удачной отправки формы запускать success() // success() - function success() { - var pos = ($(window).scrollTop()) + 30; - $('.forms_').animate({opacity: 0, top: '0'}, 200,function(){ - $(this).css('display', 'none'); +// function success(message) { +// var pos = ($(window).scrollTop()) + 30; +// $('.forms_').animate({opacity: 0, top: '0'}, 200,function(){ +// $(this).css('display', 'none'); +// }); +// setTimeout(function () { +// $('#overlay').fadeIn(400); +// $('#success_form').find('.txt-success').html(message); +// $('#success_form').css('display', 'block').animate({opacity: 1, top: pos}, 700); +// },400) +// } + + + +}); +function success(message) { + document.querySelector('#success_form .txt-success').innerHTML = message; + var pos = ($(window) + .scrollTop()) + 30 + 60; + $('.forms_') + .animate({ + opacity: 0, + top: '0' + }, 200, function() { + $(this) + .css('display', 'none'); }); - setTimeout(function () { - $('#overlay').fadeIn(400); - $('#success_form').css('display', 'block').animate({opacity: 1, top: pos}, 700); - },400) - } - - - - - -}) + setTimeout(function() { + $('#overlay') + .fadeIn(400, function() { + $('#success_form') + .css('display', 'block') + .animate({ + opacity: 1, + top: pos + }, 700); + }); + }, 400) +} +window.success = success; -- libgit2 0.21.4