From aebb725cc085c7136f59598dd950ae9dcccc8803 Mon Sep 17 00:00:00 2001 From: Alex Date: Tue, 27 Dec 2016 20:02:07 +0200 Subject: [PATCH] -List ready --- frontend/controllers/CabinetController.php | 97 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------- frontend/views/cabinet/list.php | 226 +++++++++++++++++++++++++++++++++++++++++++++++++--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- frontend/web/js/script.js | 25 +++++++++++++++++++++++++ 3 files changed, 154 insertions(+), 194 deletions(-) diff --git a/frontend/controllers/CabinetController.php b/frontend/controllers/CabinetController.php index c1e8a53..994ef88 100755 --- a/frontend/controllers/CabinetController.php +++ b/frontend/controllers/CabinetController.php @@ -71,7 +71,7 @@ ); } - public function actionSales($id = null) + public function actionSales($id = NULL) { $newRecord = false; if ($id) { @@ -81,8 +81,13 @@ $newRecord = true; } if ($property->load(\Yii::$app->request->post()) && $property->save()) { - if($newRecord) { - return $this->redirect(['cabinet/sales', 'id' => $property->id]); + if ($newRecord) { + return $this->redirect( + [ + 'cabinet/sales', + 'id' => $property->id, + ] + ); } else { $response = \Yii::$app->response; $response->format = $response::FORMAT_JSON; @@ -93,34 +98,50 @@ } } - $table = CreativeRole::find()->where([ - 'intellectual_property_id' => $id - ])->all(); + $table = CreativeRole::find() + ->where( + [ + 'intellectual_property_id' => $id, + ] + ) + ->all(); return $this->render( 'sales', [ 'property' => $property, - 'table' => $table + 'table' => $table, ] ); } public function actionList() { - return $this->render('list'); + $table = IntellectualProperty::find() + ->where( + [ + 'user_id' => \Yii::$app->user->identity->id, + ] + ) + ->all(); + return $this->render( + 'list', + [ + 'table' => $table, + ] + ); } public function actionArrivals() { return $this->render('arrivals'); } - + public function actionNotifications() { return $this->render('notifications'); } - + public function actionUsers() { return $this->render('users'); @@ -201,14 +222,41 @@ } } - public function actionAddRole() + public function actionDeleteIntProperty() { $request = \Yii::$app->request; $response = \Yii::$app->response; $response->format = $response::FORMAT_JSON; - $role = new CreativeRole(); + if (!empty($request->post('id'))) { + $role = IntellectualProperty::findOne($request->post('id')); + if ($role->delete()) { + return [ + 'success' => true, + 'message' => 'Данные успешно удалены', + ]; + } else { + return [ + 'error' => true, + 'message' => 'Ошибка удаления данных', + ]; + } + } else { + return [ + 'error' => true, + 'message' => 'Элемент не найден', + ]; + } + } + public function actionAddRole() + { + $request = \Yii::$app->request; + $response = \Yii::$app->response; + $response->format = $response::FORMAT_JSON; + + $role = new CreativeRole(); + if ($role->load($request->post()) && $role->save()) { return [ 'success' => true, @@ -227,17 +275,32 @@ $request = \Yii::$app->request; $response = \Yii::$app->response; $response->format = $response::FORMAT_JSON; - - return [ - 'message' => 'ok' . $request->post('id'), - ]; + if (!empty($request->post('id'))) { + $role = CreativeRole::findOne($request->post('id')); + if ($role->delete()) { + return [ + 'success' => true, + 'message' => 'Данные успешно удалены', + ]; + } else { + return [ + 'error' => true, + 'message' => 'Ошибка удаления данных', + ]; + } + } else { + return [ + 'error' => true, + 'message' => 'Роль не найдена', + ]; + } } public function findProperty($id) { $model = IntellectualProperty::findOne($id); - if (empty( $model )) { + if (empty($model)) { throw new NotFoundHttpException(); } return $model; diff --git a/frontend/views/cabinet/list.php b/frontend/views/cabinet/list.php index 59f5a97..c133777 100755 --- a/frontend/views/cabinet/list.php +++ b/frontend/views/cabinet/list.php @@ -1,188 +1,60 @@
-
-
Список ОІВ
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
НазваДата створенняШифрЖанрДата реєстраціїДоговірТип
Нью-Йорк03.03.200301P22112016пісня22.11.2016договірмала форма
-
+
+
Список ОІВ
+
+ 'int-property-table', + ]); + ?> + + + + + + + + + + + + + + + + + + + + + + + +
НазваДата створенняШифрЖанрДата реєстраціїДоговірТип
title ?>creation_date ?>code ?>genre ?>registration_date ?>contract ?>type ?>
+
+
diff --git a/frontend/web/js/script.js b/frontend/web/js/script.js index 3730e8e..d1a7571 100755 --- a/frontend/web/js/script.js +++ b/frontend/web/js/script.js @@ -293,10 +293,35 @@ $(document).ready(function(){ $(document).on('click', '.delete-role', function(e) { e.preventDefault(); + confirm('Удалить роль?'); $.post('delete-role', { id:$(this).attr('data-id') }, function(data) { + var type; + if(data.error) { + type = 'danger'; + } else { + type = 'success'; + } + showStatus(data.message, type); + $.pjax.reload('#roles-table'); + }); + }); + $(document).on('click', '.remove-int-prop', function(e) { + e.preventDefault(); + confirm('Удалить элемент?'); + $.post('delete-int-property', { + id:$(this).attr('data-id') + }, function(data) { + var type; + if(data.error) { + type = 'danger'; + } else { + type = 'success'; + } + showStatus(data.message, type); + $.pjax.reload('#int-property-table'); }); }); }); -- libgit2 0.21.4