
<?php
/* @var $this TidController */
/* @var $model Tid */

$this->breadcrumbs = array(
    yii::t('default', 'TIDs Management') => array('dashboardLayout/tids'),
    yii::t('default', 'Assets') => array('index'),
    //$model->id=>array('view','id'=>$model->id),
    yii::t('default', 'Renew'),
);
?>

<?php
$form = $this->beginWidget('bootstrap.widgets.TbActiveForm', array(
    'id' => 'renew-form',
    'enableAjaxValidation' => false,
        ));

$this->widget('bootstrap.widgets.TbAlert');
?>


<div id="flash-msg">
    <br>
    <?php $this->widget('bootstrap.widgets.TbAlert'); ?>
</div>

<?php
/* @var $this AssetController */
/* @var $model Asset */
/* @var $form CActiveForm */
?>
<div id="loading-div" >
    <?php
    echo $form->dropDownListControlGroup($model, 'type_of_asset_id', TypeOfAsset::getVehiclRadioForDropDown(), array(
        'empty' => Yii::t('default', 'Select Type of Asset'),
        'ajax' => array(
            'type' => 'POST',
            'data' => 'js:{type_of_asset:$(this).val(),ajax:true}',
            'url' => CController::createUrl('asset/processTypeOfAsset'),
            'success' => 'js:function(data) {
			checkTypeOfAsset(data,"ajax");
		    }',
        )
    ));
    ?>
    <div id="vehicle" style="display: none">
        <?php
        echo $form->labelEx($model, 'plate_number_auto_complete');
        $form->widget('zii.widgets.jui.CJuiAutoComplete', array(
            'model' => $model,
            'attribute' => 'plate_number_auto_complete',
            'source' => array_values(Asset::getPlateNumbersForDropDown()),
            'options' => array(
                'minLength' => '0',
            ),
             'htmlOptions' => array(             
                'placeholder' => 'Search By Plate / Asset No'
            )
        ));
        echo TbHtml::image(Yii::app()->request->baseUrl . '/css/flags/search.png', '', array("style" => ""
            . "display: inline-block;
                                        vertical-align: top;
                                        margin-top: 0px;
                                        margin-left: 0px;
                                        border: 1px solid #CCC;
                                        padding: 2px;                                    
                                        -webkit-border-bottom-right-radius: 6px;
                                        -webkit-border-top-right-radius: 6px;                                        
                                        -moz-border-bottom-right-radius: 6px;
                                        -moz-border-top-right-radius: 6px;
                                        border-bottom-right-radius: 6px;
                                        border-top-right-radius: 6px;",
                )
        );

        echo $form->labelEx($model, 'vehicle_book_expiry_date');
        
        $this->widget('yiiwheels.widgets.datepicker.WhDatePicker', array(
            'model' => $model,
            'id' => 'vehicle_book_expiry_date',
            'attribute' => 'vehicle_book_expiry_date',
            'pluginOptions' => array(
                'format' => 'yyyy-mm-dd'
            )
        ));
        ?>

    </div>

    <div id="radioactive"  style="display: none">
        <?php
        echo $form->labelEx($model, 'radioactive_license_number_auto_complete');
        $form->widget('zii.widgets.jui.CJuiAutoComplete', array(
            'model' => $model,
            'attribute' => 'radioactive_license_number_auto_complete',
            'source' => array_values(Asset::getLicenseNumbersForDropDown()),
            'options' => array(
                'minLength' => '0',
            ),
            'htmlOptions' => array(             
                'placeholder' => 'Search By License/Asset No'
            )
        ));
        echo TbHtml::image(Yii::app()->request->baseUrl . '/css/flags/search.png', '', array("style" => ""
            . "display: inline-block;
                                        vertical-align: top;
                                        margin-top: 0px;
                                        margin-left: 0px;
                                        border: 1px solid #CCC;
                                        padding: 2px;                                    
                                        -webkit-border-bottom-right-radius: 6px;
                                        -webkit-border-top-right-radius: 6px;                                        
                                        -moz-border-bottom-right-radius: 6px;
                                        -moz-border-top-right-radius: 6px;
                                        border-bottom-right-radius: 6px;
                                        border-top-right-radius: 6px;",
                )
        );


        echo $form->labelEx($model, 'radioactive_license_expiry_date');

        $this->widget('yiiwheels.widgets.datepicker.WhDatePicker', array(
            'model' => $model,
            'id' => 'radioactive_license_expiry_date',
            'attribute' => 'radioactive_license_expiry_date',
            'pluginOptions' => array(
                'format' => 'yyyy-mm-dd'
            )
        ));
        ?>

    </div>

    <div class="actions">
        <?php echo CHtml::submitButton(Yii::t('default', 'Save'), array('class' => 'btn primary')); ?>
        &ensp;
        <?php echo CHtml::button(Yii::t('default', 'Save and Renew Another Asset'), array('class' => 'btn primary', 'submit' => array('generalRenew', 'from' => 'New')));
        ?>
        &ensp;
        <?php echo CHtml::link(Yii::t('default', 'Cancel'), array('index'), array('class' => 'btn primary')); ?>
    </div>

    <?php $this->endWidget(); ?>


</div>



<script type="text/javascript">


    var vehicle_id = '<?php echo Setting::getVehicleTypeOfAsset(); ?>';
    var radio_active_id = '<?php echo Setting::getRadioActiveTypeOfAsset(); ?>';

    $(document).ready(function() {



//        var hasError = '<?php echo $model->hasErrors() ?>';
//        if (hasError != '1') {
//
//            $("label[for=Asset_radioactive_license_expiry_date]").addClass("required");
//            $("label[for=Asset_radioactive_license_expiry_date]").append('<span class="required"> *</span>');
//            //Vehicle
//            $("label[for=Asset_vehicle_book_expiry_date]").addClass("required");
//            $("label[for=Asset_vehicle_book_expiry_date]").append('<span class="required"> *</span>');
//        }

        var type_of_asset = '<?php echo $model->type_of_asset_id; ?>';
        checkTypeOfAsset(type_of_asset, 'page');
    });

    function checkTypeOfAsset(data, from) {
        if (from != 'page') {
            if (data == 'Vehicle') {
                $('#vehicle').attr('style', 'display:block');
                $('#radioactive').attr('style', 'display:none');
            }
            else
            if (data == 'RadioActive') {
                $('#vehicle').attr('style', 'display:none');
                $('#radioactive').attr('style', 'display:block');
            }
            else
            {
                $('#vehicle').attr('style', 'display:none');
                $('#radioactive').attr('style', 'display:none');
            }
        }
        else {
            if (data == vehicle_id) {
                $('#vehicle').attr('style', 'display:block');
                $('#radioactive').attr('style', 'display:none');
            }
            else
            if (data == radio_active_id) {
                $('#vehicle').attr('style', 'display:none');
                $('#radioactive').attr('style', 'display:block');
            }
            else
            {
                $('#vehicle').attr('style', 'display:none');
                $('#radioactive').attr('style', 'display:none');
            }
        }
        if (vehicle_id == '')
            $('#vehicle').attr('style', 'display:none');
        if (radio_active_id == '')
            $('#radioactive').attr('style', 'display:none');
    }


</script>




