
<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:#4c0870 !important;
        color:#fff;
        border: none;
    }
    .p-0{
        padding:0!important;
    }
</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('employee_location'); ?></div>

            <div class="clearfix"></div>
        </div>
        <div class="panel-body">
            <?php
            if ($permissions->hasPermission('add_employee_location')) {
                echo Forms::FloatingAddButton('4c0870', '#add_location', 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('Code'); ?></th>
                        <th class="text-center" style="width:15%" ><?php print CommonLanguage::getMessage('Name'); ?></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 bs-example-modal-md " id="add_location" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-sm " style="" >
        <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('employee_location') ?></h4>
                <div id="localtionAlert"></div>
            </div>
            <div class="modal-body">
                <form id="locationForm">
                    <div class="row">
                        <div class=" col-md-12 m-t-10 " >
                            <label class="labelText"><?php print CommonLanguage::getMessage('Code'); ?><span class="red-star">*</span></label>
                            <input type="text" class="form-control" id="location_code" name="location_code" required/>
                        </div>
                    </div>
                    <div class="row">
                        <div class=" col-md-12 m-t-10 " >
                            <label class="labelText"><?php print CommonLanguage::getMessage('Name'); ?><span class="red-star">*</span></label>
                            <input type="text" class="form-control" id="location_name" name="location_name" required/>
                        </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 style="color:white !important;" type="button" class="btn bg-success 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('employee_location')); ?>,
            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 () {
            $(".update_emp_div").addClass("hidden")
            IsEdit = false;
            IDToEdit = 0;
        })

        RebuildDataTable(title, [0], "HRMAjax/employee_locations")

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

            if ($("#location_name").val() == '' || $("#location_code").val() == '') {
                $("#localtionAlert").attr("class", "alert alert-danger").html(Required_Fields)
                return false;

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

        $("#tableWithSearch tbody").on('click', '.Edit', function () {
            $(".update_emp_div").removeClass("hidden")

            IsEdit = true;
            IDToEdit = $(this).parents('.Action').attr('data-id');
            $("#location_code").val($(this).parents("tr").find("td:eq(0)").html())
            $("#location_name").val($(this).parents("tr").find("td:eq(1)").html())
            $("#add_location").modal("show")

        })
        $('#tableWithSearch').on('click', '.Delete', function () {
            var entry_value = $(this).parents('.Action').attr('data-id')
            IncludeDeleteModal(common_delete_modal, {id: entry_value}, function () {
                RebuildDataTable($('.panel-heading .panel-title').html(), [0], 'HRMAjax/employee_locations');
            }, "HRMAjax/delete_emp_location");
        });

    })





</script>
