Commit 43cb22d0cdb79b03556222d41be008fbf46721e4

Authored by Yarik
1 parent 28855799

Property

frontend/controllers/CabinetController.php
... ... @@ -8,7 +8,7 @@
8 8 use yii\filters\VerbFilter;
9 9 use yii\web\Controller;
10 10 use yii\web\NotFoundHttpException;
11   -
  11 +
12 12 /**
13 13 * Cabinet controller
14 14 */
... ... @@ -24,10 +24,10 @@
24 24 {
25 25 return [
26 26 'verbs' => [
27   - 'class' => VerbFilter::className(),
  27 + 'class' => VerbFilter::className(),
28 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 45 * @var User $user
46 46 */
47 47 $user = \Yii::$app->user->identity;
48   - if(!$userData = $user->userData) {
  48 + if (!$userData = $user->userData) {
49 49 $userData = new UserData();
50 50 }
51   - if(!$userPassport = $user->userPassport) {
  51 + if (!$userPassport = $user->userPassport) {
52 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 73 public function actionSales($id = null)
67 74 {
68   - if($id) {
  75 + $newRecord = false;
  76 + if ($id) {
69 77 $property = $this->findProperty($id);
70 78 } else {
71 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 102 public function actionPersonal()
... ... @@ -92,23 +108,23 @@
92 108 * @var User $user
93 109 */
94 110 $user = \Yii::$app->user->identity;
95   - if(!$userData = $user->userData) {
  111 + if (!$userData = $user->userData) {
96 112 $userData = new UserData();
97 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 116 return [
101 117 'success' => true,
102 118 'message' => 'Данные успешно сохранены',
103 119 ];
104 120 } else {
105 121 return [
106   - 'error' => true,
  122 + 'error' => true,
107 123 'message' => 'Ошибка сохранения данных',
108 124 ];
109 125 }
110 126 }
111   -
  127 +
112 128 public function actionPassport()
113 129 {
114 130 $request = \Yii::$app->request;
... ... @@ -118,23 +134,23 @@
118 134 * @var User $user
119 135 */
120 136 $user = \Yii::$app->user->identity;
121   - if(!$userPassport = $user->userPassport) {
  137 + if (!$userPassport = $user->userPassport) {
122 138 $userPassport = new UserPassport();
123 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 142 return [
127 143 'success' => true,
128 144 'message' => 'Данные успешно сохранены',
129 145 ];
130 146 } else {
131 147 return [
132   - 'error' => true,
  148 + 'error' => true,
133 149 'message' => 'Ошибка сохранения данных',
134 150 ];
135 151 }
136 152 }
137   -
  153 +
138 154 public function actionAddIntProp()
139 155 {
140 156 $request = \Yii::$app->request;
... ... @@ -145,14 +161,14 @@
145 161  
146 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 165 return [
150 166 'success' => true,
151 167 'message' => 'Данные успешно сохранены',
152 168 ];
153 169 } else {
154 170 return [
155   - 'error' => true,
  171 + 'error' => true,
156 172 'message' => 'Ошибка сохранения данных',
157 173 ];
158 174 }
... ... @@ -161,7 +177,7 @@
161 177 public function findProperty($id)
162 178 {
163 179 $model = IntellectualProperty::findOne($id);
164   - if(empty($model)) {
  180 + if (empty( $model )) {
165 181 throw new NotFoundHttpException();
166 182 }
167 183 return $model;
... ...
frontend/models/IntellectualProperty.php
... ... @@ -84,10 +84,10 @@
84 84 'registration_date' => 'Дата реєстрації',
85 85 'contract' => 'Договір',
86 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 1 <?php
2 2 use frontend\models\IntellectualProperty;
  3 + use yii\helpers\Html;
3 4 use yii\web\View;
4 5 use yii\widgets\ActiveForm;
5 6 use yii\widgets\Pjax;
... ... @@ -315,7 +316,9 @@
315 316 </div>
316 317  
317 318 <div class="input-wrapp btn-submit-blue">
318   - <button type="submit">зберегти</button>
  319 + <?php
  320 + echo Html::submitButton('зберегти');
  321 + ?>
319 322 </div>
320 323 <?php
321 324 $form::end();
... ...
frontend/web/js/script.js
... ... @@ -152,6 +152,11 @@ $(document).ready(function(){
152 152 return false;
153 153 });
154 154  
  155 + $(document).on('beforeSubmit', '#property-form', function(e) {
  156 + postForm(this);
  157 + return false;
  158 + });
  159 +
155 160 $(document).on('pjax:complete', function() {
156 161 initDatePicker();
157 162 });
... ...