diff --git a/composer.json b/composer.json index 7f29fa6..6b99d33 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,8 @@ "php": ">=5.4.0", "yiisoft/yii2": "~2.0.6", "yiisoft/yii2-bootstrap": "~2.0.0", - "yiisoft/yii2-swiftmailer": "~2.0.0" + "yiisoft/yii2-swiftmailer": "~2.0.0", + "bower-asset/remarkable-bootstrap-notify": "*" }, "require-dev": { "yiisoft/yii2-debug": "~2.0.0", diff --git a/frontend/assets/AppAsset.php b/frontend/assets/AppAsset.php index 9a27b92..36a554c 100644 --- a/frontend/assets/AppAsset.php +++ b/frontend/assets/AppAsset.php @@ -22,5 +22,6 @@ class AppAsset extends AssetBundle 'yii\web\JqueryAsset', 'yii\web\YiiAsset', 'yii\bootstrap\BootstrapAsset', + 'yii\bootstrap\BootstrapPluginAsset', ]; } diff --git a/frontend/assets/CabinetAsset.php b/frontend/assets/CabinetAsset.php index e67062b..677a37d 100644 --- a/frontend/assets/CabinetAsset.php +++ b/frontend/assets/CabinetAsset.php @@ -23,5 +23,6 @@ class CabinetAsset extends AssetBundle 'yii\web\YiiAsset', 'yii\bootstrap\BootstrapAsset', 'frontend\assets\AppAsset', + 'frontend\assets\NotifyAsset', ]; } diff --git a/frontend/assets/NotifyAsset.php b/frontend/assets/NotifyAsset.php new file mode 100644 index 0000000..3323e08 --- /dev/null +++ b/frontend/assets/NotifyAsset.php @@ -0,0 +1,20 @@ + [ + 'class' => VerbFilter::className(), + 'actions' => [ + 'personal' => ['post'], + ], + ], ]; } @@ -44,4 +51,55 @@ ]); } + public function actionPersonal() + { + $request = \Yii::$app->request; + $response = \Yii::$app->response; + $response->format = $response::FORMAT_JSON; + /** + * @var User $user + */ + $user = \Yii::$app->user->identity; + if(!$userData = $user->userData) { + $userData = new UserData(); + $userData->user_id = $user->id; + } + if($userData->load($request->post()) && $userData->save()) { + return [ + 'success' => true, + 'message' => 'Данные успешно сохранены', + ]; + } else { + return [ + 'error' => true, + 'message' => 'Ошибка сохранения данных', + ]; + } + } + + public function actionPassport() + { + $request = \Yii::$app->request; + $response = \Yii::$app->response; + $response->format = $response::FORMAT_JSON; + /** + * @var User $user + */ + $user = \Yii::$app->user->identity; + if(!$userPassport = $user->userPassport) { + $userPassport = new UserPassport(); + $userPassport->user_id = $user->id; + } + if($userPassport->load($request->post()) && $userPassport->save()) { + return [ + 'success' => true, + 'message' => 'Данные успешно сохранены', + ]; + } else { + return [ + 'error' => true, + 'message' => 'Ошибка сохранения данных', + ]; + } + } } diff --git a/frontend/models/UserData.php b/frontend/models/UserData.php index 5a1abae..d198070 100644 --- a/frontend/models/UserData.php +++ b/frontend/models/UserData.php @@ -1,67 +1,95 @@ 255, + ], + [ + [ 'user_id' ], + 'exist', + 'skipOnError' => true, + 'targetClass' => User::className(), + 'targetAttribute' => [ 'user_id' => 'id' ], + ], + [ + [ 'phone' ], + 'match', + 'pattern' => '/\+38\s\(\d{3}\)\s\d{3}-\d{2}-\d{2}/', + ], + [ + ['email'], + 'email', + ] + ]; + } + + /** + * @inheritdoc + */ + public function attributeLabels() + { + return [ + 'id' => 'ID', + 'user_id' => 'User ID', + 'name' => 'Ім\'я', + 'surname' => 'Прізвище', + 'patronymic' => 'По батькові', + 'phone' => 'Телефон', + 'email' => 'Email', + 'inn' => 'ІНН', + ]; + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getUser() + { + return $this->hasOne(User::className(), [ 'id' => 'user_id' ]); + } } - - /** - * @inheritdoc - */ - public function rules() - { - return [ - [['user_id'], 'integer'], - [['name', 'surname', 'patronymic', 'phone', 'email', 'inn'], 'string', 'max' => 255], - [['user_id'], 'exist', 'skipOnError' => true, 'targetClass' => User::className(), 'targetAttribute' => ['user_id' => 'id']], - ]; - } - - /** - * @inheritdoc - */ - public function attributeLabels() - { - return [ - 'id' => 'ID', - 'user_id' => 'User ID', - 'name' => 'Name', - 'surname' => 'Surname', - 'patronymic' => 'Patronymic', - 'phone' => 'Phone', - 'email' => 'Email', - 'inn' => 'Inn', - ]; - } - - /** - * @return \yii\db\ActiveQuery - */ - public function getUser() - { - return $this->hasOne(User::className(), ['id' => 'user_id']); - } -} diff --git a/frontend/models/UserPassport.php b/frontend/models/UserPassport.php index f1692cd..730ebe7 100644 --- a/frontend/models/UserPassport.php +++ b/frontend/models/UserPassport.php @@ -47,10 +47,10 @@ class UserPassport extends \yii\db\ActiveRecord return [ 'id' => 'ID', 'user_id' => 'User ID', - 'series' => 'Series', - 'number' => 'Number', - 'birthday' => 'Birthday', - 'given_by' => 'Given By', + 'series' => 'Серія', + 'number' => '№', + 'birthday' => 'Дата народження', + 'given_by' => 'Ким виданий', ]; } diff --git a/frontend/views/cabinet/_passport_form.php b/frontend/views/cabinet/_passport_form.php new file mode 100644 index 0000000..cd537ff --- /dev/null +++ b/frontend/views/cabinet/_passport_form.php @@ -0,0 +1,80 @@ + [ + 'class' => 'pjax_container forms-cabinet forms-2', + ], + ] + ); +?> +
паспортні данні
+ 'passport-form', + 'action' => [ 'cabinet/passport' ], + ] + ); + echo $form->field( + $userPassport, + 'series', + [ + 'options' => [ + 'class' => 'input-wrapp-80', + ], + ] + ) + ->textInput(); + echo $form->field( + $userPassport, + 'number', + [ + 'options' => [ + 'class' => 'input-wrapp-220', + ], + ] + ) + ->textInput(); + echo $form->field( + $userPassport, + 'birthday', + [ + 'options' => [ + 'class' => 'input-wrapp-130', + ], + 'inputOptions' => [ + 'class' => '_datepicer', + ], + ] + ) + ->textInput(); + echo $form->field( + $userPassport, + 'given_by', + [ + 'options' => [ + 'class' => 'input-wrapp-445', + ], + ] + ) + ->textarea(); +?> +
+ +
+ \ No newline at end of file diff --git a/frontend/views/cabinet/_personal_form.php b/frontend/views/cabinet/_personal_form.php new file mode 100644 index 0000000..1270bba --- /dev/null +++ b/frontend/views/cabinet/_personal_form.php @@ -0,0 +1,107 @@ + [ + 'class' => 'pjax_container forms-cabinet forms-1', + ], + ] + ); +?> +
особисті данні
+ 'personal-form', + 'action' => [ 'cabinet/personal' ], + ] + ); + echo $form->field( + $userData, + 'surname', + [ + 'options' => [ + 'class' => 'input-wrapp-320', + ], + ] + ) + ->textInput(); + echo $form->field( + $userData, + 'name', + [ + 'options' => [ + 'class' => 'input-wrapp-320', + ], + ] + ) + ->textInput(); + echo $form->field( + $userData, + 'patronymic', + [ + 'options' => [ + 'class' => 'input-wrapp-320', + ], + ] + ) + ->textInput(); + echo $form->field( + $userData, + 'phone', + [ + 'options' => [ + 'class' => 'input-wrapp-320', + ], + ] + ) + ->widget( + MaskedInput::className(), + [ + 'mask' => '+38 (099) 999-99-99', + 'options' => [ + 'placeholder' => '+38 (0XX) XXX-XX-XX', + ], + ] + ); + echo $form->field( + $userData, + 'email', + [ + 'options' => [ + 'class' => 'input-wrapp-320', + ], + ] + ) + ->textInput(); + echo $form->field( + $userData, + 'inn', + [ + 'options' => [ + 'class' => 'input-wrapp-320', + ], + ] + ) + ->textInput(); + ?> +
+ +
+ + \ No newline at end of file diff --git a/frontend/views/cabinet/index.php b/frontend/views/cabinet/index.php index 70d38d2..5423b19 100644 --- a/frontend/views/cabinet/index.php +++ b/frontend/views/cabinet/index.php @@ -1,8 +1,14 @@ 129, + 'width' => 129, 'height' => 52, ] ), - ['cabinet/index'], + [ 'cabinet/index' ], [ 'class' => 'logo-cab', ] @@ -180,65 +186,20 @@ EOT;
-
-
особисті данні
-
-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
-
- -
-
-
- -
-
паспортні данні
-
-
- - -
-
- - -
-
- - -
-
- - -
-
- -
-
- -
- + render( + '_personal_form', + [ + 'userData' => $userData, + ] + ); + echo $this->render( + '_passport_form', + [ + 'userPassport' => $userPassport, + ] + ); + ?>
Список творів
diff --git a/frontend/web/css/style.css b/frontend/web/css/style.css index b29939b..3c8f675 100644 --- a/frontend/web/css/style.css +++ b/frontend/web/css/style.css @@ -2017,6 +2017,16 @@ ul.btns-box3 li a img {width: 110px;height:110px;} padding-left: 10px; width: 20%; } - - +.pjax_container { + position: relative; +} +.preloader { + position: absolute; + top:0; + left:0; + bottom:0; + right:0; + background: rgba(255, 255, 255, 0.8) url("/images/cabinet/preload_min.gif") 50% 50% no-repeat; + z-index: 100; +} diff --git a/frontend/web/js/script.js b/frontend/web/js/script.js index 8368b61..8cf9e05 100644 --- a/frontend/web/js/script.js +++ b/frontend/web/js/script.js @@ -185,6 +185,42 @@ $(document).ready(function(){ } }) } + + $(document).on('beforeSubmit', '#personal-form', function(e) { + postForm(this); + return false; + }); + + $(document).on('beforeSubmit', '#passport-form', function(e) { + postForm(this); + return false; + }); + + function postForm(context) { + $.post($(context).attr('action'), $(context).serialize(), function(data) { + var type; + if(data.error) { + type = 'danger'; + } else { + type = 'success'; + } + showStatus(data.message, type); + reload($(context).parents('.pjax_container').attr('id')); + }.bind(this)); + } + + function showStatus(txt, type) { + $.notify({ + message: txt + }, { + type: type + }); + } + + function reload(id) { + $('#'+id).prepend('
'); + $.pjax.reload('#'+id); + } }); -- libgit2 0.21.4