Commit 0d91ef5d7d048f83df1ac0bf567e1ef0835f8dfa
1 parent
caf85dfb
-Delete action added
Showing
5 changed files
with
192 additions
and
239 deletions
Show diff stats
frontend/controllers/CabinetController.php
| ... | ... | @@ -2,6 +2,7 @@ |
| 2 | 2 | namespace frontend\controllers; |
| 3 | 3 | |
| 4 | 4 | use common\models\User; |
| 5 | + use frontend\models\CreativeRole; | |
| 5 | 6 | use frontend\models\IntellectualProperty; |
| 6 | 7 | use frontend\models\UserData; |
| 7 | 8 | use frontend\models\UserPassport; |
| ... | ... | @@ -91,10 +92,16 @@ |
| 91 | 92 | ]; |
| 92 | 93 | } |
| 93 | 94 | } |
| 95 | + | |
| 96 | + $table = CreativeRole::find()->where([ | |
| 97 | + 'intellectual_property_id' => $id | |
| 98 | + ])->all(); | |
| 99 | + | |
| 94 | 100 | return $this->render( |
| 95 | 101 | 'sales', |
| 96 | 102 | [ |
| 97 | 103 | 'property' => $property, |
| 104 | + 'table' => $table | |
| 98 | 105 | ] |
| 99 | 106 | ); |
| 100 | 107 | } |
| ... | ... | @@ -193,6 +200,39 @@ |
| 193 | 200 | ]; |
| 194 | 201 | } |
| 195 | 202 | } |
| 203 | + | |
| 204 | + public function actionAddRole() | |
| 205 | + { | |
| 206 | + $request = \Yii::$app->request; | |
| 207 | + $response = \Yii::$app->response; | |
| 208 | + $response->format = $response::FORMAT_JSON; | |
| 209 | + | |
| 210 | + $role = new CreativeRole(); | |
| 211 | + | |
| 212 | + if ($role->load($request->post()) && $role->save()) { | |
| 213 | + return [ | |
| 214 | + 'success' => true, | |
| 215 | + 'message' => 'Данные успешно сохранены', | |
| 216 | + ]; | |
| 217 | + } else { | |
| 218 | + return [ | |
| 219 | + 'error' => true, | |
| 220 | + 'message' => 'Ошибка сохранения данных', | |
| 221 | + ]; | |
| 222 | + } | |
| 223 | + } | |
| 224 | + | |
| 225 | + public function actionDeleteRole() | |
| 226 | + { | |
| 227 | + $request = \Yii::$app->request; | |
| 228 | + $response = \Yii::$app->response; | |
| 229 | + $response->format = $response::FORMAT_JSON; | |
| 230 | + | |
| 231 | + return [ | |
| 232 | + 'message' => 'ok' . $request->post('id'), | |
| 233 | + ]; | |
| 234 | + | |
| 235 | + } | |
| 196 | 236 | |
| 197 | 237 | public function findProperty($id) |
| 198 | 238 | { | ... | ... |
frontend/models/CreativeRole.php
| 1 | 1 | <?php |
| 2 | - | |
| 3 | -namespace frontend\models; | |
| 4 | - | |
| 5 | -/** | |
| 6 | - * This is the model class for table "creative_role". | |
| 7 | - * | |
| 8 | - * @property integer $id | |
| 9 | - * @property integer $intellectual_property_id | |
| 10 | - * @property string $title | |
| 11 | - * @property string $name | |
| 12 | - * @property double $part | |
| 13 | - * @property string $code | |
| 14 | - * @property string $iri | |
| 15 | - * @property string $society | |
| 16 | - * | |
| 17 | - * @property IntellectualProperty $intellectualProperty | |
| 18 | - */ | |
| 19 | -class CreativeRole extends \yii\db\ActiveRecord | |
| 20 | -{ | |
| 2 | + | |
| 3 | + namespace frontend\models; | |
| 4 | + | |
| 21 | 5 | /** |
| 22 | - * @inheritdoc | |
| 6 | + * This is the model class for table "creative_role". | |
| 7 | + * | |
| 8 | + * @property integer $id | |
| 9 | + * @property integer $intellectual_property_id | |
| 10 | + * @property string $title | |
| 11 | + * @property string $name | |
| 12 | + * @property double $part | |
| 13 | + * @property string $code | |
| 14 | + * @property string $iri | |
| 15 | + * @property string $society | |
| 16 | + * @property IntellectualProperty $intellectualProperty | |
| 23 | 17 | */ |
| 24 | - public static function tableName() | |
| 18 | + class CreativeRole extends \yii\db\ActiveRecord | |
| 25 | 19 | { |
| 26 | - return 'creative_role'; | |
| 20 | + /** | |
| 21 | + * @inheritdoc | |
| 22 | + */ | |
| 23 | + public static function tableName() | |
| 24 | + { | |
| 25 | + return 'creative_role'; | |
| 26 | + } | |
| 27 | + | |
| 28 | + /** | |
| 29 | + * @inheritdoc | |
| 30 | + */ | |
| 31 | + public function rules() | |
| 32 | + { | |
| 33 | + return [ | |
| 34 | + [ | |
| 35 | + [ 'intellectual_property_id' ], | |
| 36 | + 'integer', | |
| 37 | + ], | |
| 38 | + [ | |
| 39 | + [ 'part' ], | |
| 40 | + 'number', | |
| 41 | + ], | |
| 42 | + [ | |
| 43 | + [ | |
| 44 | + 'title', | |
| 45 | + 'name', | |
| 46 | + 'code', | |
| 47 | + 'iri', | |
| 48 | + 'society', | |
| 49 | + ], | |
| 50 | + 'string', | |
| 51 | + 'max' => 255, | |
| 52 | + ], | |
| 53 | + [ | |
| 54 | + [ 'intellectual_property_id' ], | |
| 55 | + 'exist', | |
| 56 | + 'skipOnError' => true, | |
| 57 | + 'targetClass' => IntellectualProperty::className(), | |
| 58 | + 'targetAttribute' => [ 'intellectual_property_id' => 'id' ], | |
| 59 | + ], | |
| 60 | + ]; | |
| 61 | + } | |
| 62 | + | |
| 63 | + /** | |
| 64 | + * @inheritdoc | |
| 65 | + */ | |
| 66 | + public function attributeLabels() | |
| 67 | + { | |
| 68 | + return [ | |
| 69 | + 'id' => 'ID', | |
| 70 | + 'intellectual_property_id' => 'Intellectual Property ID', | |
| 71 | + 'title' => 'Творча роль', | |
| 72 | + 'name' => 'ПІБ', | |
| 73 | + 'part' => 'Доля %', | |
| 74 | + 'code' => 'Код', | |
| 75 | + 'iri' => 'IPI', | |
| 76 | + 'society' => 'Товариство', | |
| 77 | + ]; | |
| 78 | + } | |
| 79 | + | |
| 80 | + /** | |
| 81 | + * @return \yii\db\ActiveQuery | |
| 82 | + */ | |
| 83 | + public function getIntellectualProperty() | |
| 84 | + { | |
| 85 | + return $this->hasOne(IntellectualProperty::className(), [ 'id' => 'intellectual_property_id' ]); | |
| 86 | + } | |
| 27 | 87 | } |
| 28 | - | |
| 29 | - /** | |
| 30 | - * @inheritdoc | |
| 31 | - */ | |
| 32 | - public function rules() | |
| 33 | - { | |
| 34 | - return [ | |
| 35 | - [['intellectual_property_id'], 'integer'], | |
| 36 | - [['part'], 'number'], | |
| 37 | - [['title', 'name', 'code', 'iri', 'society'], 'string', 'max' => 255], | |
| 38 | - [['intellectual_property_id'], 'exist', 'skipOnError' => true, 'targetClass' => IntellectualProperty::className(), 'targetAttribute' => ['intellectual_property_id' => 'id']], | |
| 39 | - ]; | |
| 40 | - } | |
| 41 | - | |
| 42 | - /** | |
| 43 | - * @inheritdoc | |
| 44 | - */ | |
| 45 | - public function attributeLabels() | |
| 46 | - { | |
| 47 | - return [ | |
| 48 | - 'id' => 'ID', | |
| 49 | - 'intellectual_property_id' => 'Intellectual Property ID', | |
| 50 | - 'title' => 'Title', | |
| 51 | - 'name' => 'Name', | |
| 52 | - 'part' => 'Part', | |
| 53 | - 'code' => 'Code', | |
| 54 | - 'iri' => 'Iri', | |
| 55 | - 'society' => 'Society', | |
| 56 | - ]; | |
| 57 | - } | |
| 58 | - | |
| 59 | - /** | |
| 60 | - * @return \yii\db\ActiveQuery | |
| 61 | - */ | |
| 62 | - public function getIntellectualProperty() | |
| 63 | - { | |
| 64 | - return $this->hasOne(IntellectualProperty::className(), ['id' => 'intellectual_property_id']); | |
| 65 | - } | |
| 66 | -} | ... | ... |
frontend/views/cabinet/sales.php
| 1 | 1 | <?php |
| 2 | + use frontend\models\CreativeRole; | |
| 2 | 3 | use frontend\models\IntellectualProperty; |
| 3 | 4 | use yii\helpers\Html; |
| 4 | 5 | use yii\web\View; |
| ... | ... | @@ -8,6 +9,7 @@ |
| 8 | 9 | /** |
| 9 | 10 | * @var View $this |
| 10 | 11 | * @var IntellectualProperty $property |
| 12 | + * @var CreativeRole[] $table | |
| 11 | 13 | */ |
| 12 | 14 | ?> |
| 13 | 15 | <div class="style cab_content_list"> |
| ... | ... | @@ -139,12 +141,12 @@ |
| 139 | 141 | |
| 140 | 142 | <div class="btn-submit-blue"> |
| 141 | 143 | <?php echo Html::button( |
| 142 | - 'Добавить', | |
| 144 | + 'Додати', | |
| 143 | 145 | [ |
| 144 | 146 | 'type' => 'button', |
| 145 | 147 | 'class' => 'add-role-button', |
| 146 | 148 | 'data-toggle' => 'modal', |
| 147 | - 'data-target' => '#add-composition-modal', | |
| 149 | + 'data-target' => '#add-role-modal', | |
| 148 | 150 | ] |
| 149 | 151 | ) ?> |
| 150 | 152 | </div> |
| ... | ... | @@ -152,6 +154,11 @@ |
| 152 | 154 | <div class="style wrapp-tabs-table"> |
| 153 | 155 | <div class="style table-wrapp-2"> |
| 154 | 156 | <div class="hidden-tables-oiv active-tab-oiv"> |
| 157 | + <?php | |
| 158 | + Pjax::begin([ | |
| 159 | + 'id' => 'roles-table', | |
| 160 | + ]); | |
| 161 | + ?> | |
| 155 | 162 | <table class="table-1 table-2" cellpadding="0" cellspacing="0" border="0"> |
| 156 | 163 | <tr> |
| 157 | 164 | <td>Творча роль</td> |
| ... | ... | @@ -162,167 +169,26 @@ |
| 162 | 169 | <td>Товариство</td> |
| 163 | 170 | <td class="refactor-td"></td> |
| 164 | 171 | </tr> |
| 172 | + <?php | |
| 173 | + foreach ($table as $row) { | |
| 174 | + ?> | |
| 165 | 175 | <tr> |
| 166 | - <td></td> | |
| 167 | - <td></td> | |
| 168 | - <td></td> | |
| 169 | - <td></td> | |
| 170 | - <td></td> | |
| 171 | - <td></td> | |
| 172 | - <td><a href="#" class="edit-table"></a><a href="#" class="remove-table"></a> | |
| 173 | - </td> | |
| 174 | - </tr> | |
| 175 | - <tr> | |
| 176 | - <td></td> | |
| 177 | - <td></td> | |
| 178 | - <td></td> | |
| 179 | - <td></td> | |
| 180 | - <td></td> | |
| 181 | - <td></td> | |
| 182 | - <td><a href="#" class="edit-table"></a><a href="#" class="remove-table"></a> | |
| 183 | - </td> | |
| 184 | - </tr> | |
| 185 | - <tr> | |
| 186 | - <td></td> | |
| 187 | - <td></td> | |
| 188 | - <td></td> | |
| 189 | - <td></td> | |
| 190 | - <td></td> | |
| 191 | - <td></td> | |
| 192 | - <td><a href="#" class="edit-table"></a><a href="#" class="remove-table"></a> | |
| 193 | - </td> | |
| 194 | - </tr> | |
| 195 | - <tr> | |
| 196 | - <td></td> | |
| 197 | - <td></td> | |
| 198 | - <td></td> | |
| 199 | - <td></td> | |
| 200 | - <td></td> | |
| 201 | - <td></td> | |
| 202 | - <td><a href="#" class="edit-table"></a><a href="#" class="remove-table"></a> | |
| 203 | - </td> | |
| 204 | - </tr> | |
| 205 | - <tr> | |
| 206 | - <td></td> | |
| 207 | - <td></td> | |
| 208 | - <td></td> | |
| 209 | - <td></td> | |
| 210 | - <td></td> | |
| 211 | - <td></td> | |
| 212 | - <td><a href="#" class="edit-table"></a><a href="#" class="remove-table"></a> | |
| 213 | - </td> | |
| 214 | - </tr> | |
| 215 | - <tr> | |
| 216 | - <td></td> | |
| 217 | - <td></td> | |
| 218 | - <td></td> | |
| 219 | - <td></td> | |
| 220 | - <td></td> | |
| 221 | - <td></td> | |
| 222 | - <td><a href="#" class="edit-table"></a><a href="#" class="remove-table"></a> | |
| 223 | - </td> | |
| 224 | - </tr> | |
| 225 | - <tr> | |
| 226 | - <td></td> | |
| 227 | - <td></td> | |
| 228 | - <td></td> | |
| 229 | - <td></td> | |
| 230 | - <td></td> | |
| 231 | - <td></td> | |
| 232 | - <td><a href="#" class="edit-table"></a><a href="#" class="remove-table"></a> | |
| 233 | - </td> | |
| 234 | - </tr> | |
| 235 | - <tr> | |
| 236 | - <td></td> | |
| 237 | - <td></td> | |
| 238 | - <td></td> | |
| 239 | - <td></td> | |
| 240 | - <td></td> | |
| 241 | - <td></td> | |
| 242 | - <td><a href="#" class="edit-table"></a><a href="#" class="remove-table"></a> | |
| 243 | - </td> | |
| 244 | - </tr> | |
| 245 | - <tr> | |
| 246 | - <td></td> | |
| 247 | - <td></td> | |
| 248 | - <td></td> | |
| 249 | - <td></td> | |
| 250 | - <td></td> | |
| 251 | - <td></td> | |
| 252 | - <td><a href="#" class="edit-table"></a><a href="#" class="remove-table"></a> | |
| 253 | - </td> | |
| 254 | - </tr> | |
| 255 | - <tr> | |
| 256 | - <td></td> | |
| 257 | - <td></td> | |
| 258 | - <td></td> | |
| 259 | - <td></td> | |
| 260 | - <td></td> | |
| 261 | - <td></td> | |
| 262 | - <td><a href="#" class="edit-table"></a><a href="#" class="remove-table"></a> | |
| 263 | - </td> | |
| 264 | - </tr> | |
| 265 | - <tr> | |
| 266 | - <td></td> | |
| 267 | - <td></td> | |
| 268 | - <td></td> | |
| 269 | - <td></td> | |
| 270 | - <td></td> | |
| 271 | - <td></td> | |
| 272 | - <td><a href="#" class="edit-table"></a><a href="#" class="remove-table"></a> | |
| 273 | - </td> | |
| 274 | - </tr> | |
| 275 | - <tr> | |
| 276 | - <td></td> | |
| 277 | - <td></td> | |
| 278 | - <td></td> | |
| 279 | - <td></td> | |
| 280 | - <td></td> | |
| 281 | - <td></td> | |
| 282 | - <td><a href="#" class="edit-table"></a><a href="#" class="remove-table"></a> | |
| 283 | - </td> | |
| 284 | - </tr> | |
| 285 | - <tr> | |
| 286 | - <td></td> | |
| 287 | - <td></td> | |
| 288 | - <td></td> | |
| 289 | - <td></td> | |
| 290 | - <td></td> | |
| 291 | - <td></td> | |
| 292 | - <td><a href="#" class="edit-table"></a><a href="#" class="remove-table"></a> | |
| 293 | - </td> | |
| 294 | - </tr> | |
| 295 | - <tr> | |
| 296 | - <td></td> | |
| 297 | - <td></td> | |
| 298 | - <td></td> | |
| 299 | - <td></td> | |
| 300 | - <td></td> | |
| 301 | - <td></td> | |
| 302 | - <td><a href="#" class="edit-table"></a><a href="#" class="remove-table"></a> | |
| 303 | - </td> | |
| 304 | - </tr> | |
| 305 | - <tr> | |
| 306 | - <td></td> | |
| 307 | - <td></td> | |
| 308 | - <td></td> | |
| 309 | - <td></td> | |
| 310 | - <td></td> | |
| 311 | - <td></td> | |
| 312 | - <td><a href="#" class="edit-table"></a><a href="#" class="remove-table"></a> | |
| 313 | - </td> | |
| 314 | - </tr> | |
| 315 | - <tr> | |
| 316 | - <td></td> | |
| 317 | - <td></td> | |
| 318 | - <td></td> | |
| 319 | - <td></td> | |
| 320 | - <td></td> | |
| 321 | - <td></td> | |
| 322 | - <td><a href="#" class="edit-table"></a><a href="#" class="remove-table"></a> | |
| 323 | - </td> | |
| 176 | + <td><?= $row->title ?></td> | |
| 177 | + <td><?= $row->name ?></td> | |
| 178 | + <td><?= $row->part ?></td> | |
| 179 | + <td><?= $row->code ?></td> | |
| 180 | + <td><?= $row->iri ?></td> | |
| 181 | + <td><?= $row->society ?></td> | |
| 182 | + <td><a href="#" class="edit-table"></a><a href="#" class="remove-table delete-role" data-id="<?=$row->id?>"></a> | |
| 183 | + </td> | |
| 324 | 184 | </tr> |
| 185 | + <?php | |
| 186 | + } | |
| 187 | + ?> | |
| 325 | 188 | </table> |
| 189 | + <?php | |
| 190 | + Pjax::end(); | |
| 191 | + ?> | |
| 326 | 192 | </div> |
| 327 | 193 | </div> |
| 328 | 194 | </div> |
| ... | ... | @@ -340,55 +206,55 @@ |
| 340 | 206 | </div> |
| 341 | 207 | |
| 342 | 208 | <!-- Modal --> |
| 343 | -<div class="modal fade" id="add-composition-modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"> | |
| 209 | +<div class="modal fade" id="add-role-modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"> | |
| 344 | 210 | <div class="modal-dialog" role="document"> |
| 345 | 211 | <div class="modal-content"> |
| 346 | 212 | <div class="modal-header"> |
| 347 | 213 | <button type="button" class="close" data-dismiss="modal" aria-label="Close"> |
| 348 | 214 | <span aria-hidden="true">×</span></button> |
| 349 | - <h4 class="modal-title" id="myModalLabel">Додати твір</h4> | |
| 215 | + <h4 class="modal-title" id="myModalLabel">Додати роль</h4> | |
| 350 | 216 | </div> |
| 351 | 217 | <?php |
| 352 | 218 | $form = ActiveForm::begin( |
| 353 | 219 | [ |
| 354 | - 'action' => 'add-int-prop', | |
| 355 | - 'id' => 'add-int-prop-form', | |
| 220 | + 'action' => 'add-role', | |
| 221 | + 'id' => 'add-role-form', | |
| 356 | 222 | ] |
| 357 | 223 | ); |
| 358 | - $addIntProp = new IntellectualProperty(); | |
| 224 | + $addRole = new CreativeRole(); | |
| 359 | 225 | ?> |
| 360 | 226 | <div class="modal-body forms-cabinet forms-2"> |
| 361 | 227 | |
| 362 | 228 | |
| 363 | 229 | |
| 364 | 230 | <?php |
| 365 | - echo $form->field($addIntProp, 'title'); | |
| 231 | + echo $form->field($addRole, 'title'); | |
| 366 | 232 | ?> |
| 367 | 233 | |
| 368 | 234 | <?php |
| 369 | - echo $form->field($addIntProp, 'registration_date')->textInput([ | |
| 370 | - 'class' => '_datepicker form-control', | |
| 371 | - ]); | |
| 235 | + echo $form->field($addRole, 'name'); | |
| 372 | 236 | ?> |
| 373 | 237 | |
| 374 | 238 | <?php |
| 375 | - echo $form->field($addIntProp, 'genre'); | |
| 239 | + echo $form->field($addRole, 'part'); | |
| 376 | 240 | ?> |
| 377 | 241 | |
| 378 | 242 | <?php |
| 379 | - echo $form->field($addIntProp, 'author_role'); | |
| 243 | + echo $form->field($addRole, 'code'); | |
| 380 | 244 | ?> |
| 381 | 245 | |
| 382 | 246 | <?php |
| 383 | - echo $form->field($addIntProp, 'percent'); | |
| 247 | + echo $form->field($addRole, 'iri'); | |
| 384 | 248 | ?> |
| 385 | 249 | |
| 386 | 250 | <?php |
| 387 | - echo $form->field($addIntProp, 'calculated'); | |
| 251 | + echo $form->field($addRole, 'society'); | |
| 388 | 252 | ?> |
| 389 | - | |
| 390 | - <?php | |
| 391 | - echo $form->field($addIntProp, 'play_count'); | |
| 253 | + | |
| 254 | + <?php | |
| 255 | + echo $form->field($addRole, 'intellectual_property_id')->hiddenInput([ | |
| 256 | + 'value' => $property->id, | |
| 257 | + ])->label(false); | |
| 392 | 258 | ?> |
| 393 | 259 | |
| 394 | 260 | </div> | ... | ... |
frontend/web/css/cabinet-style.css
| ... | ... | @@ -748,12 +748,12 @@ ul.list-cab li.active-li ul li.active-li-drop span.act_bg { |
| 748 | 748 | |
| 749 | 749 | |
| 750 | 750 | /* Add modal */ |
| 751 | -#add-composition-modal .forms-cabinet { | |
| 751 | +#add-composition-modal .forms-cabinet, #add-role-modal .forms-cabinet { | |
| 752 | 752 | width: 100%; |
| 753 | 753 | margin: 0; |
| 754 | 754 | max-width: 1000px; |
| 755 | 755 | } |
| 756 | -#add-composition-modal .modal-footer { | |
| 756 | +#add-composition-modal .modal-footer, #add-role-modal .modal-footer { | |
| 757 | 757 | border: 0px solid white; |
| 758 | 758 | } |
| 759 | 759 | #myModalLabel { | ... | ... |
frontend/web/js/script.js
| ... | ... | @@ -273,6 +273,32 @@ $(document).ready(function(){ |
| 273 | 273 | |
| 274 | 274 | return false; |
| 275 | 275 | }); |
| 276 | + | |
| 277 | + $(document).on('beforeSubmit', '#add-role-form', function() { | |
| 278 | + $.post($(this).attr('action'), $(this).serialize(), function(data) { | |
| 279 | + var type; | |
| 280 | + if(data.error) { | |
| 281 | + type = 'danger'; | |
| 282 | + } else { | |
| 283 | + type = 'success'; | |
| 284 | + } | |
| 285 | + $('#add-role-modal').modal('hide'); | |
| 286 | + showStatus(data.message, type); | |
| 287 | + $.pjax.reload('#roles-table'); | |
| 288 | + document.getElementById('add-role-form').reset(); | |
| 289 | + }); | |
| 290 | + | |
| 291 | + return false; | |
| 292 | + }); | |
| 293 | + | |
| 294 | + $(document).on('click', '.delete-role', function(e) { | |
| 295 | + e.preventDefault(); | |
| 296 | + $.post('delete-role', { | |
| 297 | + id:$(this).attr('data-id') | |
| 298 | + }, function(data) { | |
| 299 | + | |
| 300 | + }); | |
| 301 | + }); | |
| 276 | 302 | }); |
| 277 | 303 | |
| 278 | 304 | ... | ... |