<?php 
$isEdit   = !empty($model->id);
$isActive = ($model && $model->isActive == 'Y');

$form = $this->beginWidget('CActiveForm', array(
    'id' => 'country-form',
    'enableAjaxValidation' => false,
    'enableClientValidation' => false,
)); 
?>

<div class="tab-content">
    <div class="tab-pane active">
        <ul class="clearfix form-ul material">

            <li class="col-sm-6">
                <?php echo $form->textField($model, 'country_name', array(
                    'class' => 'form-control text-bold',
                    'data-label' => 'Country Name'
                )); ?>
            </li>

            <li class="col-sm-6">
                <?php echo $form->dropDownList($model, 'isActive', array(
                    'Y' => 'Active',
                    'N' => 'Inactive'
                ), array(
                    'class' => 'form-control text-bold',
                    'data-label' => 'Status'
                )); ?>
            </li>

            <?php echo $form->hiddenField($model, 'id'); ?>

        </ul>    
    </div>
</div>

<div class="modal-footer">
    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>

    <?php
        $url = Yii::app()->createUrl('/country/SaveCountry');
        echo CHtml::ajaxSubmitButton('Save', $url, array(
            'dataType' => 'json',
            'type' => 'post',
            'beforeSend' => 'function(){
                if(window.countrySubmitting){ return false; }
                window.countrySubmitting = true;
                $("#loader").show();
                $(".country-save-btn").prop("disabled", true)
                    .addClass("btn_loding")
                    .removeClass("btn-theme");
            }',
            'success' => 'function(data){
                $("#loader").hide();
                window.countrySubmitting = false;
                $(".country-save-btn").prop("disabled", false)
                    .removeClass("btn_loding")
                    .addClass("btn-theme");

                if(data.status=="success"){
                    t8.success(data.message || "Country Saved Successfully!");
                    $(".modal").modal("hide");
                    window.location.reload();
                } else {
                    t8.error(data.message || "Error while saving!");
                }
            }',
            'error' => 'function(){
                window.countrySubmitting = false;
                $("#loader").hide();
                $(".country-save-btn").prop("disabled", false)
                    .removeClass("btn_loding")
                    .addClass("btn-theme");
                t8.error("Something went wrong!");
            }'
        ), array('class'=>'country-save-btn btn btn-theme'));
    ?>
</div>

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