<?php
$this->breadcrumbs = array(
        Yii::t('intranet', 'Sistema') => array('sistema/index'),
	Yii::t('intranet', 'Usuarios'),
);

$this->menu = array(
	array(
            'label'=>'<img class="mgright5" alt="' . Yii::t('intranet', 'Nuevo usuario') . '" src="' . Yii::app()->baseUrl . '/images/icons/small/white/user.png"/>' . Yii::t('intranet', 'Nuevo usuario'),
            'url'=>array('create'),
            'linkOptions'=>array('class'=>'iconlink'),
        ),
	array(
            'label'=>'<img class="mgright5" alt="' . Yii::t('intranet', 'Búsqueda avanzada') . '" src="' . Yii::app()->baseUrl . '/images/icons/small/white/search.png"/>' . Yii::t('intranet', 'Búsqueda avanzada'),
            'url'=>array('#'),
            'linkOptions'=>array('class'=>'iconlink search-button'),
        ),    
);

/*$cs=Yii::app()->clientScript;  
$cs->registerScriptFile(Yii::app()->baseUrl . '/js/star-rating/jquery.rating.pack.js', CClientScript::POS_HEAD);  
$cs->registerScriptFile(Yii::app()->baseUrl . '/js/star-rating/jquery.MetaData.js', CClientScript::POS_HEAD);  
$cs->registerCssFile(Yii::app()->baseUrl . '/js/star-rating/jquery.rating.css'); */

$this->pageTitle = Yii::t('intranet', 'Gestión de usuarios');

Yii::app()->clientScript->registerScript('search', "
$('.search-button').click(function(){
	$('.search-form').toggle();
	return false;
});
$('.search-form form').submit(function(){
	$.fn.yiiGridView.update('usuario-grid', {
		data: $(this).serialize()
	});
	return false;
});
");

?>

<div class="search-form" style="display:none">
    <?php $this->renderPartial('_search',array(
            'model'=>$model,
    )); ?>
</div>
<div class="clear"></div>

<div class="dataTables_wrapper">
    <div class="top">
        <div class="dataTables_length">
        <?php 
            $this->widget('application.extensions.PageSize.PageSize', array(
                'mGridId' => 'usuario-grid',
                'mPageSize' => @$_GET['pageSize'],
                'mDefPageSize' => Yii::app()->params['defaultPageSize'],
                'mPageSizeOptions' => Yii::app()->params['pageSizeOptions'],
            ));
        ?>
        </div>
    
        <div class="dataTables_filter">
            <label class="disabled">Buscar: <input type="text" disabled /></label>
        </div>
    </div>
    <?php
        $columns = array(            
            array(
                'header'=>Yii::t('intranet', 'Acciones'),
                'class'=>'CButtonColumn',
                'headerHtmlOptions'=>array(
                    'style' => 'width:55px;',
                    'class' => 'head1', 
                ),
                'template'=>'{update}{delete}',
                'cssClassExpression' => '"con1"',
            ),            
            array(
                'type' => 'html',
                'name' => 'name',
                'value' => 'CHtml::link(CHtml::encode($data->name), array("update", "id"=>$data->id));',
                'headerHtmlOptions'=>array(
                    'class' => 'head0',
                ),
                'cssClassExpression' => '"con0"',
            ),
            array(
                'type' => 'html',
                'name' => 'email',
                'value' => 'CHtml::mailto(CHtml::encode($data->email));',
                'headerHtmlOptions'=>array(
                    'class' => 'head1', 
                ),
                'cssClassExpression' => '"con1"',
            ),        
            array(
                'name' => 'username',
                'headerHtmlOptions'=>array(
                    'class' => 'head0', 
                ),
                'cssClassExpression' => '"con0"',
            ),        
            array(
                'type' => 'raw',
                'name' => 'last_login_time',            
                'value' => '($data->last_login_time === NULL) ? CHtml::tag("span", array("class"=>"nodata"), "Nunca") : Time::timeAgoInWords($data->last_login_time);',
                'headerHtmlOptions'=>array(
                    'class' => 'head1', 
                ),
                'cssClassExpression' => '"con1"',
            ),
        );

        $dataProvider = $model->search();
        $pageSize = Yii::app()->user->getState('pageSize', Yii::app()->params['defaultPageSize']);
        $dataProvider->getPagination()->setPageSize($pageSize);
        
        $this->widget('application.extensions.SelGridView', array(
            'id'=>'usuario-grid',
            'dataProvider'=>$dataProvider,
            'columns'=>$columns,
            'filter'=>$model,
            'filterPosition' => 'footer',
            'cssFile' => Yii::app()->baseUrl . '/css/gridview2.css',
            'itemsCssClass' => 'display',            
            'pagerCssClass' => 'dataTables_paginate',
            'template' => '{items}{summary}{pager}',            
            'emptyText' => Yii::t('intranet', 'No hay usuarios'),
            'summaryCssClass' => 'dataTables_info',
            'summaryText' => 'Mostrando registros del {start} al {end} de {count} en total.',
            'selectableRows' => 1,
            ));
    ?>
</div>    
