From cfd988b7d2fe2fe1c6bb0e9711b2fc3d68695e06 Mon Sep 17 00:00:00 2001 From: Vladimir Fomichev Date: Tue, 28 Oct 2025 16:59:47 +0300 Subject: [PATCH] admin position --- .../controllers/AdminPositionsController.php | 144 ++++++++++++++++++ erp24/views/admin-positions/_form.php | 60 ++++++++ erp24/views/admin-positions/create.php | 20 +++ erp24/views/admin-positions/index.php | 47 ++++++ erp24/views/admin-positions/update.php | 21 +++ erp24/views/admin-positions/view.php | 43 ++++++ 6 files changed, 335 insertions(+) create mode 100644 erp24/controllers/AdminPositionsController.php create mode 100644 erp24/views/admin-positions/_form.php create mode 100644 erp24/views/admin-positions/create.php create mode 100644 erp24/views/admin-positions/index.php create mode 100644 erp24/views/admin-positions/update.php create mode 100644 erp24/views/admin-positions/view.php diff --git a/erp24/controllers/AdminPositionsController.php b/erp24/controllers/AdminPositionsController.php new file mode 100644 index 00000000..a1868f90 --- /dev/null +++ b/erp24/controllers/AdminPositionsController.php @@ -0,0 +1,144 @@ + [ + 'class' => VerbFilter::className(), + 'actions' => [ + 'delete' => ['POST'], + ], + ], + ] + ); + } + + /** + * Lists all AdminPositions models. + * + * @return string + */ + public function actionIndex() + { + $dataProvider = new ActiveDataProvider([ + 'query' => AdminPositions::find(), + /* + 'pagination' => [ + 'pageSize' => 50 + ], + 'sort' => [ + 'defaultOrder' => [ + 'id' => SORT_DESC, + ] + ], + */ + ]); + + return $this->render('index', [ + 'dataProvider' => $dataProvider, + ]); + } + + /** + * Displays a single AdminPositions model. + * @param int $id ID + * @return string + * @throws NotFoundHttpException if the model cannot be found + */ + public function actionView($id) + { + return $this->render('view', [ + 'model' => $this->findModel($id), + ]); + } + + /** + * Creates a new AdminPositions model. + * If creation is successful, the browser will be redirected to the 'view' page. + * @return string|\yii\web\Response + */ + public function actionCreate() + { + $model = new AdminPositions(); + + if ($this->request->isPost) { + if ($model->load($this->request->post()) && $model->save()) { + return $this->redirect(['view', 'id' => $model->id]); + } + } else { + $model->loadDefaultValues(); + } + + return $this->render('create', [ + 'model' => $model, + ]); + } + + /** + * Updates an existing AdminPositions model. + * If update is successful, the browser will be redirected to the 'view' page. + * @param int $id ID + * @return string|\yii\web\Response + * @throws NotFoundHttpException if the model cannot be found + */ + public function actionUpdate($id) + { + $model = $this->findModel($id); + + if ($this->request->isPost && $model->load($this->request->post()) && $model->save()) { + return $this->redirect(['view', 'id' => $model->id]); + } + + return $this->render('update', [ + 'model' => $model, + ]); + } + + /** + * Deletes an existing AdminPositions model. + * If deletion is successful, the browser will be redirected to the 'index' page. + * @param int $id ID + * @return \yii\web\Response + * @throws NotFoundHttpException if the model cannot be found + */ + public function actionDelete($id) + { + $this->findModel($id)->delete(); + + return $this->redirect(['index']); + } + + /** + * Finds the AdminPositions model based on its primary key value. + * If the model is not found, a 404 HTTP exception will be thrown. + * @param int $id ID + * @return AdminPositions the loaded model + * @throws NotFoundHttpException if the model cannot be found + */ + protected function findModel($id) + { + if (($model = AdminPositions::findOne(['id' => $id])) !== null) { + return $model; + } + + throw new NotFoundHttpException('The requested page does not exist.'); + } +} diff --git a/erp24/views/admin-positions/_form.php b/erp24/views/admin-positions/_form.php new file mode 100644 index 00000000..f55150ee --- /dev/null +++ b/erp24/views/admin-positions/_form.php @@ -0,0 +1,60 @@ + + +
+ + + + field($model, 'name')->textInput(['maxlength' => true]) ?> + + field($model, 'alias')->hiddenInput()->label(false) ?> + + field($model, 'salary')->textInput() ?> + +
+ 'btn btn-success']) ?> +
+ + + +
+ +registerJs(" +$(document).ready(function() { + // Функция транслитерации русского текста в латиницу + function transliterate(text) { + var translitMap = { + 'а': 'a', 'б': 'b', 'в': 'v', 'г': 'g', 'д': 'd', 'е': 'e', 'ё': 'e', + 'ж': 'zh', 'з': 'z', 'и': 'i', 'й': 'y', 'к': 'k', 'л': 'l', 'м': 'm', + 'н': 'n', 'о': 'o', 'п': 'p', 'р': 'r', 'с': 's', 'т': 't', 'у': 'u', + 'ф': 'f', 'х': 'kh', 'ц': 'ts', 'ч': 'ch', 'ш': 'sh', 'щ': 'shch', + 'ъ': '', 'ы': 'y', 'ь': '', 'э': 'e', 'ю': 'yu', 'я': 'ya', + 'А': 'A', 'Б': 'B', 'В': 'V', 'Г': 'G', 'Д': 'D', 'Е': 'E', 'Ё': 'E', + 'Ж': 'Zh', 'З': 'Z', 'И': 'I', 'Й': 'Y', 'К': 'K', 'Л': 'L', 'М': 'M', + 'Н': 'N', 'О': 'O', 'П': 'P', 'Р': 'R', 'С': 'S', 'Т': 'T', 'У': 'U', + 'Ф': 'F', 'Х': 'Kh', 'Ц': 'Ts', 'Ч': 'Ch', 'Ш': 'Sh', 'Щ': 'Shch', + 'Ъ': '', 'Ы': 'Y', 'Ь': '', 'Э': 'E', 'Ю': 'Yu', 'Я': 'Ya' + }; + + return text.split('').map(function(char) { + return translitMap[char] || char; + }).join('').replace(/[^a-zA-Z0-9-_]/g, '-').replace(/-+/g, '-').replace(/^-|-$/g, ''); + } + + // Обработчик изменения поля name + $('#adminpositions-name').on('input', function() { + var nameValue = $(this).val(); + var aliasValue = transliterate(nameValue); + $('#adminpositions-alias').val(aliasValue); + }); +}); +"); +?> diff --git a/erp24/views/admin-positions/create.php b/erp24/views/admin-positions/create.php new file mode 100644 index 00000000..1f45d4fa --- /dev/null +++ b/erp24/views/admin-positions/create.php @@ -0,0 +1,20 @@ +title = 'Создание должности сотрудников'; +$this->params['breadcrumbs'][] = ['label' => 'Admin Positions', 'url' => ['index']]; +$this->params['breadcrumbs'][] = $this->title; +?> +
+ +

