Commit 43cb22d0cdb79b03556222d41be008fbf46721e4
1 parent
28855799
Property
Showing
4 changed files
with
65 additions
and
41 deletions
Show diff stats
frontend/controllers/CabinetController.php
| @@ -8,7 +8,7 @@ | @@ -8,7 +8,7 @@ | ||
| 8 | use yii\filters\VerbFilter; | 8 | use yii\filters\VerbFilter; |
| 9 | use yii\web\Controller; | 9 | use yii\web\Controller; |
| 10 | use yii\web\NotFoundHttpException; | 10 | use yii\web\NotFoundHttpException; |
| 11 | - | 11 | + |
| 12 | /** | 12 | /** |
| 13 | * Cabinet controller | 13 | * Cabinet controller |
| 14 | */ | 14 | */ |
| @@ -24,10 +24,10 @@ | @@ -24,10 +24,10 @@ | ||
| 24 | { | 24 | { |
| 25 | return [ | 25 | return [ |
| 26 | 'verbs' => [ | 26 | 'verbs' => [ |
| 27 | - 'class' => VerbFilter::className(), | 27 | + 'class' => VerbFilter::className(), |
| 28 | 'actions' => [ | 28 | 'actions' => [ |
| 29 | - 'personal' => ['post'], | ||
| 30 | - 'passport' => ['post'], | 29 | + 'personal' => [ 'post' ], |
| 30 | + 'passport' => [ 'post' ], | ||
| 31 | ], | 31 | ], |
| 32 | ], | 32 | ], |
| 33 | ]; | 33 | ]; |
| @@ -45,42 +45,58 @@ | @@ -45,42 +45,58 @@ | ||
| 45 | * @var User $user | 45 | * @var User $user |
| 46 | */ | 46 | */ |
| 47 | $user = \Yii::$app->user->identity; | 47 | $user = \Yii::$app->user->identity; |
| 48 | - if(!$userData = $user->userData) { | 48 | + if (!$userData = $user->userData) { |
| 49 | $userData = new UserData(); | 49 | $userData = new UserData(); |
| 50 | } | 50 | } |
| 51 | - if(!$userPassport = $user->userPassport) { | 51 | + if (!$userPassport = $user->userPassport) { |
| 52 | $userPassport = new UserPassport(); | 52 | $userPassport = new UserPassport(); |
| 53 | } | 53 | } |
| 54 | 54 | ||
| 55 | - $table = IntellectualProperty::find()->where([ | ||
| 56 | - 'user_id' => \Yii::$app->user->identity->id, | ||
| 57 | - ])->all(); | 55 | + $table = IntellectualProperty::find() |
| 56 | + ->where( | ||
| 57 | + [ | ||
| 58 | + 'user_id' => \Yii::$app->user->identity->id, | ||
| 59 | + ] | ||
| 60 | + ) | ||
| 61 | + ->all(); | ||
| 58 | 62 | ||
| 59 | - return $this->render('index', [ | ||
| 60 | - 'userData' => $userData, | ||
| 61 | - 'userPassport' => $userPassport, | ||
| 62 | - 'table' => $table, | ||
| 63 | - ]); | 63 | + return $this->render( |
| 64 | + 'index', | ||
| 65 | + [ | ||
| 66 | + 'userData' => $userData, | ||
| 67 | + 'userPassport' => $userPassport, | ||
| 68 | + 'table' => $table, | ||
| 69 | + ] | ||
| 70 | + ); | ||
| 64 | } | 71 | } |
| 65 | 72 | ||
| 66 | public function actionSales($id = null) | 73 | public function actionSales($id = null) |
| 67 | { | 74 | { |
| 68 | - if($id) { | 75 | + $newRecord = false; |
| 76 | + if ($id) { | ||
| 69 | $property = $this->findProperty($id); | 77 | $property = $this->findProperty($id); |
| 70 | } else { | 78 | } else { |
| 71 | $property = new IntellectualProperty(); | 79 | $property = new IntellectualProperty(); |
| 80 | + $newRecord = true; | ||
| 72 | } | 81 | } |
| 73 | - if($property->load(\Yii::$app->request->post()) && $property->save()) { | ||
| 74 | - $response = \Yii::$app->response; | ||
| 75 | - $response->format = $response::FORMAT_JSON; | ||
| 76 | - return [ | ||
| 77 | - 'success' => true, | ||
| 78 | - 'message' => 'Данные успешно сохранены', | ||
| 79 | - ]; | 82 | + if ($property->load(\Yii::$app->request->post()) && $property->save()) { |
| 83 | + if($newRecord) { | ||
| 84 | + return $this->redirect(['cabinet/sales', 'id' => $property->id]); | ||
| 85 | + } else { | ||
| 86 | + $response = \Yii::$app->response; | ||
| 87 | + $response->format = $response::FORMAT_JSON; | ||
| 88 | + return [ | ||
| 89 | + 'success' => true, | ||
| 90 | + 'message' => 'Данные успешно сохранены', | ||
| 91 | + ]; | ||
| 92 | + } | ||
| 80 | } | 93 | } |
| 81 | - return $this->render('sales', [ | ||
| 82 | - 'property' => $property, | ||
| 83 | - ]); | 94 | + return $this->render( |
| 95 | + 'sales', | ||
| 96 | + [ | ||
| 97 | + 'property' => $property, | ||
| 98 | + ] | ||
| 99 | + ); | ||
| 84 | } | 100 | } |
| 85 | 101 | ||
| 86 | public function actionPersonal() | 102 | public function actionPersonal() |
| @@ -92,23 +108,23 @@ | @@ -92,23 +108,23 @@ | ||
| 92 | * @var User $user | 108 | * @var User $user |
| 93 | */ | 109 | */ |
| 94 | $user = \Yii::$app->user->identity; | 110 | $user = \Yii::$app->user->identity; |
| 95 | - if(!$userData = $user->userData) { | 111 | + if (!$userData = $user->userData) { |
| 96 | $userData = new UserData(); | 112 | $userData = new UserData(); |
| 97 | $userData->user_id = $user->id; | 113 | $userData->user_id = $user->id; |
| 98 | } | 114 | } |
| 99 | - if($userData->load($request->post()) && $userData->save()) { | 115 | + if ($userData->load($request->post()) && $userData->save()) { |
| 100 | return [ | 116 | return [ |
| 101 | 'success' => true, | 117 | 'success' => true, |
| 102 | 'message' => 'Данные успешно сохранены', | 118 | 'message' => 'Данные успешно сохранены', |
| 103 | ]; | 119 | ]; |
| 104 | } else { | 120 | } else { |
| 105 | return [ | 121 | return [ |
| 106 | - 'error' => true, | 122 | + 'error' => true, |
| 107 | 'message' => 'Ошибка сохранения данных', | 123 | 'message' => 'Ошибка сохранения данных', |
| 108 | ]; | 124 | ]; |
| 109 | } | 125 | } |
| 110 | } | 126 | } |
| 111 | - | 127 | + |
| 112 | public function actionPassport() | 128 | public function actionPassport() |
| 113 | { | 129 | { |
| 114 | $request = \Yii::$app->request; | 130 | $request = \Yii::$app->request; |
| @@ -118,23 +134,23 @@ | @@ -118,23 +134,23 @@ | ||
| 118 | * @var User $user | 134 | * @var User $user |
| 119 | */ | 135 | */ |
| 120 | $user = \Yii::$app->user->identity; | 136 | $user = \Yii::$app->user->identity; |
| 121 | - if(!$userPassport = $user->userPassport) { | 137 | + if (!$userPassport = $user->userPassport) { |
| 122 | $userPassport = new UserPassport(); | 138 | $userPassport = new UserPassport(); |
| 123 | $userPassport->user_id = $user->id; | 139 | $userPassport->user_id = $user->id; |
| 124 | } | 140 | } |
| 125 | - if($userPassport->load($request->post()) && $userPassport->save()) { | 141 | + if ($userPassport->load($request->post()) && $userPassport->save()) { |
| 126 | return [ | 142 | return [ |
| 127 | 'success' => true, | 143 | 'success' => true, |
| 128 | 'message' => 'Данные успешно сохранены', | 144 | 'message' => 'Данные успешно сохранены', |
| 129 | ]; | 145 | ]; |
| 130 | } else { | 146 | } else { |
| 131 | return [ | 147 | return [ |
| 132 | - 'error' => true, | 148 | + 'error' => true, |
| 133 | 'message' => 'Ошибка сохранения данных', | 149 | 'message' => 'Ошибка сохранения данных', |
| 134 | ]; | 150 | ]; |
| 135 | } | 151 | } |
| 136 | } | 152 | } |
| 137 | - | 153 | + |
| 138 | public function actionAddIntProp() | 154 | public function actionAddIntProp() |
| 139 | { | 155 | { |
| 140 | $request = \Yii::$app->request; | 156 | $request = \Yii::$app->request; |
| @@ -145,14 +161,14 @@ | @@ -145,14 +161,14 @@ | ||
| 145 | 161 | ||
| 146 | $intProperty->user_id = \Yii::$app->user->identity->id; | 162 | $intProperty->user_id = \Yii::$app->user->identity->id; |
| 147 | 163 | ||
| 148 | - if($intProperty->load($request->post()) && $intProperty->save()) { | 164 | + if ($intProperty->load($request->post()) && $intProperty->save()) { |
| 149 | return [ | 165 | return [ |
| 150 | 'success' => true, | 166 | 'success' => true, |
| 151 | 'message' => 'Данные успешно сохранены', | 167 | 'message' => 'Данные успешно сохранены', |
| 152 | ]; | 168 | ]; |
| 153 | } else { | 169 | } else { |
| 154 | return [ | 170 | return [ |
| 155 | - 'error' => true, | 171 | + 'error' => true, |
| 156 | 'message' => 'Ошибка сохранения данных', | 172 | 'message' => 'Ошибка сохранения данных', |
| 157 | ]; | 173 | ]; |
| 158 | } | 174 | } |
| @@ -161,7 +177,7 @@ | @@ -161,7 +177,7 @@ | ||
| 161 | public function findProperty($id) | 177 | public function findProperty($id) |
| 162 | { | 178 | { |
| 163 | $model = IntellectualProperty::findOne($id); | 179 | $model = IntellectualProperty::findOne($id); |
| 164 | - if(empty($model)) { | 180 | + if (empty( $model )) { |
| 165 | throw new NotFoundHttpException(); | 181 | throw new NotFoundHttpException(); |
| 166 | } | 182 | } |
| 167 | return $model; | 183 | return $model; |
frontend/models/IntellectualProperty.php
| @@ -84,10 +84,10 @@ | @@ -84,10 +84,10 @@ | ||
| 84 | 'registration_date' => 'Дата реєстрації', | 84 | 'registration_date' => 'Дата реєстрації', |
| 85 | 'contract' => 'Договір', | 85 | 'contract' => 'Договір', |
| 86 | 'type' => 'Тип', | 86 | 'type' => 'Тип', |
| 87 | - 'author_role' => 'Роль автора', | ||
| 88 | - 'percent' => 'Процент долі автора', | ||
| 89 | - 'calculated' => 'Нараховано', | ||
| 90 | - 'play_count' => 'К-ть відтворень', | 87 | + 'author_role' => 'Роль автора', |
| 88 | + 'percent' => 'Процент долі автора', | ||
| 89 | + 'calculated' => 'Нараховано', | ||
| 90 | + 'play_count' => 'К-ть відтворень', | ||
| 91 | ]; | 91 | ]; |
| 92 | } | 92 | } |
| 93 | 93 |
frontend/views/cabinet/sales.php
| 1 | <?php | 1 | <?php |
| 2 | use frontend\models\IntellectualProperty; | 2 | use frontend\models\IntellectualProperty; |
| 3 | + use yii\helpers\Html; | ||
| 3 | use yii\web\View; | 4 | use yii\web\View; |
| 4 | use yii\widgets\ActiveForm; | 5 | use yii\widgets\ActiveForm; |
| 5 | use yii\widgets\Pjax; | 6 | use yii\widgets\Pjax; |
| @@ -315,7 +316,9 @@ | @@ -315,7 +316,9 @@ | ||
| 315 | </div> | 316 | </div> |
| 316 | 317 | ||
| 317 | <div class="input-wrapp btn-submit-blue"> | 318 | <div class="input-wrapp btn-submit-blue"> |
| 318 | - <button type="submit">зберегти</button> | 319 | + <?php |
| 320 | + echo Html::submitButton('зберегти'); | ||
| 321 | + ?> | ||
| 319 | </div> | 322 | </div> |
| 320 | <?php | 323 | <?php |
| 321 | $form::end(); | 324 | $form::end(); |
frontend/web/js/script.js
| @@ -152,6 +152,11 @@ $(document).ready(function(){ | @@ -152,6 +152,11 @@ $(document).ready(function(){ | ||
| 152 | return false; | 152 | return false; |
| 153 | }); | 153 | }); |
| 154 | 154 | ||
| 155 | + $(document).on('beforeSubmit', '#property-form', function(e) { | ||
| 156 | + postForm(this); | ||
| 157 | + return false; | ||
| 158 | + }); | ||
| 159 | + | ||
| 155 | $(document).on('pjax:complete', function() { | 160 | $(document).on('pjax:complete', function() { |
| 156 | initDatePicker(); | 161 | initDatePicker(); |
| 157 | }); | 162 | }); |