Skip to content

Commit 35c9670

Browse files
committed
create and update actions via ajax,
install widget yii2-modal-ajax, install fontawesome npm asset, fix init dates on employee report, throw 403 forbidden exception if user trying to access only ajax action, employee report convert dates before validate, search models order by id by default, search models trim attributes, add icons to save buttons, add cancel button to form order, add back button to report pages, register js in main layout to restore sidebar scroll position, mobile support, rebuild layout to not having fixed positions, rename sidenav php files, table forms improve layout to have better look inside ajax modals, do not show ActionColumn in gridView for brigadeWorker role, hide remove button in index.php table files to better support mobile, change css for the main layout
1 parent d828d91 commit 35c9670

File tree

89 files changed

+1132
-535
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+1132
-535
lines changed

assets/AppAsset.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,6 @@ class AppAsset extends AssetBundle
2727
'yii\web\YiiAsset',
2828
'yii\bootstrap4\BootstrapAsset',
2929
'rmrevin\yii\fontawesome\NpmFreeAssetBundle',
30+
'lo\widgets\modal\ModalAjaxAsset',
3031
];
3132
}

composer.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
"kartik-v/yii2-grid": "^3.3",
2121
"kartik-v/yii2-widget-datetimepicker": "^1.4",
2222
"kartik-v/yii2-widget-select2": "^2.1",
23+
"loveorigami/yii2-modal-ajax": "dev-master",
24+
"npm-asset/fortawesome--fontawesome-free": "~5.7.1",
2325
"rmrevin/yii2-fontawesome": "dev-npm-free-asset-fix",
2426
"yiisoft/yii2": "~2.0.14",
2527
"yiisoft/yii2-bootstrap4": "^2.0"
@@ -70,6 +72,10 @@
7072
{
7173
"type": "vcs",
7274
"url": "https://github.com/f1amy/yii2-fontawesome"
75+
},
76+
{
77+
"type": "vcs",
78+
"url": "https://github.com/f1amy/yii2-modal-ajax"
7379
}
7480
]
7581
}

composer.lock

Lines changed: 52 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

controllers/report/EmployeeController.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ public function actionIndex()
3434
$model = new EmployeeReport();
3535

