<style>
    .table thead tr >th{
        background-color: #652d90;
        color:#fff;
    }
</style>
<div class="container-fluid container-fixed-lg bg-white">
    <div class="panel panel-transparent">
        <div class="panel-heading">
            <div class="panel-title"><?php print CommonLanguage::getMessage('checkup_setting'); ?></div>
        </div>
        <div class="panel-body">
            <table class="table table-bordered table-hover demo-table-search" id="tableWithSearch" >
                <thead>
                    <tr>
                        <th class="text-center" style="width:10%" ><?php print CommonLanguage::getMessage('checkup_setting_title'); ?></th>
                        <th class="text-center" style="width:10%" ><?php print CommonLanguage::getMessage('checkup_setting_type'); ?></th>
                        <th class="text-center" style="width:10%" ><?php print CommonLanguage::getMessage('Action'); ?></th>
                    </tr>
                </thead>
                <tbody>
                </tbody>
            </table>
        </div>
    </div>
</div>
<div class="modal fade " data-backdrop="static" id="checkup-setting-modal" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog modal-sm" >
        <div class="modal-content">
            <div class="modal-header clearfix text-left">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true"><i class="pg-close fs-20"></i>
                </button>
                <h5 class="add-label bold"><?php print CommonLanguage::getMessage('checkup_setting'); ?></h5>
            </div>
            <div class="modal-body">
                <div class="row">
                    <?php echo Forms::AlertDiv('checkup_setting_alert'); ?>
                </div>
                <form id="checkup_setting_form" method="POST" onsubmit="return false">
                    <input type="hidden" class="checkup_setting_id" id="checkup_setting_id" name="checkup_setting_id" value=""/> 
                    <div class="row ">
                        <div class="col-md-12 form-group" >
                            <label><?php echo CommonLanguage::getMessage('checkup_setting_title') ?></label>
                            <span class="red-star">*</span>
                            <input type="text" class="form-control checkup_setting_title" name="checkup_setting_title" id="checkup_setting_title" required/>
                        </div>
                    </div>
                    <div class="row form-group">
                        <div class="col-md-12 " >
                            <input type="radio" id="check_out" value="0" name="checkup_setting_type" class="empty_radio"   required/>
                            <label><?php print CommonLanguage::getMessage('check_out');?></label>&nbsp;
                            <input type="radio" id="check_in" value="1" name="checkup_setting_type" class="empty_radio"   required/>
                            <label><?php print CommonLanguage::getMessage('check_in');?></label>&nbsp;
                            <input type="radio" id="check_in_out" value="2" name="checkup_setting_type"  class="empty_radio"  required/>
                            <label><?php print CommonLanguage::getMessage('check_in_out');?></label>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button class="btn btn-default" data-dismiss="modal"   > <?php print CommonLanguage::getMessage('Close'); ?> </button>
                <button class="btn btn-bg-success-darker" id="SubmitCheckupSetting"  > <?php print CommonLanguage::getMessage('Save'); ?>   </button>
            </div>
            <?php echo Forms::ModalLoader('checkupSettingDisabler'); ?>
        </div>
    </div>
</div>
<script>
    $(function(){
        RebuildDataTable($('.panel-heading .panel-title').html(), [0, 1], 'GarageAjax/getVehicleCheckUpSetting');
        $('#tableWithSearch').on('click','.edit_checkup_setting',function(){
            $("input[name=checkup_setting_type]").prop('checked', false); 
            var parent = $(this).parents('tr'),data = $(this).attr('data-id').split('/');
            $('#checkup_setting_title').val($('td:eq(0)',parent).html())
            $('#checkup_setting_id').val(data[0]);
            $("input[name=checkup_setting_type][value="+data[1]+"]").prop('checked', true);

        });
        $("#SubmitCheckupSetting").on("click",function(){
            if(!$("#checkup_setting_form").valid()){
                return;
            }
            var Data = new FormData(document.getElementById('checkup_setting_form'));
            $("#checkupSettingDisabler").removeClass('hidden');
            $.ajax({
                url: "GarageAjax/submitCheckupSetting",
                method: "POST",
                data: Data,
                processData: false,
                contentType: false,
                dataType: "JSON",
                complete: function (jqXHR, status) {
                    if (status == 'success') {
                        if (jqXHR.responseJSON[1] == "success") {
                            RebuildDataTable($('.panel-heading .panel-title').html(), [0, 1], 'GarageAjax/getVehicleCheckUpSetting');
                            hideModalAlert('checkup-setting-modal', 'checkup_setting_alert');
                        }
                        AddAlert("#checkup_setting_alert", jqXHR.responseJSON[0], jqXHR.responseJSON[1]);
                    }
                    $("#checkupSettingDisabler").addClass('hidden');
                }
            });
        });
    });
</script>