Skip to content

Commit 189ca50

Browse files
committed
Создание задач
1 parent f4d2019 commit 189ca50

File tree

4 files changed

+82
-1
lines changed

4 files changed

+82
-1
lines changed

controllers/TodoBackendController.php

+19
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
use yupe\widgets\YFlashMessages;
23
use yupe\components\controllers\BackController;
34

45
/**
@@ -19,4 +20,22 @@ public function actionIndex()
1920

2021
$this->render('index', ['model' => $model]);
2122
}
23+
24+
public function actionCreate()
25+
{
26+
$model = new Todo();
27+
28+
if ($data = Yii::app()->getRequest()->getPost('Todo')) {
29+
30+
$model->setAttributes($data);
31+
32+
if ($model->save()) {
33+
Yii::app()->user->setFlash(YFlashMessages::SUCCESS_MESSAGE, 'Задача успешно добавлена');
34+
35+
$this->redirect((array)Yii::app()->getRequest()->getPost('submit-type', ['create']));
36+
}
37+
}
38+
39+
$this->render('create', ['model' => $model]);
40+
}
2241
}

views/todoBackend/_form.php

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
/**
3+
* @var $model Todo
4+
* @var $form \yupe\widgets\ActiveForm
5+
*/
6+
7+
$form = $this->beginWidget('\yupe\widgets\ActiveForm', [
8+
'id' => 'todo-form',
9+
'enableAjaxValidation' => false,
10+
'enableClientValidation' => true,
11+
'htmlOptions' => ['class' => 'well'],
12+
]);
13+
?>
14+
<div class="alert alert-info">Поля отмеченные <span class="required">*</span> обязательны для заполнения</div>
15+
16+
<?= $form->errorSummary($model); ?>
17+
18+
<div class="row">
19+
<div class="col-sm-12">
20+
<?= $form->textFieldGroup($model, 'description'); ?>
21+
</div>
22+
</div>
23+
24+
<?php $this->widget('bootstrap.widgets.TbButton', [
25+
'buttonType' => 'submit',
26+
'context' => 'primary',
27+
'label' => $model->isNewRecord ? 'Создать задачу и продолжить' : 'Сохранить задачу и продолжить',
28+
]); ?>
29+
30+
<?php $this->widget('bootstrap.widgets.TbButton', [
31+
'buttonType' => 'submit',
32+
'htmlOptions' => ['name' => 'submit-type', 'value' => 'index'],
33+
'label' => $model->isNewRecord ? 'Создать задачу и закрыть' : 'Сохранить задачу и закрыть',
34+
]); ?>
35+
36+
<?php $this->endWidget(); ?>

views/todoBackend/create.php

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
/**
3+
* @var $model Todo
4+
*/
5+
6+
$this->pageTitle = 'ToDo - Создание задачи';
7+
8+
$this->breadcrumbs = [
9+
'Список задач' => ['/todo/todoBackend/index'],
10+
$this->pageTitle
11+
];
12+
13+
$this->menu = [
14+
['icon' => 'fa fa-fw fa-list-alt', 'label' => 'Список задач', 'url' => ['/todo/todoBackend/index']],
15+
['icon' => 'fa fa-fw fa-plus-square', 'label' => 'Создать задачу', 'url' => ['/todo/todoBackend/create']],
16+
];
17+
?>
18+
<div class="page-header">
19+
<h1>Задача <small>создание</small></h1>
20+
</div>
21+
22+
<?= $this->renderPartial('_form', ['model' => $model]); ?>
23+

views/todoBackend/index.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@
88

99
$this->breadcrumbs = [ $this->pageTitle ];
1010

11-
11+
$this->menu = [
12+
['icon' => 'fa fa-fw fa-list-alt', 'label' => 'Список задач', 'url' => ['/todo/todoBackend/index']],
13+
['icon' => 'fa fa-fw fa-plus-square', 'label' => 'Создать задачу', 'url' => ['/todo/todoBackend/create']],
14+
];
1215
?>
1316
<div class="page-header">
1417
<h1><?= $this->pageTitle ?></h1>

0 commit comments

Comments
 (0)