<?php
$cs = Yii::app()->getClientScript();
$cs->registerScript("CategorywiseGMC", "function CategorywiseGMC(cat_id){
    if (cat_id > 0) {
        jQuery.ajax({
                'data': {
                'cat_id': cat_id,
                'YII_CSRF_TOKEN' : ' ". Yii::app()->request->csrfToken ."'
            },
            'dataType': 'json',
            'type': 'post',
            'url': '".Yii::app()->createUrl('hiddengmc/getGmcFromCategory') ."',
            'success': function(data) {
                $('#div_cat_pdts').html(data.dt);
            } 
        });  
    }
    
};", CClientScript::POS_HEAD);
$cs->registerScript("getmodelNo", "function getmodelNo(product_id){
    if (product_id > 0) {
        jQuery.ajax({
                'data': {
                'product_id': product_id,
                'YII_CSRF_TOKEN' : ' ". Yii::app()->request->csrfToken ."'
            },
            'dataType': 'json',
            'type': 'post',
            'url': '".Yii::app()->createUrl('hiddengmc/getModelFromGMC') ."',
            'success': function(data) {
                $('#HiddenGMCModel_no').addClass('filled');
                $('#HiddenGMCModel_no').val(data.model_no);
            } 
        });  
    }
    
};", CClientScript::POS_HEAD);
?>
<div class="popup_inner_element">
<?php
$form = $this->beginWidget('CActiveForm', array(
    'id' => 'hiddengmc-form',
    'enableAjaxValidation' => false,
    'enableClientValidation' => false,
        ));
?>

    <div class="tab-content">
        <div class="tab-pane active">
            <ul class="clearfix form-ul material">
                <?php echo $form->hiddenField($model, 'id'); ?>
                <li class="col-sm-4">
                    <?php 
                    $arr_dis=new MasDistributerType();
                    $arr_dis=$arr_dis->getActiveDistributerType();
                    echo $form->dropdownList($model, 'distributer_type_id',$arr_dis, array('data-label' => 'Distributor Type<span style="color:red">*</span>', 'data-validation' => 'required','empty'=>'-Select-','data-search'=>'true')); ?>
                </li> 
                <li class="col-sm-4">
                    <?php 
                    $modelMasProductCategory=new MasProductCategory();
                    $arrProductCategory = $modelMasProductCategory->getProductCategory();
                    $cat_id = $model->gmc_det->product_category_id;
                    echo CHtml::dropdownList('product_Category',$cat_id,$arrProductCategory, array('data-label' => 'Product Category <span style="color:red">*</span>', 'data-validation' => 'required', 'onchange' => 'CategorywiseGMC(this.value)','empty'=>'-Select-','data-search'=>'true')); ?>
                </li>
                
                <div id="div_cat_pdts">
                <li class="col-sm-4">
                    <?php $arr_pdts=new Inventory();
                    $arr_pdts = $arr_pdts->getActiveGMCs();
                    echo $form->dropdownList($model, 'product_id',$arr_pdts, array('data-label' => 'GMC <span style="color:red">*</span>', 'data-validation' => 'required','empty'=>'-Select-','onchange'=>'getmodelNo(this.value);','data-search'=>'true')); ?>
                </li>
                </div>
                <li class="col-sm-4">
                    <?php echo CHtml::textField('HiddenGMCModel_no',$model->gmc_det->model_no,['data-label' => 'Model No <span style="color:red">*</span>','readonly'=>true]);?>
                </li>
                
            </ul>
        </div>
    </div>

 <div class="modal-footer">
    <button type="button" class="btn btn-default" id="hiddengmc_close" data-dismiss="modal">Close</button>
    <?php
    $url = Yii::app()->createUrl('hiddengmc/Save');
    if($type!='view'){
        
    echo CHtml::ajaxSubmitButton('Save', $url, array(
        'dataType' => 'json',
        'type' => 'post',
        'success' => 'function(data) {
            $("#loader").hide();
                if(data.status=="success"){  
                    t8.success("GMC Hidded Successfully for Distributer!");
                    $("#hiddengmc_close").click();
                    reloadTable("#tbl_hiddengmc_details");
                } else { 
                    $("#hiddengmc-form .hiddengmc-save-btn").prop("disabled", false);                      
                    $("#hiddengmc-form .hiddengmc-save-btn").addClass("btn-theme").removeClass("btn_loading"); 
                    $.each(data, function(key, val) {
                        t8.error(""+val+""); 
                    }); 
                } 
        }',
        'beforeSend' => 'function(){ 
            $("#loader").show();
            $(".toast8-error").hide();
            $("#hiddengmc-form .hiddengmc-save-btn").prop("disabled", true);                      
            $("#hiddengmc-form .hiddengmc-save-btn").addClass("btn_loading").removeClass("btn-theme"); 

        }'
    ), 
    array('id' => 'mybtn' . rand(), 'class' => 'hiddengmc-save-btn btn btn-theme'));
    }
    ?>
</div>
<?php $this->endWidget(); ?>