<script type="text/javascript">
    $(function()
    {
        $('.recover_u, .delete_u').live('click', function()
        {
            var msg = $(this).attr('class') == 'recover_u' ? 'Восстановить пользователя?' : 'Удалить пользователя безвозвратно?';

            if (confirm(msg))
            {
                var url = $(this).attr('href');

                $.fn.yiiGridView.update('user-grid',
                    {
                        type:'POST',
                        url:url,
                        success:function(data)
                        {
                            $.fn.yiiGridView.update('user-grid');
                        }
                    });
            }

            return false;
        });
    });
</script>
<?php 
use yii\helpers\Url;
use yii\helpers\ArrayHelper;
use yii\helpers\Html;
use common\components\zii\AdminGrid;
use yii\grid\GridView;

?>
<?php if (\Yii::$app->session->hasFlash('flash')) : ?>
	<div class="message"><span><?php echo Yii::app()->session->getFlash('flash'); ?></span></div>
<?php endif; ?>

<?php
if ($is_deleted)
{
    \Yii::$app->controller->tabs = array(
        "Все пользователи" => Url::toRoute("manage")
    );

    $buttons = [
        'class'    => 'common\components\ColorActionColumn',
		'options' 		  => ['width' => '75'],
        'template' => '{revert}&nbsp;{view}&nbsp;{remove}',
        'buttons'  => [
            'remove'          => function($url, $data) {
                $url      = Url::toRoute(["/users/userAdmin/delete", 'id'=>$data->id, 'ajax'=>'user-grid']);
                $imageUrl = '/img/icons/remove.png';
                $options  = [
                    'title' => 'удалить окончательно',
                    'class' => 'delete_u',
                ];
				return \yii\helpers\Html::a('<span class="glyphicon"><img src="'.$imageUrl.'"></span>', $url, $options);
			},
            'revert'          => function($url, $data) {
                $url = Url::toRoute(["/users/userAdmin/SetDeletedFlag", 'id'=>$data->id, 'is_deleted'=>0]);
                $imageUrl = '/img/icons/revert.png';
                $options  = [
                    'title' => 'Восстановить пользователя',
                    'class' => 'recover_u',
                ];
				return \yii\helpers\Html::a('<span class="glyphicon"><img src="'.$imageUrl.'"></span>', $url, $options);
			}
        ]
    ];
}
else
{
    \Yii::$app->controller->tabs = array(
        "Удаленные пользователи" => Url::toRoute(["manage", "is_deleted" => 1]),
    );

    $buttons = [
        'class'           => 'common\components\ColorActionColumn',
		'options' 		  => ['width' => '75'],
		'template'        => '{sendEmail}&nbsp;{sendNewPassword}<br>{view}&nbsp;{update}&nbsp;{delete}',
        'buttons'         => [
			'sendNewPassword' => function($url, $data) {
				$url = Url::toRoute("/users/userAdmin/sendNewPassword/id/$data->id");
				$imageUrl = '/img/icons/mail.png';
				$title = 'Отправить новый пароль';
				return \yii\helpers\Html::a('<span class="glyphicon"><img src="'.$imageUrl.'"></span>', $url, ['title' => $title]);
			},
			'sendEmail' => function($url, $data) {
                $url = '"mailto:".$data->email';
                $imageUrl = '/img/icons/email.png';
                $title = 'Отправить сообщение на email';
				return \yii\helpers\Html::a('<span class="glyphicon"><img src="'.$imageUrl.'"></span>', $url, ['title' => $title]);
            },
        ]
    ];
}

\yii\widgets\Pjax::begin(['id' => 'demo']); 
echo AdminGrid::widget([
    'id'             => 'user-grid',
    'dataProvider'   => $model->search(Yii::$app->request->queryParams),
    'filterModel'    => $model,
	'class' => 'table table-striped table-bordered nowrap',
    'columns'        => [
		['class'=>'yii\grid\SerialColumn'],
		'name',
		'email',
		'date_create',
		$buttons
    ],
]);

yii\widgets\Pjax::end();
?>

