<?php
    User::blockNotWorking();

    $this->PageTitle = false;

    $nomeCliente  = Util::getNomeImplantacao($model->Cliente->CLI_NOME, $model->Cliente->CLI_IMPLANTACAO);
    $nomeCliente .= Util::getPendencias($model->Cliente, true);

    $this->renderPartial('_menu', array('model' => $model));
?>
<div id="div-vincular-cliente">
    <h1>Solicitações de Transferência &raquo; <?= $nomeCliente; ?> &raquo; Vincular Prospecto / Cliente</h1>
    <div class="form">
        <div class="portlet" id="yw2">
            <div class="portlet-content">
                <ul id="yw3">
                    <li>
                        <a class="search-button" href="#" id="abrir-formulario">
                            <span class="text">Abrir Formulário</span> <?php echo FaHtml::iconSetaClose(false); ?>
                        </a>
                    </li>
                </ul>
            </div>
        </div>
        <div class="search-form" style="display:block">
            <?php
                $this->renderPartial('_search_clientes', array(
                    'model' => $model,
                    'modelClientes' => $modelClientes,
                ));
            ?>
        </div><!-- search-form -->
    </div><!-- form -->
    <?php
        if ($dataProvider) {
            $this->widget('ext.Utils.widgets.CrmGridView', array(
                'id'              => 'clientes-grid',
                'dataProvider'    => $dataProvider,
                'selectableRows'  => 1,
                'afterAjaxUpdate' => 'updated',
                'columns'         => array(
                    'CLI_NOME',
                    array(
                        'name'  => 'CLI_CNPJCPF',
                        'value' => '!empty($data->CLI_CNPJCPF)?Util::formataCNPJCPF($data->CLI_CNPJCPF):"Não informado"'
                    ),
                    'CLI_FONE1',
                    array(
                        'name'  => 'CLI_CIDADE',
                        'value' => 'GxHtml::valueEx($data->Cidade)',
                    ),
                    array(
                        'name'  => 'CLI_SITUACAO',
                        'value' => 'Util::getStatusCliente($data->CLI_SITUACAO)',
                    ),
                    array(
                        'class'               => 'CButtonColumn',
                        'template'            => '{vincular}',
                        'viewButtonOptions'   => array('target'   => '_blank'),
                        'updateButtonOptions' => array('target' => '_blank'),
                        'buttons'             => array(
                            'vincular' => array(
                                'label' => 'Vincular',
                                'url'   => '
                                    Yii::app()->createUrl("clientesTransferencias/link", array(
                                        "id" => ' . $model->CLT_IDTRANSFERENCIA . ',
                                        "cliente" => $data->CLI_IDCLIENTE
                                    ))
                                ',
                            ),
                        ),
                    ),
                ),
            ));
        }
    ?>
</div>

<?php
$this->renderPartial('_view', array('model' => $model));

$cs = Yii::app()->getClientScript();

$css = <<<CSS
    .search-form {
        margin-top: 0px;
    }
    .toggle_atd {
        display: none;
    }
    .toggle_atendimentos {
        float: right;
        position: relative;
    }
    .toggle_atendimentos i {
        font-size: 14px;
        margin-left: 5px;
        top: -2px;
        height: 14px;
        position: relative;
    }
    th {
        background: #d4e6ea!important;
    }
    #infos {
        float: left;
        width: 100%;
    }
CSS;
$cs->registerCss(Util::uid(), $css);

$FaHtml = new FaHtml;
$script = <<<JAVASCRIPT
    $('#abrir-formulario').click( function() {
        if($('.text').html() == 'Abrir Formulário') {
            $(this).html('<span class="text">Fechar Formulário</span> {$FaHtml->iconSetaOpen(false)}</a>');
        } else {
            $(this).html('<span class="text">Abrir Formulário</span> {$FaHtml->iconSetaClose(false)}</a>');
        }
        $('.search-form').slideToggle('fast');
    });
    $('.toggle_atendimentos').click(function() {
        $('.'+$(this).data('toggle')).toggle();
        event.preventDefault();
        return false;
    });
JAVASCRIPT;
$cs->registerScript(Util::uid(), $script);
