<?php
$this->breadcrumbs=array(
	Yii::t('intranet', 'Candidatos'),
);

$this->menu=array(
    'principal' => array(
	array(
            'label'=>'<img class="mgright5" alt="Nuevo candidato" src="' . Yii::app()->baseUrl . '/images/icons/small/white/user.png"/>Nuevo candidato',
            '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'),
        ),
    ),
);

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

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


$updateJS = CHtml::ajax( array(
  'url' => "js:url",
  'data' => "js:form.serialize()",
  'type' => "post",
  'dataType' => "json",
  'success' => "function( data ) {
    if( data.status == 'failure' ) {
        setTimeout( \"jQuery( '#dlg-updateestado' ).dialog( 'close' );\", 1000 );
    } else {
        if( data.status == 'success' ) // Update all grid views on success
        {
            jQuery( 'div.grid-view' ).each( function() {
                jQuery.fn.yiiGridView.update( jQuery( this ).attr( 'id' ) );
            });
        }
        setTimeout( \"jQuery( '#dlg-updateestado' ).dialog( 'close' );\", 1000 );
        
    }
  }"
));

Yii::app()->clientScript->registerScript( 'updateEstado', "
function updateEstado( url )
{
  var action = '';
  var form = jQuery( '#dlg-updateestado form' );
  
  if(!url) {
    //action = '&action=' + act;
    url = form.attr( 'action' );
  }
  {$updateJS}
}"); 

  
?>

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

<?php
$this->beginWidget('zii.widgets.jui.CJuiDialog', array(
    'id' => 'dlg-updateestado',
    'options' => array(
        'title' => Yii::t('intranet', 'Cambiar de estado'),
        'width' => 400,
        'autoOpen' => false,
        'resizable' => false,
        'modal' => true,
        'closeOnEscape' => true,
        'buttons' => array(
            'Cambiar' => array(
                'text' => Yii::t('intranet', 'Cambiar'),
                'class' => 'ok-button',
                'click' => 'js:function(){updateEstado()}',
            ),
            'Cancelar' => array(
                'text' => Yii::t('intranet', 'Cancelar'),
                'class' => 'cancel-button',
                'click' => 'js:function(){$(this).dialog("close");}',
            ),
        ),
    ),
));
$this->endWidget('zii.widgets.jui.CJuiDialog');
?>


<div class="clear"></div>

<div class="dataTables_wrapper">
    <div class="top">
        <div class="dataTables_length">
        <?php 
            $this->widget('application.extensions.PageSize.PageSize', array(
                'mGridId' => 'candidato-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' => '"con0"',
            ),
            
            array(
                'type' => 'html',
                'name' => 'nombreCompleto_search',
                'value' => 'CHtml::link(CHtml::encode($data->nombreCompleto), array("view", "id"=>$data->id));',
                'headerHtmlOptions'=>array(
                    'class' => 'head0 sorting', 
                ),
                'cssClassExpression' => '"con1"',                
            ),
            
            array(
                'type' => 'html',
                'name' => 'capacidad_tecnica_search',
                'value'=> array($this, 'gridDataColumnCapacidadTecnica'), 
                'header' => 'Capacidad técnica',
                'headerHtmlOptions'=>array(
                    'class' => 'head1 sorting', 
                ),
                'filter' => CHtml::listData(PerfilTecnico::model()->findAll(), 'id', 'descripcion'),
                'cssClassExpression' => '"con0"',
            ),        
            
            array(
                'type'=>'raw',
                'name' => 'nombre_estado_search',
                'headerHtmlOptions'=>array(
                    'class' => 'head0 sorting', 
                ),
                'cssClassExpression' => '"con0"',
                'value'=> 'CHtml::ajaxLink(
                        CHtml::encode($data->estados->descripcion),
                        array("candidato/updateEstado"),
                        array(
                            "data" => array("id" => $data->id),
                            "success" => "function(data){
                                jQuery(\"#dlg-updateestado\").html(data);
                                jQuery(\"#dlg-updateestado\").dialog(\"open\");
                            }",
                        ),
                        array(
                            "id"=>"updateestado-$data->id",
                            "class"=>$data->cssClassEstado,
                        )
                    );',
            ),
            
            array(
                'type' => 'raw',
                'name' => 'fecha_modificacion',
                'value' => '($data->fecha_modificacion === NULL) ? CHtml::tag("span", array("class"=>"nodata"), "Nunca") : Time::timeAgoInWords($data->fecha_modificacion);',
                'headerHtmlOptions'=>array(
                    'class' => 'head1 sorting', 
                ),
                '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'=>'candidato-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 candidatos'),
            'summaryCssClass' => 'dataTables_info',
            'summaryText' => 'Mostrando registros del {start} al {end} de {count} en total.',
            'selectableRows' => 1,
            ));        
    ?>
    

    
    
</div> 
