<?php
$js_datepicker = <<<JS
    jQuery(function($) {
        jQuery('.datepicker').datepicker(
            jQuery.extend({showMonthAfterYear:false}, 
            jQuery.datepicker.regional['es'], 
            {'showAnim':'fold','dateFormat':'dd/mm/yy'}
            )
        );
    });
JS;
Yii::app()->clientScript->registerScript('js_datepicker', $js_datepicker, CClientScript::POS_END);
?>


<div class="row-fluid formSep">
    <div class="span12">
        <label class="control-label"><?php echo Yii::t('profind', 'Currículums'); ?></label>
        <div class="controls">            
            <table class="table templateFrame">
                <thead class="templateHead">
                    <tr>
                        <th style="width: 20%;"><?php echo Yii::t('profind', 'Fecha'); ?></th>
                        <th style="width: 30%;"><?php echo Yii::t('profind', 'Título'); ?></th>
                        <th style="width: 40%;"><?php echo Yii::t('profind', 'Fichero'); ?></th>
                        <th style="width: 10%;"></th>
                    </tr>
                </thead>
                <tbody class="templateTarget">
                    <?php foreach($candidato->documentos as $i=>$documento): ?>
                    <tr class="templateContent">
                        <td>
                            <?php $this->widget('zii.widgets.jui.CJuiDatePicker', array(
                                'model' => $documento,
                               'attribute' => "[$i]fecha",
                                'language' => 'es',
                                'options' => array('showAnim' => 'fold', 'dateFormat' => 'dd/mm/yy'),
                                'htmlOptions' => array('class' => 'span12'),
                            ));
                            ?>                             
                            <?php echo CHtml::error($documento, 'fecha'); ?>
                        </td>
                        <td>
                            <?php echo CHtml::activeTextField($documento, "[$i]titulo", array('class' => 'span12')); ?>
                            <?php echo CHtml::error($documento, 'titulo'); ?>
                        </td>
                        <td>
                            <?php if ($documento->getError('nombre_fichero') != '') : ?>
                                <?php echo CHtml::activeFileField($documento, "[$i]titulo", array('class' => 'span12')); ?>
                                <?php echo CHtml::error($documento, 'nombre_fichero'); ?>
                            <?php else : ?>
                                <?php echo CHtml::encode($documento->nombre_fichero); ?>
                            <?php endif; ?>
                        </td>
                        <td>
                            <?php echo CHtml::activeHiddenField($documento, "[$i]id", array('class' => 'pk')); ?>
                            <?php echo CHtml::activeHiddenField($documento, "[$i]id_candidato"); ?>
                            <?php echo CHtml::hiddenField("CandidatoDocumento[$i][_borrar]", '0', array('class' => 'to_remove')); ?>
                            <input type="hidden" class="rowIndex" value="<?php echo $i;?>" />
                            <?php if (!$documento->hasErrors()) : ?>
                                <?php echo CHtml::link(CHtml::tag('i', array('class' => 'icon-download'), ''), 
                                        $this->createUrl('download', array("id"=>$documento->id)), 
                                        array('class' => 'btn btn-small download')
                                ); ?>
                            <?php endif; ?>
                            <a class="btn btn-small remove" href="#"><i class="icon-trash"></i></a>                            
                        </td>
                    </tr>
                    <?php endforeach; ?>
                </tbody>
                <tfoot>
                    <tr>
                        <td colspan="4">
                            <a class="btn btn-small add" href="#"><i class="icon-plus"></i> <?php echo Yii::t('profind', 'Añadir un currículum');?></a>
                            <textarea class="hide template">
                                <tr class="templateContent">
                                    <td>
                                        <?php $this->widget('zii.widgets.jui.CJuiDatePicker', array(
                                            'name' => 'CandidatoDocumento[{0}][fecha]',
                                            'value' => date('dd/mm/yy', time()),
                                            'language' => 'es',
                                            'options' => array('showAnim' => 'fold', 'dateFormat' => 'dd/mm/yy'),
                                            'htmlOptions' => array('class' => 'span12 datepicker'),
                                        ));
                                        ?>  
                                    </td>
                                    <td>
                                        <?php echo CHtml::textField('CandidatoDocumento[{0}][titulo]', Yii::t('profind', 'Documento'), array('class' => 'span12')); ?>
                                    </td>
                                    <td>
                                        <?php echo CHtml::fileField('CandidatoDocumento[{0}][nombre_fichero]'); ?>
                                    </td>
                                    <td>
                                        <?php echo CHtml::hiddenField('CandidatoDocumento[{0}][id]', '', array('class' => 'pk')); ?>
                                        <?php echo CHtml::hiddenField('CandidatoDocumento[{0}][id_candidato]'); ?>
                                        <?php echo CHtml::hiddenField('CandidatoDocumento[{0}][_borrar]', '0', array('class' => 'to_remove')); ?>
                                        <input type="hidden" class="rowIndex" value="{0}" />
                                        
                                        <a class="btn btn-small remove" href="#"><i class="icon-trash"></i></a>
                                    </td>
                                </tr>
                            </textarea>
                        </td>
                    </tr>
                </tfoot>
            </table>                
        </div>
    </div>
</div>

