Commit dcfb3d5cb38d93c7c15b08aeeb352d060b2c3f17

Authored by Alexey Boroda
1 parent d840497c

-Form ajax ready

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\IntellectualProperty;
5 6 use frontend\models\UserData;
6 7 use frontend\models\UserPassport;
7 8 use yii\filters\VerbFilter;
... ... @@ -103,4 +104,25 @@
103 104 ];
104 105 }
105 106 }
  107 +
  108 + public function actionAddIntProp()
  109 + {
  110 + $request = \Yii::$app->request;
  111 + $response = \Yii::$app->response;
  112 + $response->format = $response::FORMAT_JSON;
  113 +
  114 + $intProperty = new IntellectualProperty();
  115 +
  116 + if($intProperty->load($request->post()) && $intProperty->save()) {
  117 + return [
  118 + 'success' => true,
  119 + 'message' => 'Данные успешно сохранены',
  120 + ];
  121 + } else {
  122 + return [
  123 + 'error' => true,
  124 + 'message' => 'Ошибка сохранения данных',
  125 + ];
  126 + }
  127 + }
106 128 }
... ...
frontend/models/IntellectualProperty.php
1 1 <?php
2   -
3   -namespace frontend\models;
4   -
5   -use common\models\User;
6   -
7   -/**
8   - * This is the model class for table "intellectual_property".
9   - *
10   - * @property integer $id
11   - * @property integer $user_id
12   - * @property string $title
13   - * @property integer $creation_date
14   - * @property string $code
15   - * @property string $genre
16   - * @property integer $registration_date
17   - * @property string $contract
18   - * @property string $type
19   - *
20   - * @property CreativeRole[] $creativeRoles
21   - * @property User $user
22   - * @property Report[] $reports
23   - */
24   -class IntellectualProperty extends \yii\db\ActiveRecord
25   -{
  2 +
  3 + namespace frontend\models;
  4 +
  5 + use common\models\User;
  6 +
26 7 /**
27   - * @inheritdoc
  8 + * This is the model class for table "intellectual_property".
  9 + *
  10 + * @property integer $id
  11 + * @property integer $user_id
  12 + * @property string $title
  13 + * @property integer $creation_date
  14 + * @property string $code
  15 + * @property string $genre
  16 + * @property integer $registration_date
  17 + * @property string $contract
  18 + * @property string $type
  19 + * @property CreativeRole[] $creativeRoles
  20 + * @property User $user
  21 + * @property Report[] $reports
28 22 */
29   - public static function tableName()
  23 + class IntellectualProperty extends \yii\db\ActiveRecord
30 24 {
31   - return 'intellectual_property';
  25 + /**
  26 + * @inheritdoc
  27 + */
  28 + public static function tableName()
  29 + {
  30 + return 'intellectual_property';
  31 + }
  32 +
  33 + /**
  34 + * @inheritdoc
  35 + */
  36 + public function rules()
  37 + {
  38 + return [
  39 + [
  40 + [
  41 + 'user_id',
  42 + ],
  43 + 'integer',
  44 + ],
  45 + [
  46 + [
  47 + 'creation_date',
  48 + 'registration_date',
  49 + 'title',
  50 + 'code',
  51 + 'genre',
  52 + 'contract',
  53 + 'type',
  54 + 'author_role',
  55 + 'percent',
  56 + 'calculated',
  57 + 'play_count',
  58 + ],
  59 + 'string',
  60 + 'max' => 255,
  61 + ],
  62 + [
  63 + [ 'user_id' ],
  64 + 'exist',
  65 + 'skipOnError' => true,
  66 + 'targetClass' => User::className(),
  67 + 'targetAttribute' => [ 'user_id' => 'id' ],
  68 + ],
  69 + ];
  70 + }
  71 +
  72 + /**
  73 + * @inheritdoc
  74 + */
  75 + public function attributeLabels()
  76 + {
  77 + return [
  78 + 'id' => 'ID',
  79 + 'user_id' => 'User ID',
  80 + 'title' => 'Назва',
  81 + 'creation_date' => 'Creation Date',
  82 + 'code' => 'Code',
  83 + 'genre' => 'Жанр',
  84 + 'registration_date' => 'Дата реєстрації',
  85 + 'contract' => 'Contract',
  86 + 'type' => 'Type',
  87 + 'author_role' => 'Роль автора',
  88 + 'percent' => 'Процент долі автора',
  89 + 'calculated' => 'Нараховано',
  90 + 'play_count' => 'К-ть відтворень',
  91 + ];
  92 + }
  93 +
  94 + /**
  95 + * @return \yii\db\ActiveQuery
  96 + */
  97 + public function getCreativeRoles()
  98 + {
  99 + return $this->hasMany(CreativeRole::className(), [ 'intellectual_property_id' => 'id' ]);
  100 + }
  101 +
  102 + /**
  103 + * @return \yii\db\ActiveQuery
  104 + */
  105 + public function getUser()
  106 + {
  107 + return $this->hasOne(User::className(), [ 'id' => 'user_id' ]);
  108 + }
  109 +
  110 + /**
  111 + * @return \yii\db\ActiveQuery
  112 + */
  113 + public function getReports()
  114 + {
  115 + return $this->hasMany(Report::className(), [ 'intellectual_property_id' => 'id' ]);
  116 + }
32 117 }
33   -
34   - /**
35   - * @inheritdoc
36   - */
37   - public function rules()
38   - {
39   - return [
40   - [['user_id', 'creation_date', 'registration_date'], 'integer'],
41   - [['title', 'code', 'genre', 'contract', 'type'], 'string', 'max' => 255],
42   - [['user_id'], 'exist', 'skipOnError' => true, 'targetClass' => User::className(), 'targetAttribute' => ['user_id' => 'id']],
43   - ];
44   - }
45   -
46   - /**
47   - * @inheritdoc
48   - */
49   - public function attributeLabels()
50   - {
51   - return [
52   - 'id' => 'ID',
53   - 'user_id' => 'User ID',
54   - 'title' => 'Title',
55   - 'creation_date' => 'Creation Date',
56   - 'code' => 'Code',
57   - 'genre' => 'Genre',
58   - 'registration_date' => 'Registration Date',
59   - 'contract' => 'Contract',
60   - 'type' => 'Type',
61   - ];
62   - }
63   -
64   - /**
65   - * @return \yii\db\ActiveQuery
66   - */
67   - public function getCreativeRoles()
68   - {
69   - return $this->hasMany(CreativeRole::className(), ['intellectual_property_id' => 'id']);
70   - }
71   -
72   - /**
73   - * @return \yii\db\ActiveQuery
74   - */
75   - public function getUser()
76   - {
77   - return $this->hasOne(User::className(), ['id' => 'user_id']);
78   - }
79   -
80   - /**
81   - * @return \yii\db\ActiveQuery
82   - */
83   - public function getReports()
84   - {
85   - return $this->hasMany(Report::className(), ['intellectual_property_id' => 'id']);
86   - }
87   -}
... ...
frontend/views/cabinet/index.php
... ... @@ -2278,7 +2278,7 @@ EOT;
2278 2278 <?php
2279 2279 $form = ActiveForm::begin(
2280 2280 [
2281   - 'action' => 'som-act',
  2281 + 'action' => 'add-int-prop',
2282 2282 'id' => 'add-int-prop-form',
2283 2283 ]
2284 2284 );
... ... @@ -2293,7 +2293,9 @@ EOT;
2293 2293 ?>
2294 2294  
2295 2295 <?php
2296   - echo $form->field($addIntProp, 'registration_date');
  2296 + echo $form->field($addIntProp, 'registration_date')->textInput([
  2297 + 'class' => '_datepicker form-control',
  2298 + ]);
2297 2299 ?>
2298 2300  
2299 2301 <?php
... ... @@ -2333,7 +2335,7 @@ EOT;
2333 2335  
2334 2336 <?php
2335 2337 $js = <<<EOT
2336   -$('._datepicer')
  2338 +$('._datepicer, ._datepicker')
2337 2339 .datepicker(
2338 2340 {
2339 2341 changeMonth: true,
... ...
frontend/web/js/script.js
... ... @@ -221,6 +221,22 @@ $(document).ready(function(){
221 221 $('#'+id).prepend('<div class="preloader"></div>');
222 222 $.pjax.reload('#'+id);
223 223 }
  224 +
  225 + $(document).on('beforeSubmit', '#add-int-prop-form', function() {
  226 + $.post($(this).attr('action'), $(this).serialize(), function(data) {
  227 + var type;
  228 + if(data.error) {
  229 + type = 'danger';
  230 + } else {
  231 + type = 'success';
  232 + }
  233 + $('#add-composition-modal').modal('hide');
  234 + showStatus(data.message, type);
  235 + document.getElementById('add-int-prop-form').reset();
  236 + });
  237 +
  238 + return false;
  239 + });
224 240 });
225 241  
226 242  
... ...