Commit e5923f6e3fae6bb3f7e2ab40f2d6d4077f51ae40
Merge remote-tracking branch 'origin/master'
Showing
6 changed files
with
140 additions
and
3 deletions
Show diff stats
frontend/controllers/CabinetController.php
... | ... | @@ -308,6 +308,40 @@ |
308 | 308 | ]; |
309 | 309 | } |
310 | 310 | } |
311 | + | |
312 | + public function actionUpdateRole() | |
313 | + { | |
314 | + $request = \Yii::$app->request; | |
315 | + $response = \Yii::$app->response; | |
316 | + $response->format = $response::FORMAT_JSON; | |
317 | + | |
318 | + $role = CreativeRole::findOne($request->get('id')); | |
319 | + | |
320 | + if ($role->load($request->post()) && $role->save()) { | |
321 | + return [ | |
322 | + 'success' => true, | |
323 | + 'message' => 'Данные успешно сохранены', | |
324 | + ]; | |
325 | + } else { | |
326 | + return [ | |
327 | + 'error' => true, | |
328 | + 'message' => 'Ошибка сохранения данных', | |
329 | + ]; | |
330 | + } | |
331 | + } | |
332 | + | |
333 | + public function actionGetRoleForm() | |
334 | + { | |
335 | + $request = \Yii::$app->request; | |
336 | + $response = \Yii::$app->response; | |
337 | + $response->format = $response::FORMAT_JSON; | |
338 | + | |
339 | + $model = CreativeRole::findOne($request->post('id')); | |
340 | + | |
341 | + return [ | |
342 | + 'answer' => $this->renderPartial('_update_form', ['model' => $model]) | |
343 | + ]; | |
344 | + } | |
311 | 345 | |
312 | 346 | public function actionDeleteRole() |
313 | 347 | { | ... | ... |
1 | +<?php | |
2 | + /** | |
3 | + * @var CreativeRole $model | |
4 | + */ | |
5 | + use frontend\models\CreativeRole; | |
6 | + use yii\helpers\Html; | |
7 | + use yii\widgets\ActiveForm; | |
8 | +?> | |
9 | + | |
10 | +<div class="modal-dialog" role="document"> | |
11 | +<div class="modal-content"> | |
12 | + <div class="modal-header"> | |
13 | + <button type="button" class="close" data-dismiss="modal" aria-label="Close"> | |
14 | + <span aria-hidden="true">×</span></button> | |
15 | + <h4 class="modal-title" id="myModalLabel">Редагувати роль</h4> | |
16 | + </div> | |
17 | + <?php | |
18 | + $form = ActiveForm::begin( | |
19 | + [ | |
20 | + 'action' => 'update-role?id=' . $model->id, | |
21 | + 'id' => 'update-role-form', | |
22 | + ] | |
23 | + ); | |
24 | + | |
25 | + ?> | |
26 | + <div class="modal-body forms-cabinet forms-2"> | |
27 | + | |
28 | + | |
29 | + | |
30 | + <?php | |
31 | + echo $form->field($model, 'title'); | |
32 | + ?> | |
33 | + | |
34 | + <?php | |
35 | + echo $form->field($model, 'name'); | |
36 | + ?> | |
37 | + | |
38 | + <?php | |
39 | + echo $form->field($model, 'part'); | |
40 | + ?> | |
41 | + | |
42 | + <?php | |
43 | + echo $form->field($model, 'code'); | |
44 | + ?> | |
45 | + | |
46 | + <?php | |
47 | + echo $form->field($model, 'iri'); | |
48 | + ?> | |
49 | + | |
50 | + <?php | |
51 | + echo $form->field($model, 'society'); | |
52 | + echo $form->field($model, 'id')->hiddenInput()->label(false); | |
53 | + ?> | |
54 | + | |
55 | + </div> | |
56 | + <div class="clearfix"></div> | |
57 | + <div class="modal-footer btn-submit-blue"> | |
58 | + <?php | |
59 | + echo Html::submitButton( | |
60 | + 'OK' | |
61 | + ); | |
62 | + ?> | |
63 | + </div> | |
64 | + <?php | |
65 | + $form::end(); | |
66 | + ?> | |
67 | +</div> | |
68 | +</div> | ... | ... |
frontend/views/cabinet/index.php
... | ... | @@ -68,7 +68,7 @@ |
68 | 68 | ?> |
69 | 69 | <tr> |
70 | 70 | <td><?= $i; ?></td> |
71 | - <td><?= $row->title ?></td> | |
71 | + <td><?php echo Html::a($row->title, ['sales', 'id' => $row->id])?></td> | |
72 | 72 | <td><?= $row->registration_date ?></td> |
73 | 73 | <td><?= $row->genre ?></td> |
74 | 74 | <td><?= $row->author_role ?></td> | ... | ... |
frontend/views/cabinet/sales.php
... | ... | @@ -179,7 +179,7 @@ |
179 | 179 | <td><?= $row->code ?></td> |
180 | 180 | <td><?= $row->iri ?></td> |
181 | 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> | |
182 | + <td><a href="#" class="edit-table update-role" data-id="<?=$row->id?>"></a><a href="#" class="remove-table delete-role" data-id="<?=$row->id?>"></a> | |
183 | 183 | </td> |
184 | 184 | </tr> |
185 | 185 | <?php |
... | ... | @@ -270,4 +270,10 @@ |
270 | 270 | ?> |
271 | 271 | </div> |
272 | 272 | </div> |
273 | +</div> | |
274 | + | |
275 | + | |
276 | +<!-- Modal Update --> | |
277 | +<div class="modal fade" id="update-role-modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"> | |
278 | + | |
273 | 279 | </div> |
274 | 280 | \ No newline at end of file | ... | ... |
frontend/web/css/cabinet-style.css
... | ... | @@ -748,7 +748,9 @@ 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, #add-role-modal .forms-cabinet { | |
751 | +#add-composition-modal .forms-cabinet, | |
752 | +#add-role-modal .forms-cabinet, | |
753 | +#update-role-modal .forms-cabinet { | |
752 | 754 | width: 100%; |
753 | 755 | margin: 0; |
754 | 756 | max-width: 1000px; | ... | ... |
frontend/web/js/script.js
... | ... | @@ -312,6 +312,23 @@ $(document).ready(function(){ |
312 | 312 | return false; |
313 | 313 | }); |
314 | 314 | |
315 | + $(document).on('submit', '#update-role-form', function() { | |
316 | + $.post($(this).attr('action'), $(this).serialize(), function(data) { | |
317 | + var type; | |
318 | + if(data.error) { | |
319 | + type = 'danger'; | |
320 | + } else { | |
321 | + type = 'success'; | |
322 | + } | |
323 | + $('#update-role-modal').modal('hide'); | |
324 | + showStatus(data.message, type); | |
325 | + $.pjax.reload('#roles-table'); | |
326 | + $('#update-role-modal').html(''); | |
327 | + }); | |
328 | + | |
329 | + return false; | |
330 | + }); | |
331 | + | |
315 | 332 | $(document).on('click', '.delete-role', function(e) { |
316 | 333 | e.preventDefault(); |
317 | 334 | confirm('Удалить роль?'); |
... | ... | @@ -329,6 +346,16 @@ $(document).ready(function(){ |
329 | 346 | }); |
330 | 347 | }); |
331 | 348 | |
349 | + $(document).on('click', '.update-role', function(e) { | |
350 | + e.preventDefault(); | |
351 | + $.post('get-role-form', { | |
352 | + id:$(this).attr('data-id') | |
353 | + }, function(data) { | |
354 | + $('#update-role-modal').html(data.answer); | |
355 | + $('#update-role-modal').modal('show'); | |
356 | + }); | |
357 | + }); | |
358 | + | |
332 | 359 | $(document).on('click', '.remove-int-prop', function(e) { |
333 | 360 | e.preventDefault(); |
334 | 361 | confirm('Удалить элемент?'); | ... | ... |