Skip to content

Commit 3f4478a

Browse files
committed
Изменение статусов
1 parent 2157ef2 commit 3f4478a

5 files changed

Lines changed: 87 additions & 2 deletions

File tree

controllers/TodoBackendController.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,19 @@ public function filters()
1717
);
1818
}
1919

20+
public function actions()
21+
{
22+
return [
23+
'inline' => [
24+
'class' => 'yupe\components\actions\YInLineEditAction',
25+
'model' => 'Todo',
26+
'validAttributes' => [
27+
'status',
28+
]
29+
],
30+
];
31+
}
32+
2033
public function actionIndex()
2134
{
2235
$model = new Todo('search');

helpers/TodoStatusHelper.php

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
class TodoStatusHelper
3+
{
4+
const STATUS_CANCELLED = 0;
5+
const STATUS_DEFAULT = 1;
6+
const STATUS_URGENT = 2;
7+
const STATUS_DONE = 3;
8+
9+
/**
10+
* Return a list of statuses
11+
*
12+
* @return array
13+
*/
14+
public static function getList()
15+
{
16+
return [
17+
self::STATUS_CANCELLED => 'Отменена',
18+
self::STATUS_DEFAULT => 'Обычная',
19+
self::STATUS_URGENT => 'Срочная',
20+
self::STATUS_DONE => 'Выполнена',
21+
];
22+
}
23+
24+
/**
25+
* Get css class names list
26+
*
27+
* @return array
28+
*/
29+
public static function getStylesList()
30+
{
31+
return [
32+
self::STATUS_CANCELLED => ['class' => 'label-danger'],
33+
self::STATUS_DEFAULT => ['class' => 'label-default'],
34+
self::STATUS_URGENT => ['class' => 'label-primary'],
35+
self::STATUS_DONE => ['class' => 'label-success'],
36+
];
37+
}
38+
39+
/**
40+
* Get status label by id
41+
*
42+
* @param int $id
43+
* @return string
44+
*/
45+
public static function getLabel($id)
46+
{
47+
$list = self::getList();
48+
49+
return $list[$id];
50+
}
51+
}

install/todo.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,7 @@
33
'module' => [
44
'class' => 'application.modules.todo.TodoModule',
55
],
6+
'import' => [
7+
'application.modules.todo.helpers.*',
8+
],
69
];

views/todoBackend/_form.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,16 @@
1616
<?= $form->errorSummary($model); ?>
1717

1818
<div class="row">
19-
<div class="col-sm-12">
19+
<div class="col-sm-8">
2020
<?= $form->textFieldGroup($model, 'description'); ?>
2121
</div>
22+
<div class="col-sm-4">
23+
<?= $form->dropDownListGroup($model, 'status', [
24+
'widgetOptions' => [
25+
'data' => TodoStatusHelper::getList(),
26+
],
27+
]); ?>
28+
</div>
2229
</div>
2330

2431
<?php $this->widget('bootstrap.widgets.TbButton', [

views/todoBackend/index.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,18 @@
2525
'columns' => [
2626
'id',
2727
'description',
28-
'status',
28+
[
29+
'name' => 'status',
30+
'class' => 'yupe\widgets\EditableStatusColumn',
31+
'url' => $this->createUrl('/todo/todoBackend/inline'),
32+
'source' => TodoStatusHelper::getList(),
33+
'options' => TodoStatusHelper::getStylesList(),
34+
'filter' => CHtml::activeDropDownList($model, 'status', TodoStatusHelper::getList(), [
35+
'encode' => false,
36+
'empty' => '',
37+
'class' => 'form-control',
38+
]),
39+
],
2940
[
3041
'class' => 'yupe\widgets\CustomButtonColumn',
3142
'template' => '{update} {delete}'

0 commit comments

Comments
 (0)