<?php Yii::app()->clientScript->registerScriptFile(Yii::app()->theme->baseUrl . '/js/bootstrap-inputmask.js'); ?>
<?php Yii::app()->clientScript->registerScriptFile(Yii::app()->theme->baseUrl . '/js/bootstrap-fileupload.js'); ?>
<?php Yii::app()->clientScript->registerScriptFile(Yii::app()->theme->baseUrl . '/lib/chosen/chosen.jquery.min.js'); ?>

<?php
Yii::app()->clientScript->registerScript(
        'chosen', "
            $(document).ready(function(){ 
                $('#Usuario_localidad').chosen({
                    allow_single_deselect: true,
                    no_results_text: 'Localidad no encontrada:'
                });
            });
        ", CClientScript::POS_END);
?>

<?php
Yii::app()->clientScript->registerScript(
        'quitar_fotografia', "
            $(document).ready(function(){
                $(document).find(':file').bind('change', function(event, param) {
                    if (param == 'clear') {
                        $('#quitar_fotografia').val('1');
                    }
                });
            });
        ", CClientScript::POS_END);
?>



<div class="row-fluid">
    <div class="span12">
        <h3 class="heading"><?php echo Yii::t('profind', 'Perfil del agente'); ?></h3>
        <div class="row-fluid">
        <?php
            $form = $this->beginWidget('CActiveForm', array(
                'id' => 'usuario-form',
                'enableAjaxValidation' => false,
                'htmlOptions' => array(
                    'enctype' => 'multipart/form-data',
                    'class' => 'form-horizontal'
                )
            ));
        ?>
            <div class="span8">
                <fieldset>
                    <p>Recoger datos desde la red: 
                        <?php echo CHtml::link('LinkedIn', Yii::app()->createUrl('usuario/modificar', array('id' => $model->id, 'provider' => 'LinkedIn'))); ?>, 
                        <?php echo CHtml::link('Facebook', Yii::app()->createUrl('usuario/modificar', array('id' => $model->id, 'provider' => 'Facebook'))); ?>, 
                        <?php echo CHtml::link('Twitter', Yii::app()->createUrl('usuario/modificar', array('id' => $model->id, 'provider' => 'Twitter'))); ?>.
                    </p>
                    <?php if ($model->hasErrors()) { ?>
                        <div class="alert alert-error">
                            <a data-dismiss="alert" class="close">×</a>
                            <?php
                            echo CHtml::errorSummary($model, '<strong>' . Yii::t('profind', 'Se han encontrado errores') . '</strong>', '', array('firstError' => true));
                            ?>
                        </div>
                    <?php } ?>


                    <div class="control-group formSep">
                        <div class="sepH_b">
                                <?php echo $form->labelEx($model, 'nombre', array('class' => 'control-label')); ?>
                            <div class="controls">
                        <?php echo $form->textField($model, 'nombre', array('class' => 'input-xlarge')); ?>
                            </div>
                        </div>
                            <?php echo $form->labelEx($model, 'apellidos', array('class' => 'control-label')); ?>
                        <div class="controls">
                            <?php echo $form->textField($model, 'apellidos', array('class' => 'input-xlarge')); ?>
                        </div>              
                    </div>
                    <div class="control-group formSep">
                        <?php echo $form->labelEx($model, 'email', array('class' => 'control-label')); ?>
                        <div class="controls">
                            <div class="input-prepend">
                                <span class="add-on"><i class="icon-envelope"></i></span>
                                <?php echo $form->textField($model, 'email', array('class' => 'input-xlarge')); ?>
                            </div>
                        </div>
                    </div>

                    <div class="control-group formSep">
                        <label class='control-label'><?php echo Yii::t('profind', 'Password'); ?></label>
                        <div class="controls text_line">
                            <?php echo CHtml::link(Yii::t('profind', 'Cambiar la password'), $this->createUrl('cambiarPassword', array('id' => Yii::app()->user->id))); ?>
                        </div>
                    </div>

                    <div class="control-group formSep">
                         <?php echo $form->labelEx($model, 'telefono', array('class' => 'control-label')); ?>
                        <div class="controls">
                            <?php echo $form->textField($model, 'telefono', array('class' => 'input-xlarge')); ?>
                        </div>
                    </div>

                    <div class="control-group formSep">
                        <?php echo $form->labelEx($model, 'localidad', array('class' => 'control-label')); ?>
                        <div class="controls">
                            <?php
                            $lista = CHtml::listData(Poblacion::model()->findAll(), 'id', 'poblacion');
                            echo $form->dropDownList(
                                    $model, 'localidad', $lista, array(
                                'empty' => '',
                                'data-placeholder' => Yii::t('profind', 'Elegir la localidad...'),
                                'class' => 'chzn_a input-xlarge',
                            ));
                            ?>
                        </div>                        
                    </div>

                    <div class="control-group formSep">
                        <?php echo $form->labelEx($model, 'titulo', array('class' => 'control-label')); ?>
                        <div class="controls">
                            <?php echo $form->textField($model, 'titulo', array('class' => 'input-xlarge')); ?>
                        </div>
                    </div>                        
                    <div class="control-group">
                        <?php echo $form->labelEx($model, 'descripcion', array('class' => 'control-label')); ?>
                        <div class="controls">
                            <?php echo $form->textArea($model, 'descripcion', array('class' => 'input-xlarge', 'rows' => 7)); ?>
                        </div>
                    </div>
                    <div class="form-actions">
                        <button type="submit" class="btn btn-primary"><?php echo $model->isNewRecord ? Yii::t('profind', 'Crear') : Yii::t('profind', 'Guardar cambios'); ?></button>
                        <button class="btn"><?php echo Yii::t('profind', 'Cancelar'); ?></button>
                    </div>    
                </fieldset>
            </div>            
            <div class="span4">
                <fieldset>
                    <div class="control-group">
                        <?php echo $form->labelEx($model, 'ficheroFotografia', array('class' => '')); ?>
                            <div class="fileupload <?php echo ($model->fotografia->tieneFotografia()) ? 'fileupload-exists' : 'fileupload-new'; ?>" data-provides="fileupload">
                                <div class="fileupload-preview thumbnail" style="width: 150px; height: 150px;">
                                    <?php echo CHtml::image($model->fotografia->getThumbnail()); ?>
                                </div>
                                <div>
                                    <span class="btn btn-file">
                                        <span class="fileupload-new"><?php echo Yii::t('profind', 'Seleccionar imagen'); ?></span>
                                        <span class="fileupload-exists"><?php echo Yii::t('profind', 'Cambiar'); ?></span>
                                        <?php echo $form->fileField($model, 'ficheroFotografia'); ?>
                                        <input type="hidden" id="quitar_fotografia" name="quitar_fotografia" value="0">
                                    </span>
                                    <a href="#" class="btn fileupload-exists" data-dismiss="fileupload"><?php echo Yii::t('profind', 'Quitar'); ?></a>
                                </div>
                            </div>
                    </div>
                </fieldset>
            </div>
            <?php $this->endWidget(); ?>
        </div>
        
    </div>
</div>

