Commit 9e523ea9d5789fb3b9bc1b15a7c20fb6ef478b24

Authored by Alexey Boroda
1 parent aebb725c

-Update ready

frontend/controllers/CabinetController.php
... ... @@ -269,6 +269,40 @@
269 269 ];
270 270 }
271 271 }
  272 +
  273 + public function actionUpdateRole()
  274 + {
  275 + $request = \Yii::$app->request;
  276 + $response = \Yii::$app->response;
  277 + $response->format = $response::FORMAT_JSON;
  278 +
  279 + $role = CreativeRole::findOne($request->get('id'));
  280 +
  281 + if ($role->load($request->post()) && $role->save()) {
  282 + return [
  283 + 'success' => true,
  284 + 'message' => 'Данные успешно сохранены',
  285 + ];
  286 + } else {
  287 + return [
  288 + 'error' => true,
  289 + 'message' => 'Ошибка сохранения данных',
  290 + ];
  291 + }
  292 + }
  293 +
  294 + public function actionGetRoleForm()
  295 + {
  296 + $request = \Yii::$app->request;
  297 + $response = \Yii::$app->response;
  298 + $response->format = $response::FORMAT_JSON;
  299 +
  300 + $model = CreativeRole::findOne($request->post('id'));
  301 +
  302 + return [
  303 + 'answer' => $this->renderPartial('_update_form', ['model' => $model])
  304 + ];
  305 + }
272 306  
273 307 public function actionDeleteRole()
274 308 {
... ...
frontend/views/cabinet/_update_form.php 0 → 100644
  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">&times;</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
... ... @@ -291,6 +291,23 @@ $(document).ready(function(){
291 291 return false;
292 292 });
293 293  
  294 + $(document).on('submit', '#update-role-form', function() {
  295 + $.post($(this).attr('action'), $(this).serialize(), function(data) {
  296 + var type;
  297 + if(data.error) {
  298 + type = 'danger';
  299 + } else {
  300 + type = 'success';
  301 + }
  302 + $('#update-role-modal').modal('hide');
  303 + showStatus(data.message, type);
  304 + $.pjax.reload('#roles-table');
  305 + $('#update-role-modal').html('');
  306 + });
  307 +
  308 + return false;
  309 + });
  310 +
294 311 $(document).on('click', '.delete-role', function(e) {
295 312 e.preventDefault();
296 313 confirm('Удалить роль?');
... ... @@ -308,6 +325,16 @@ $(document).ready(function(){
308 325 });
309 326 });
310 327  
  328 + $(document).on('click', '.update-role', function(e) {
  329 + e.preventDefault();
  330 + $.post('get-role-form', {
  331 + id:$(this).attr('data-id')
  332 + }, function(data) {
  333 + $('#update-role-modal').html(data.answer);
  334 + $('#update-role-modal').modal('show');
  335 + });
  336 + });
  337 +
311 338 $(document).on('click', '.remove-int-prop', function(e) {
312 339 e.preventDefault();
313 340 confirm('Удалить элемент?');
... ...