<!--FIXME : translation tags ! -->
<?php 
if (!$model->isNewRecord()) { 
?>
<script>
$('#firmware-grid_Modal').on('show',function() {
    $('h4').text('<?php echo __("FIRMWARE_HEADER_UPDATE").': '.CHtml::encode($model->phoneType); ?> ');
});
</script>
<?php
}else {
?>
<script>
$('#firmware-grid_Modal').on('show',function() {
    $('h4').text('<?php echo __("FIRMWARE_HEADER_CREATE")?>');
});
</script>
<?php
}
$form=$this->beginWidget('ext.PlGrid.PlActiveForm', array(
        'id'=>'firmware-form',
        'gridId'=>'firmware-grid',
		'displayProgressBar'=>true,
        'action'=> $model->isNewRecord ? array('create') : array()
    ));
    
    $bool = array('standard');
    $text = array();
    $phonesDropDown = array('phoneType');
    $file = array('data');
    $hidden = array('fileName');
    


       
    foreach ($model->attributes as $attributeName => $attributeValue) {
       
        if (in_array($attributeName, $hidden)) {
            $htmlOptions = array();
            
            if ($attributeName== 'fileName') {
                $htmlOptions=array('id'=>'fileName','name'=>'Firmware[data]');
            }
            echo $form->hiddenField($model,$attributeName,$htmlOptions);
        }

        if (in_array($attributeName, $file)) {
            $htmlOptions = array('onchange'=>'getFileName(this)', 'data-translation-target'=>'FIRMWARE_ERROR_MESSAGE_TRANSLATIONS');
            
            echo $form->labelEx($model,$attributeName,array('class'=>'control-label'));
            echo '<div class="controls">';       
            echo CHtml::activeFileField($model,$attributeName,$htmlOptions);
            echo $form->error($model,$attributeName);
            
            echo "<div class='showError'>";
            echo '</div>';
            echo '</div>';

        }
        if (in_array($attributeName, $bool)) {
            $htmlOptions = array();
            echo $form->checkBoxRow($model,$attributeName,$htmlOptions);
        }
        if (in_array($attributeName, $phonesDropDown)) {
            
            $htmlOptions = array();
            $data = $phones;
            echo $form->dropDownListRow($model, $attributeName,$data, $htmlOptions);
        }
    }

$this->endWidget();

if (Yii::app()->user->translateMode) {
	echo '<i data-translation-target="FIRMWARE_ERROR_MESSAGE_TRANSLATIONS" data-translation-id="FIRMWARE_MODEL_DATA"></i>';
	echo '<i data-translation-target="FIRMWARE_ERROR_MESSAGE_TRANSLATIONS" data-translation-id="FIRMWARE_VALIDATION_ERROR_FILE_NOT_SET"></i>';
	echo '<i data-translation-target="FIRMWARE_ERROR_MESSAGE_TRANSLATIONS" data-translation-id="FIRMWARE_VALIDATION_ERROR_FILE_EXISTS"></i>';
	echo '<i data-translation-target="FIRMWARE_ERROR_MESSAGE_TRANSLATIONS" data-translation-id="FIRMWARE_VALIDATION_ERROR_NO_VALID_PHONE_MODEL_FOUND"></i>';
	echo '<i data-translation-target="FIRMWARE_ERROR_MESSAGE_TRANSLATIONS" data-translation-id="FIRMWARE_VALIDATION_ERROR_WRONG_FILE_IS_NOT_VALID"></i>';
	echo '<i data-translation-target="FIRMWARE_ERROR_MESSAGE_TRANSLATIONS" data-translation-id="FIRMWARE_VALIDATION_ERROR_WRONG_FILE_IS_NOT_A_FIRMWARE_FOR"></i>';
	echo '<i data-translation-target="FIRMWARE_ERROR_MESSAGE_TRANSLATIONS" data-translation-id="FIRMWARE_VALIDATION_ERROR_WRONG_FILE_IS_NOT_A_OS_FIRMWARE"></i>';
	echo '<i data-translation-target="FIRMWARE_ERROR_MESSAGE_TRANSLATIONS" data-translation-id="FIRMWARE_VALIDATION_ERROR_WRONG_FILE_IS_NOT_A_SIP_FIRMWARE"></i>';
}

?>
<script>
$('#Firmware_data_em_').show();
function getFileName(el) { 
     filePath = $(el).val().replace(/C:\\fakepath\\/i, '');  
     $('#fileName').val(filePath);
}
</script>