3636
if ($model->load(Yii::$app->request->get()) && $model->validate()) {
37+
$model->start_date = Yii::$app
38+
->formatter->asDate($model->start_date, 'php:d.m.Y');
39+
$model->end_date = Yii::$app
40+
->formatter->asDate($model->end_date, 'php:d.m.Y');
41+
3742
return $this->render('index', [
3843
'model' => $model,
3944
'reportDates' => [

controllers/table/CustomerController.php

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use yii\web\NotFoundHttpException;
1010
use yii\filters\AccessControl;
1111
use yii\filters\VerbFilter;
12+
use yii\web\ForbiddenHttpException;
1213

1314
/**
1415
* CustomerController implements the CRUD actions for Customer model.
@@ -64,13 +65,18 @@ public function actionIndex()
6465
*/
6566
public function actionCreate()
6667
{
68+
if (!Yii::$app->request->isAjax) {
69+
throw new ForbiddenHttpException('Доступ к запрашиваемой странице запрещен.');
70+
}
71+
6772
$model = new Customer();
6873

6974
if ($model->load(Yii::$app->request->post()) && $model->save()) {
70-
return $this->redirect(['index']);
75+
Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
76+
return ['success' => true];
7177
}
7278

73-
return $this->render('create', [
79+
return $this->renderAjax('create', [
7480
'model' => $model,
7581
]);
7682
}
@@ -85,13 +91,18 @@ public function actionCreate()
8591
*/
8692
public function actionUpdate($id)
8793
{
94+
if (!Yii::$app->request->isAjax) {
95+
throw new ForbiddenHttpException('Доступ к запрашиваемой странице запрещен.');
96+
}
97+
8898
$model = $this->findModel($id);
8999

90100
if ($model->load(Yii::$app->request->post()) && $model->save()) {
91-
return $this->redirect(['index']);
101+
Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
102+
return ['success' => true];
92103
}
93104

94-
return $this->render('update', [
105+
return $this->renderAjax('update', [
95106
'model' => $model,
96107
]);
97108
}

controllers/table/EmployeeController.php

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,18 @@ public function actionIndex()
6464
*/
6565
public function actionCreate()
6666
{
67+
if (!Yii::$app->request->isAjax) {
68+
throw new ForbiddenHttpException('Доступ к запрашиваемой странице запрещен.');
69+
}
70+
6771
$model = new Employee();
6872

6973
if ($model->load(Yii::$app->request->post()) && $model->save()) {
70-
return $this->redirect(['index']);
74+
Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
75+
return ['success' => true];
7176
}
7277

73-
return $this->render('create', [
78+
return $this->renderAjax('create', [
7479
'model' => $model,
7580
]);
7681
}
@@ -85,13 +90,18 @@ public function actionCreate()
8590
*/
8691
public function actionUpdate($id)
8792
{
93+
if (!Yii::$app->request->isAjax) {
94+
throw new ForbiddenHttpException('Доступ к запрашиваемой странице запрещен.');
95+
}
96+
8897
$model = $this->findModel($id);
8998

9099
if ($model->load(Yii::$app->request->post()) && $model->save()) {
91-
return $this->redirect(['index']);
100+
Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
101+
return ['success' => true];
92102
}
93103

94-
return $this->render('update', [
104+
return $this->renderAjax('update', [
95105
'model' => $model,
96106
]);
97107
}

controllers/table/EquipmentController.php

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,17 +69,23 @@ public function actionIndex()
6969
*/
7070
public function actionCreate()
7171
{
72+
if (!Yii::$app->request->isAjax) {
73+
throw new ForbiddenHttpException('Доступ к запрашиваемой странице запрещен.');
74+
}
75+
7276
$model = new Equipment();
7377

7478
if ($model->load(Yii::$app->request->post()) && $model->save()) {
7579
$item = $model->item;
7680
$item->quantity -= $model->item_quantity;
7781
$item->save();
7882

79-
return $this->redirect(['index']);
83+
Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
84+
85+
return ['success' => true];
8086
}
8187

82-
return $this->render('create', [
88+
return $this->renderAjax('create', [
8389
'model' => $model,
8490
]);
8591
}
@@ -94,6 +100,10 @@ public function actionCreate()
94100
*/
95101
public function actionUpdate($id)
96102
{
103+
if (!Yii::$app->request->isAjax) {
104+
throw new ForbiddenHttpException('Доступ к запрашиваемой странице запрещен.');
105+
}
106+
97107
$model = $this->findModel($id);
98108

99109
$oldItem = $model->item;
@@ -111,10 +121,11 @@ public function actionUpdate($id)
111121
$newItem->quantity -= $model->item_quantity;
112122
$newItem->save();
113123

114-
return $this->redirect(['index']);
124+
Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
125+
return ['success' => true];
115126
}
116127

117-
return $this->render('update', [
128+
return $this->renderAjax('update', [
118129
'model' => $model,
119130
]);
120131
}
@@ -130,7 +141,7 @@ public function actionUpdate($id)
130141
public function actionDelete($id)
131142
{
132143
$equipment = $this->findModel($id);
133-
144+
134145
$item = $equipment->item;
135146
$item->quantity += $equipment->item_quantity;
136147
$item->save();

controllers/table/ExitToObjectController.php

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,18 @@ public function actionIndex()
6969
*/
7070
public function actionCreate()
7171
{
72+
if (!Yii::$app->request->isAjax) {
73+
throw new ForbiddenHttpException('Доступ к запрашиваемой странице запрещен.');
74+
}
75+
7276
$model = new ExitToObject();
7377

7478
if ($model->load(Yii::$app->request->post()) && $model->save()) {
75-
return $this->redirect(['index']);
79+
Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
80+
return ['success' => true];
7681
}
7782

78-
return $this->render('create', [
83+
return $this->renderAjax('create', [
7984
'model' => $model,
8085
]);
8186
}
@@ -90,16 +95,21 @@ public function actionCreate()
9095
*/
9196
public function actionUpdate($id)
9297
{
98+
if (!Yii::$app->request->isAjax) {
99+
throw new ForbiddenHttpException('Доступ к запрашиваемой странице запрещен.');
100+
}
101+
93102
$model = $this->findModel($id);
94103

95104
$model->brigade_gathering_datetime = \Yii::$app->formatter
96105
->asDate($model->brigade_gathering_datetime, 'php:d.m.Y H:i');
97106

98107
if ($model->load(Yii::$app->request->post()) && $model->save()) {
99-
return $this->redirect(['index']);
108+
Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
109+
return ['success' => true];
100110
}
101111

102-
return $this->render('update', [
112+
return $this->renderAjax('update', [
103113
'model' => $model,
104114
]);
105115
}

controllers/table/ItemController.php

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,18 @@ public function actionIndex()
6464
*/
6565
public function actionCreate()
6666
{
67+
if (!Yii::$app->request->isAjax) {
68+
throw new ForbiddenHttpException('Доступ к запрашиваемой странице запрещен.');
69+
}
70+
6771
$model = new Item();
6872

6973
if ($model->load(Yii::$app->request->post()) && $model->save()) {
70-
return $this->redirect(['index']);
74+
Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
75+
return ['success' => true];
7176
}
7277

73-
return $this->render('create', [
78+
return $this->renderAjax('create', [
7479
'model' => $model,
7580
]);
7681
}
@@ -85,13 +90,18 @@ public function actionCreate()
8590
*/
8691
public function actionUpdate($id)
8792
{
93+
if (!Yii::$app->request->isAjax) {
94+
throw new ForbiddenHttpException('Доступ к запрашиваемой странице запрещен.');
95+
}
96+
8897
$model = $this->findModel($id);
8998

9099
if ($model->load(Yii::$app->request->post()) && $model->save()) {
91-
return $this->redirect(['index']);
100+
Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
101+
return ['success' => true];
92102
}
93103

94-
return $this->render('update', [
104+
return $this->renderAjax('update', [
95105
'model' => $model,
96106
]);
97107
}

0 commit comments

Comments
 (0)