155 lines
6.2 KiB
PHP
155 lines
6.2 KiB
PHP
|
<?php
|
|||
|
|
|||
|
use common\helpers\HtmlHelper;
|
|||
|
use yii\helpers\Url;
|
|||
|
use yii\helpers\Html;
|
|||
|
use yii\grid\GridView;
|
|||
|
use yii\widgets\ActiveForm;
|
|||
|
use common\helpers\UserHelper;
|
|||
|
use common\components\user\models\User;
|
|||
|
use common\components\user\models\search\UserSearch;
|
|||
|
|
|||
|
/**
|
|||
|
* @var $this yii\web\View
|
|||
|
* @var $model User
|
|||
|
* @var $dataProvider yii\data\ActiveDataProvider
|
|||
|
* @var $searchModel UserSearch
|
|||
|
*/
|
|||
|
|
|||
|
$this->title = Yii::t('user', 'Пользователи');
|
|||
|
$this->params['breadcrumbs'][] = $this->title;
|
|||
|
|
|||
|
$script = <<< JS
|
|||
|
//Активация/Деактивация пользователя
|
|||
|
$("input[type=checkbox].status").on('change',function () {
|
|||
|
let id = $(this).attr('data-id');
|
|||
|
$.ajax({
|
|||
|
type: "get",
|
|||
|
url: "/user/default/activate",
|
|||
|
data: {
|
|||
|
id: id
|
|||
|
}
|
|||
|
}).done(function(response) {
|
|||
|
if(response.status) {
|
|||
|
$('#alert-error').hide();
|
|||
|
$('#alert-success').html(response.message).fadeIn().delay(300).fadeOut();
|
|||
|
if(response.activate) {
|
|||
|
$('.reset-password-' + id).removeClass('d-none');
|
|||
|
} else {
|
|||
|
$('.reset-password-' + id).addClass('d-none');
|
|||
|
}
|
|||
|
} else {
|
|||
|
$('#alert-success').hide();
|
|||
|
$('#alert-error').html(response.message).fadeIn().delay(300).fadeOut();
|
|||
|
}
|
|||
|
});
|
|||
|
});
|
|||
|
JS;
|
|||
|
|
|||
|
$this->registerJs($script, yii\web\View::POS_END);
|
|||
|
?>
|
|||
|
|
|||
|
<div class="row">
|
|||
|
<div class="col-xs-12">
|
|||
|
<h1><?= Html::encode($this->title) ?></h1>
|
|||
|
<div class="table">
|
|||
|
<?= Html::a(Yii::t('user', 'Добавить пользователя'), Url::to(['create']), ['class' => 'btn btn-outline-primary btn-sm']) ?>
|
|||
|
</div>
|
|||
|
<?php $form = ActiveForm::begin([
|
|||
|
'id' => 'user-form',
|
|||
|
'method' => 'get',
|
|||
|
'action' => '/user',
|
|||
|
]); ?>
|
|||
|
|
|||
|
<div class="row">
|
|||
|
<div class="col-xs-12 col-md-4 col-lg-3">
|
|||
|
<?= $form->field($searchModel, 'role')->dropDownList(UserHelper::roleNameList(), ['prompt' => Yii::t('user', 'Все')]) ?>
|
|||
|
</div>
|
|||
|
<div class="col-xs-12 col-md-4 col-lg-3">
|
|||
|
<?= $form->field($searchModel, 'status')->dropDownList(UserHelper::statusNameList(), ['prompt' => Yii::t('user', 'Все')]) ?>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<br/>
|
|||
|
<div class="row">
|
|||
|
<div class="col-xs-12 col-md-6 col-lg-3">
|
|||
|
<?= Html::submitButton(Yii::t('user', 'Фильтр'), ['class' => 'btn btn-sm btn-success']) ?>
|
|||
|
<?= Html::a(Yii::t('user', 'Сбросить фильтр'), Url::to(['/user']), ['class' => 'btn btn-outline-dark btn-sm']) ?>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<?php ActiveForm::end(); ?>
|
|||
|
<br/>
|
|||
|
<div class="table-responsive">
|
|||
|
<?= GridView::widget([
|
|||
|
'tableOptions' => ['class' => 'table table-striped table-bordered'],
|
|||
|
'dataProvider' => $dataProvider,
|
|||
|
'pager' => [
|
|||
|
'firstPageLabel' => Yii::t('user', 'В начало'),
|
|||
|
'lastPageLabel' => Yii::t('user', 'В конец'),
|
|||
|
],
|
|||
|
'columns' => [
|
|||
|
['class' => yii\grid\SerialColumn::class],
|
|||
|
'email',
|
|||
|
[
|
|||
|
'attribute' => 'role',
|
|||
|
'format' => 'raw',
|
|||
|
'value' => function ($model) {
|
|||
|
if ($model->role) {
|
|||
|
return UserHelper::roleNameList($model->role);
|
|||
|
} else {
|
|||
|
return Yii::t('user', 'Роль не указана');
|
|||
|
}
|
|||
|
},
|
|||
|
],
|
|||
|
[
|
|||
|
'attribute' => 'status',
|
|||
|
'format' => 'raw',
|
|||
|
'value' => function ($model) {
|
|||
|
return UserHelper::statusNameList($model->status);
|
|||
|
},
|
|||
|
],
|
|||
|
[
|
|||
|
'class' => yii\grid\ActionColumn::class,
|
|||
|
'template' => '{reset-password}',
|
|||
|
'buttons' => [
|
|||
|
'reset-password' => function ($url, $model, $key) {
|
|||
|
$hidden = 'd-none';
|
|||
|
if ($model->status == UserHelper::STATUS_ACTIVE) {
|
|||
|
$hidden = '';
|
|||
|
}
|
|||
|
return Html::a(Yii::t('user', 'Сброс пароля'), $url, ['class' => "btn btn-sm btn-outline-secondary reset-password-{$model->id} $hidden", 'data-id' => $model->id]);
|
|||
|
},
|
|||
|
],
|
|||
|
],
|
|||
|
[
|
|||
|
'class' => yii\grid\ActionColumn::class,
|
|||
|
'template' => '{update}',
|
|||
|
'buttons' => [
|
|||
|
'update' => function ($url, $model, $key) {
|
|||
|
|
|||
|
return Html::a(Yii::t('user', '<span class="fa" aria-hidden="true">{icon}</span>', [
|
|||
|
'icon' => HtmlHelper::ICON_UPDATE,
|
|||
|
]), $url);
|
|||
|
},
|
|||
|
],
|
|||
|
],
|
|||
|
[
|
|||
|
'class' => yii\grid\ActionColumn::class,
|
|||
|
'template' => '{ban}',
|
|||
|
'buttons' => [
|
|||
|
'ban' => function ($url, $model, $key) {
|
|||
|
if ($model->status != UserHelper::STATUS_BLOCKED_MANUAL && $model->status != UserHelper::STATUS_BLOCKED_AUTO) {
|
|||
|
return Html::a(Yii::t('user', '<span class="fa" aria-hidden="true">{icon}</span>', [
|
|||
|
'icon' => HtmlHelper::ICON_DELETE,
|
|||
|
]), $url);
|
|||
|
} else {
|
|||
|
return '';
|
|||
|
}
|
|||
|
},
|
|||
|
],
|
|||
|
],
|
|||
|
],
|
|||
|
]); ?>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
</div>
|