From dcfb3d5cb38d93c7c15b08aeeb352d060b2c3f17 Mon Sep 17 00:00:00 2001 From: Alex Date: Tue, 27 Dec 2016 17:26:18 +0200 Subject: [PATCH] -Form ajax ready --- frontend/controllers/CabinetController.php | 22 ++++++++++++++++++++++ frontend/models/IntellectualProperty.php | 194 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------------------------------------------------------------- frontend/views/cabinet/index.php | 8 +++++--- frontend/web/js/script.js | 16 ++++++++++++++++ 4 files changed, 155 insertions(+), 85 deletions(-) diff --git a/frontend/controllers/CabinetController.php b/frontend/controllers/CabinetController.php index 85242a5..a306041 100644 --- a/frontend/controllers/CabinetController.php +++ b/frontend/controllers/CabinetController.php @@ -2,6 +2,7 @@ namespace frontend\controllers; use common\models\User; + use frontend\models\IntellectualProperty; use frontend\models\UserData; use frontend\models\UserPassport; use yii\filters\VerbFilter; @@ -103,4 +104,25 @@ ]; } } + + public function actionAddIntProp() + { + $request = \Yii::$app->request; + $response = \Yii::$app->response; + $response->format = $response::FORMAT_JSON; + + $intProperty = new IntellectualProperty(); + + if($intProperty->load($request->post()) && $intProperty->save()) { + return [ + 'success' => true, + 'message' => 'Данные успешно сохранены', + ]; + } else { + return [ + 'error' => true, + 'message' => 'Ошибка сохранения данных', + ]; + } + } } diff --git a/frontend/models/IntellectualProperty.php b/frontend/models/IntellectualProperty.php index 381b6cc..32ff22e 100644 --- a/frontend/models/IntellectualProperty.php +++ b/frontend/models/IntellectualProperty.php @@ -1,87 +1,117 @@ 255, + ], + [ + [ 'user_id' ], + 'exist', + 'skipOnError' => true, + 'targetClass' => User::className(), + 'targetAttribute' => [ 'user_id' => 'id' ], + ], + ]; + } + + /** + * @inheritdoc + */ + public function attributeLabels() + { + return [ + 'id' => 'ID', + 'user_id' => 'User ID', + 'title' => 'Назва', + 'creation_date' => 'Creation Date', + 'code' => 'Code', + 'genre' => 'Жанр', + 'registration_date' => 'Дата реєстрації', + 'contract' => 'Contract', + 'type' => 'Type', + 'author_role' => 'Роль автора', + 'percent' => 'Процент долі автора', + 'calculated' => 'Нараховано', + 'play_count' => 'К-ть відтворень', + ]; + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getCreativeRoles() + { + return $this->hasMany(CreativeRole::className(), [ 'intellectual_property_id' => 'id' ]); + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getUser() + { + return $this->hasOne(User::className(), [ 'id' => 'user_id' ]); + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getReports() + { + return $this->hasMany(Report::className(), [ 'intellectual_property_id' => 'id' ]); + } } - - /** - * @inheritdoc - */ - public function rules() - { - return [ - [['user_id', 'creation_date', 'registration_date'], 'integer'], - [['title', 'code', 'genre', 'contract', 'type'], 'string', 'max' => 255], - [['user_id'], 'exist', 'skipOnError' => true, 'targetClass' => User::className(), 'targetAttribute' => ['user_id' => 'id']], - ]; - } - - /** - * @inheritdoc - */ - public function attributeLabels() - { - return [ - 'id' => 'ID', - 'user_id' => 'User ID', - 'title' => 'Title', - 'creation_date' => 'Creation Date', - 'code' => 'Code', - 'genre' => 'Genre', - 'registration_date' => 'Registration Date', - 'contract' => 'Contract', - 'type' => 'Type', - ]; - } - - /** - * @return \yii\db\ActiveQuery - */ - public function getCreativeRoles() - { - return $this->hasMany(CreativeRole::className(), ['intellectual_property_id' => 'id']); - } - - /** - * @return \yii\db\ActiveQuery - */ - public function getUser() - { - return $this->hasOne(User::className(), ['id' => 'user_id']); - } - - /** - * @return \yii\db\ActiveQuery - */ - public function getReports() - { - return $this->hasMany(Report::className(), ['intellectual_property_id' => 'id']); - } -} diff --git a/frontend/views/cabinet/index.php b/frontend/views/cabinet/index.php index 4f5ab16..7b51444 100644 --- a/frontend/views/cabinet/index.php +++ b/frontend/views/cabinet/index.php @@ -2278,7 +2278,7 @@ EOT; 'som-act', + 'action' => 'add-int-prop', 'id' => 'add-int-prop-form', ] ); @@ -2293,7 +2293,9 @@ EOT; ?> field($addIntProp, 'registration_date'); + echo $form->field($addIntProp, 'registration_date')->textInput([ + 'class' => '_datepicker form-control', + ]); ?> '); $.pjax.reload('#'+id); } + + $(document).on('beforeSubmit', '#add-int-prop-form', function() { + $.post($(this).attr('action'), $(this).serialize(), function(data) { + var type; + if(data.error) { + type = 'danger'; + } else { + type = 'success'; + } + $('#add-composition-modal').modal('hide'); + showStatus(data.message, type); + document.getElementById('add-int-prop-form').reset(); + }); + + return false; + }); }); -- libgit2 0.21.4