title) ?>

+ + render('_form', [ + 'model' => $model, + ]) ?> + +
diff --git a/erp24/views/admin-positions/index.php b/erp24/views/admin-positions/index.php new file mode 100644 index 00000000..38ada630 --- /dev/null +++ b/erp24/views/admin-positions/index.php @@ -0,0 +1,47 @@ +title = 'Должности сотрудников'; +$this->params['breadcrumbs'][] = $this->title; +?> +
+ +

title) ?>

+ +

+ 'btn btn-success']) ?> +

+ + + $dataProvider, + 'columns' => [ + ['class' => 'yii\grid\SerialColumn'], + + 'id', + 'name', + 'alias', + 'salary', + 'created_at', + 'created_by', + 'updated_at', + 'updated_by', + [ + 'class' => ActionColumn::class, + 'urlCreator' => function ($action, AdminPositions $model, $key, $index, $column) { + return Url::toRoute([$action, 'id' => $model->id]); + } + ], + ], + ]); ?> + + +
diff --git a/erp24/views/admin-positions/update.php b/erp24/views/admin-positions/update.php new file mode 100644 index 00000000..1321d776 --- /dev/null +++ b/erp24/views/admin-positions/update.php @@ -0,0 +1,21 @@ +title = 'Изменение должности: ' . $model->name; +$this->params['breadcrumbs'][] = ['label' => 'Admin Positions', 'url' => ['index']]; +$this->params['breadcrumbs'][] = ['label' => $model->name, 'url' => ['view', 'id' => $model->id]]; +$this->params['breadcrumbs'][] = 'Update'; +?> +
+ +

title) ?>

+ + render('_form', [ + 'model' => $model, + ]) ?> + +
diff --git a/erp24/views/admin-positions/view.php b/erp24/views/admin-positions/view.php new file mode 100644 index 00000000..7cd6bfd4 --- /dev/null +++ b/erp24/views/admin-positions/view.php @@ -0,0 +1,43 @@ +title = $model->name; +$this->params['breadcrumbs'][] = ['label' => 'Admin Positions', 'url' => ['index']]; +$this->params['breadcrumbs'][] = $this->title; +\yii\web\YiiAsset::register($this); +?> +
+ 'btn btn-primary mb-4']) ?> +

title) ?>

+ +

+ $model->id], ['class' => 'btn btn-primary']) ?> + $model->id], [ + 'class' => 'btn btn-danger', + 'data' => [ + 'confirm' => 'Вы уверены что хотите удалить?', + 'method' => 'post', + ], + ]) ?> +

+ + $model, + 'attributes' => [ + 'id', + 'name', + 'alias', + 'salary', + 'created_at', + 'created_by', + 'updated_at', + 'updated_by', + ], + ]) ?> + +
-- 2.39.5