<?php
$this->PageTitle = 'RDM';

$botoes = (User::canUpdate()) ? '{view} {pdf} {update}' : '{view}{pdf} ';

if (User::isAdmin()) {
    $botoes .= ' {delete}';
}

$imagem = (User::getUser()->FUN_TBL_RDM == 1 ) ? FaHtml::iconNovo() : FaHtml::iconBlank();

if (User::getUser()->FUN_TBL_RDM != 1) {

    $botoes = str_replace('{update}', '', $botoes);

    $this->menu = array(
        array('label' => FaHtml::iconSetaClose(), 'url' => '#', 'linkOptions' => array('class' => 'search-button')),
        array('label' => FaHtml::iconRefresh(), 'url' => 'javascript:void(0);', 'linkOptions' => array('onclick' => 'reloadFrame();', 'class' => 'refresh-button'))
    );
} else {

    $this->menu = array(
        array('label' => $imagem, 'url' => array('create'), 'linkOptions'=>array('target' => '_blank', 'class' => 'novo')),
        array('label' => FaHtml::iconSetaClose(), 'url' => '#', 'linkOptions' => array('class' => 'search-button')),
        array('label' => FaHtml::iconRefresh(), 'url' => 'javascript:void(0);', 'linkOptions' => array('onclick' => 'reloadFrame();', 'class' => 'refresh-button'))
    );
}
?>

<?php
if (User::getUser()->FUN_TBL_RDM != 1) {
    $model->RDM_IDRESPONSAVEL = User::getId();
}
$dataProvider = $model->search();
?>
<div class="search-form" style="display:<?php echo ($dataProvider->totalItemCount > 0) ? 'none' : 'block'; ?>" >
    <?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',
    'pager' => Util::getPagerDefaultConfig(),
    'columns' => array(
        'RDM_IDRDM',
        'RDM_DATA',
        array(
            'name' => 'RDM_IDREVENDA',
            'value' => 'GxHtml::valueEx($data->Revenda)',
        ),
        array(
            'name' => 'RDM_IDRESPONSAVEL',
            'value' => 'GxHtml::valueEx($data->Responsavel)',
        ),
        array(
            'name' => 'RDM_STATUS',
            'value' => 'Util::getStatusRdm($data->RDM_STATUS)',
        ),
        array(
            'class' => 'CButtonColumn',
            'template' => $botoes,
            'viewButtonOptions' => array('target' => '_blank'),
            'updateButtonOptions' => array('target' => '_blank'),
            'buttons' => array
                (
                'pdf' => array
                    (
                    'label' => 'Gerar PDF',
                    'imageUrl' => FaHtml::getImgUrl('ico-pdf.png'),
                    'url' => 'Yii::app()->createUrl("rdm/gerarpdf", array("id"=>$data->RDM_IDRDM))',
                    'visible' => '$data->RDM_STATUS == "5"',
                ),
                'view' => array
                    (
                    'label' => 'Exibir',
                    'url' => 'Yii::app()->createUrl("rdm/view", array("id"=>$data->RDM_IDRDM))',
                ),
                'update' => array
                    (
                    'label' => 'Editar',
                    'url' => 'Yii::app()->createUrl("rdm/update", array("id"=>$data->RDM_IDRDM))',
                    'visible' => '$data->RDM_STATUS != "5"',
                ),
                'delete' => array
                    (
                    'label' => 'Excluir',
                    'url' => 'Yii::app()->createUrl("rdm/delete", array("id"=>$data->RDM_IDRDM))',
                ),
            ),
        ),
    ),
));