<?php
    $this->PageTitle = 'Interessados';
    $botoes = (User::canUpdate()) ? '{view} {update} {prospecto}' : '{view} {prospecto}';

    if (User::isAdmin()) {
        $botoes .= ' {delete}';
    }
    $options = array();
    $options[] = array('label' =>  FaHtml::iconNovo(),
                       'url' => array('create'),
                       'linkOptions'=>array('target' => '_blank', 'class' => 'novo'));

    //$options[] = array('label' => '<img src="'.FaHtml::getImgUrl('ico-word.png').'" width="18" height="18" alt="Exportar para word"> Exportar', 'url' => array('wordReport', 'token' => $model->TOKEN), 'linkOptions' => array('class' => 'novo'));

    $options[] = array('label' => '<img src="'.FaHtml::getImgUrl('ico-excel.png').'" width="18" height="18" alt="Exportar para excel"> Exportar',
        'url' => array('excelReport'),
        'linkOptions' => array('class' => 'novo exportar'));

    $options[] = array('label' => FaHtml::iconSetaClose(), 'url' => '#', 'linkOptions' => array('class' => 'search-button'));

    $options[] = array('label' => FaHtml::iconRefresh(),
                       'url' => 'javascript:void(0);',
                       'linkOptions' => array('onclick' => 'reloadFrame();',
                                              'class' => 'refresh-button'));

    $this->menu = $options;

    $dataProvider = $model->search();
?>

<div class="search-form" <?php if($dataProvider->totalItemCount > 0) echo 'style="display: none;"'; ?> >
    <?php $this->renderPartial('_search', array('model' => $model)); ?>
</div><!-- search-form -->

<?php
$this->widget('ext.Utils.widgets.CrmGridView', array(
    'id' => 'admin-grid',
    'dataProvider' => $dataProvider,
    'afterAjaxUpdate'=>'updated',
    'selectableRows' => 1,
    'pager' => Util::getPagerDefaultConfig(),
    'columns' => array(
        'INT_CODIGO',
        'INT_DATA',
        'INT_EMPRESA',
        'INT_NOME',
        array(
            'name' => 'Vendedor',
            'value' => 'GxHtml::valueEx($data->Vendedor)',
        ),
        array(
            'name' => 'Cidade',
            'value' => '$data->Cidade->getCidadeEstado()',
        ),
        array(
            'name'  => 'INT_TIPO',
            'value' => '$data->getTipo()',
        ),
        'INT_PROSPECTO_DESDE',
        array(
            'class' => 'CButtonColumn',
            'template' => $botoes,
            'viewButtonOptions' => array('target' => '_blank'),
            'updateButtonOptions' => array('target' => '_blank'),
            'buttons' => array(
                'view' => array(
                    'label' => 'Exibir',
                    'url' => 'Yii::app()->createUrl("interessados/view", array("id"=>$data->INT_CODIGO))',
                    'visible' => '$data->canView()',
                ),
                'update' => array(
                    'label' => 'Editar',
                    'url' => 'Yii::app()->createUrl("interessados/update", array("id"=>$data->INT_CODIGO))',
                    'visible' => '$data->canUpdate()',
                ),
                'delete' => array(
                    'label' => 'Excluir',
                    'url' => 'Yii::app()->createUrl("interessados/delete", array("id"=>$data->INT_CODIGO))',
                    'visible' => '$data->canDelete()',
                ),
                'prospecto' => array(
                    'label' => 'Prospecto',
                    'url' => 'Yii::app()->createUrl("clientes/view", array("id"=>$data->INT_IDPROSPECTO))',
                    'imageUrl' => FaHtml::getImgUrl('ico-prospects.png'),
                    'options' => array('target' => '_blank'),
                    'visible' => '$data->INT_IDPROSPECTO != 0',
                ),
            ),
        ),
    ),
));

$script = <<<JAVASCRIPT
    jQuery(document).ready(function($) {
        setTimeout(function() {
            $("#admin-grid table").css({
                'display': 'block',
                'overflow': 'scroll'
            });
        }, 100);
    });
JAVASCRIPT;
Yii::app()->getClientScript()->registerScript(Util::uid(), $script);