Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Изменение статусов
  • Loading branch information
sabian committed Jan 16, 2016
1 parent 2157ef2 commit 3f4478a
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 2 deletions.
13 changes: 13 additions & 0 deletions controllers/TodoBackendController.php
Expand Up @@ -17,6 +17,19 @@ public function filters()
);
}

public function actions()
{
return [
'inline' => [
'class' => 'yupe\components\actions\YInLineEditAction',
'model' => 'Todo',
'validAttributes' => [
'status',
]
],
];
}

public function actionIndex()
{
$model = new Todo('search');
Expand Down
51 changes: 51 additions & 0 deletions helpers/TodoStatusHelper.php
@@ -0,0 +1,51 @@
<?php
class TodoStatusHelper
{
const STATUS_CANCELLED = 0;
const STATUS_DEFAULT = 1;
const STATUS_URGENT = 2;
const STATUS_DONE = 3;

/**
* Return a list of statuses
*
* @return array
*/
public static function getList()
{
return [
self::STATUS_CANCELLED => 'Отменена',
self::STATUS_DEFAULT => 'Обычная',
self::STATUS_URGENT => 'Срочная',
self::STATUS_DONE => 'Выполнена',
];
}

/**
* Get css class names list
*
* @return array
*/
public static function getStylesList()
{
return [
self::STATUS_CANCELLED => ['class' => 'label-danger'],
self::STATUS_DEFAULT => ['class' => 'label-default'],
self::STATUS_URGENT => ['class' => 'label-primary'],
self::STATUS_DONE => ['class' => 'label-success'],
];
}

/**
* Get status label by id
*
* @param int $id
* @return string
*/
public static function getLabel($id)
{
$list = self::getList();

return $list[$id];
}
}
3 changes: 3 additions & 0 deletions install/todo.php
Expand Up @@ -3,4 +3,7 @@
'module' => [
'class' => 'application.modules.todo.TodoModule',
],
'import' => [
'application.modules.todo.helpers.*',
],
];
9 changes: 8 additions & 1 deletion views/todoBackend/_form.php
Expand Up @@ -16,9 +16,16 @@
<?= $form->errorSummary($model); ?>

<div class="row">
<div class="col-sm-12">
<div class="col-sm-8">
<?= $form->textFieldGroup($model, 'description'); ?>
</div>
<div class="col-sm-4">
<?= $form->dropDownListGroup($model, 'status', [
'widgetOptions' => [
'data' => TodoStatusHelper::getList(),
],
]); ?>
</div>
</div>

<?php $this->widget('bootstrap.widgets.TbButton', [
Expand Down
13 changes: 12 additions & 1 deletion views/todoBackend/index.php
Expand Up @@ -25,7 +25,18 @@
'columns' => [
'id',
'description',
'status',
[
'name' => 'status',
'class' => 'yupe\widgets\EditableStatusColumn',
'url' => $this->createUrl('/todo/todoBackend/inline'),
'source' => TodoStatusHelper::getList(),
'options' => TodoStatusHelper::getStylesList(),
'filter' => CHtml::activeDropDownList($model, 'status', TodoStatusHelper::getList(), [
'encode' => false,
'empty' => '',
'class' => 'form-control',
]),
],
[
'class' => 'yupe\widgets\CustomButtonColumn',
'template' => '{update} {delete}'
Expand Down

0 comments on commit 3f4478a

Please sign in to comment.