
<style>
    .table thead tr >th{
        background-color: #4c0870;
        color:#fff;
    }
    .table thead tr th[class*='sorting_'] {
        color: #FFFFFF;
    }
    .bg-master-lighter {
        border:none;
        background-color:#fff;
        border-top:1px solid #ddd; 

    }
    .btn-default{
        border: none;
        background-color: #eee;
    }
    .btn-default:hover{
        background-color:#ed9421 !important;
        color:#fff;
        border: none;
    }

</style>
<div id="Barcode" style="display:none"></div>


<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('trans_types'); ?></div>

            <div class="clearfix"></div>
        </div>
        <div class="panel-body">
            <?php
            if ($permissions->hasPermission('add_trans_type')) {
                echo Forms::FloatingAddButton('4c0870', '#add_trans_type', CommonLanguage::getMessage('add'));
            }
            ?>
            <table class="table table-bordered table-hover demo-table-search" id="tableWithSearch" >
                <thead>
                    <tr>
                        <th class="text-center" style="width:15%" ><?php print CommonLanguage::getMessage('trans_type'); ?></th>
                        <th class="text-center" style="width:15%" ><?php print CommonLanguage::getMessage('abbreviation'); ?></th>
                        <th class="text-center" style="width:15%" ><?php print CommonLanguage::getMessage('Action'); ?></th>
                    </tr>
                </thead>
                <tbody>
                </tbody>
            </table>
        </div>



    </div>
</div>
<div class="modal fade"  data-backdrop="static" id="add_trans_type" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" 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-label="Close"><span aria-hidden="true"><i class="pg-close fa-22"></i></span></button>
                <h4 class="modal-title"><?php print CommonLanguage::getMessage('trans_types') ?></h4>
                <div id="assignTransTypeAlert"></div>
            </div>
            <div class="modal-body">
                <form id="AssignTransTypeForm">
                    <div class="row">
                        <div class=" col-md-12 m-t-10 " >
                            <div class=" col-md-6 m-t-10 " >
                                <label class="labelText"><?php print CommonLanguage::getMessage('trans_type'); ?><span class="red-star">*</span></label>
                                <input type="text" class="form-control" id="subtype_name" name="subtype_name" required/>
                            </div>
                            <div class=" col-md-6 m-t-10 " >
                                <label class="labelText"><?php print CommonLanguage::getMessage('abbreviation'); ?><span class="red-star">*</span></label>
                                <input type="text" class="form-control" id="subtype_abbrv" name="subtype_abbrv" required/>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal"><?php print CommonLanguage::getMessage('Close') ?></button>
                <button type="button" class="btn bg-complete white" id="assignBtn" style="width:auto"><?php print CommonLanguage::getMessage('Save') ?></button>
            </div>
        </div>
    </div>
</div>

<script>
    var title = <?php echo json_encode(CommonLanguage::getMessage('trans_types')); ?>,
            Submitted_Successfully = <?php echo json_encode(CommonLanguage::getMessage('Submitted_Successfully')); ?>,
            Required_Fields = <?php echo json_encode(CommonLanguage::getMessage('Required_Fields')); ?>,
            Failed_Submit = <?php echo json_encode(CommonLanguage::getMessage('Failed_Submit')); ?>;
    var IsEdit = false, IDToEdit = 0;
    $(function () {


        $(".floatingContainer").on("click", function () {
            IsEdit = false;
            IDToEdit = 0;
        })

        RebuildDataTable(title, [0], "ACCAjax/trans_type_list")

        $("#assignBtn").on("click", function () {
            $("#assignTransTypeAlert").removeClass('hidden')

            if ($("#subtype_name").val() == '' || $("#subtype_abbrv").val() == '') {
                $("#assignTransTypeAlert").attr("class", "alert alert-danger").html(Required_Fields)
                return false;

            }
            var DataArr = new FormData(document.getElementById("AssignTransTypeForm"));
            DataArr.append("subtype_id", IDToEdit)
            DataArr.append("is_edit", (IsEdit ? 1 : 0))
            $.ajax({
                url: "ACCAjax/add_edit_trans_types",
                method: "POST",
                dataType: 'json',
                data: DataArr,
                processData: false,
                contentType: false,
                complete: function (v1, v2) {
                    if (v2 == "success" && v1.responseJSON == 'OK') {
                        $("#assignTransTypeAlert").attr("class", "alert alert-success").html(Submitted_Successfully)
                        RebuildDataTable(title, [0], "ACCAjax/trans_type_list")
                        setTimeout(function () {
                            $("#assignTransTypeAlert").addClass('hidden')
                            $("#add_trans_type").modal("hide")
                        }, 5000)
                    } else {
                        $("#assignTransTypeAlert").attr("class", "alert alert-danger").html(v1.responseJSON)
                    }
                }
            })
        })

        $("#tableWithSearch tbody").on('click', '.Edit', function () {
            IsEdit = true;
            IDToEdit = $(this).attr('data-id');

            $("#subtype_name").val($(this).parents("tr").find("td:eq(0)").text())
            $("#subtype_abbrv").val($(this).parents("tr").find("td:eq(1)").text())
            $("#add_trans_type").modal("show")

        })
    })





</script>
