<?php 
if ($permissions->hasPermission('addEmployeeChildren')) {
    include('Views/HRM/addEmployeeChildren.php');
}
?>
<style>
    .table thead tr >th{
        background-color:#4c0870;
        color:#fff;
        width: 17% !important;
        text-align: center !important;
    }
    .table thead tr th[class*='sorting_'] {
        color: #fff;
    }
    .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;
    }
    #Employee_Role{
        border: 2px solid #ddd;
        background: #eee;
        width: 100%;
        margin-left: 16px;
    }
</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('viewEmployeeChild') ?></div>
            
            <?php echo Forms::FloatingAddButton('4c0870', '#add_EmployeeChildren', CommonLanguage::getMessage('add_childreen_employee')); ?>
            <div id="UserValidationAlert" class="WizardValidationAlert alert alert-success hidden"> </div>
            <div class="clearfix"></div>
        </div>
        <div class="panel-body">
            <table class="table table-bordered table-hover demo-table-search" id="tableWithSearch">
                <thead>
                    <tr >
                        <th  ><?php print CommonLanguage::getMessage('employee_name') ?></th>
                        <th ><?php print CommonLanguage::getMessage('Date') ?></th>
                        <th ><?php print CommonLanguage::getMessage('amount') ?></th>
                        <th ><?php print CommonLanguage::getMessage('note') ?></th>
                        <th ><?php print CommonLanguage::getMessage('Action') ?></th>
                    </tr>
                </thead>
                <tbody>
                </tbody>
            </table>
        </div>
    </div>
</div>

<div class="modal fade bs-example-modal-md" id="Delete_Employee_Child" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true">
    <div class="modal-dialog" style="width:50%">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
                <h4 class="modal-title"><?php print CommonLanguage::getMessage('Confirm_Delete') ?></h4>
                <div id="DeleteEmployeeChild_modalAlert" class="alert alert-success"></div>
            </div>
            <div class="modal-body">
                <form>
                    <div class="row">
                        <div class="col-md-12 ">
                            <div class="col-md-12" style="margin-top: 20px;">
                                <p><?php print CommonLanguage::getMessage('Delete_Employee_Child') ?> <strong class="EmployeeName"></strong><?php print CommonLanguage::getMessage('irreversible_proc') ?></p>
                                <p><?php print CommonLanguage::getMessage('Proceed_Delete') ?></p>
                            </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 btn-danger" id="User_Delete" style="width:auto"><?php print CommonLanguage::getMessage('delete') ?></button>
            </div>
        </div>
    </div>
</div>
<script>
    var Submitted_Successfully = <?php echo json_encode(CommonLanguage::getMessage('Submitted_Successfully')); ?>,
            Failed_Submit = <?php echo json_encode(CommonLanguage::getMessage('Failed_Submit')); ?>,
            title = <?php echo json_encode(CommonLanguage::getMessage('viewEmployeeChild')); ?>,
            is_actual = <?php echo json_encode($is_actual)?>;
    $(function () {

        RebuildDataTable(title, [0,1,2,3], 'HRMAjax/viewEmployeeChildRequest',{is_actual:is_actual})
    })


    
    
    var CurrentID_ToDelete;
    $("#tableWithSearch").on("click", ".Action .Delete", function () {
        var EmployeeName = $(this).parents("tr").find("td:eq(0)").text()//parent tr keep searching till it reach tr 


        $("#Delete_Employee_Child").find(".EmployeeName").text(EmployeeName).end().modal("show") // to set the name of employee in modal to delete 


        CurrentID_ToDelete = $(this).parents('tr').find('.Action').attr('data-id') // current id to delete

    })
    $("#DeleteEmployeeChild_modalAlert").hide(); // hide the alert when submit if true or false
    //on click the delete button in modal get the id of the selected employee to delete it 
    $("#User_Delete").on("click", function () {
        var oTable = $('#tableWithSearch').dataTable();
        var me = this;
        $.ajax({
            type: 'POST',
            url: 'HRMAjax/viewEmployeeChildRequest',
            data: {GetID: CurrentID_ToDelete},
            complete: function (data, vv) {
                if (vv == "success" && data.responseText == "ok") {

                    $("#DeleteEmployeeChild_modalAlert").attr("class", "alert alert-success").html(Submitted_Successfully).show()
                    RebuildDataTable(title, [0,1,2,3], 'HRMAjax/viewEmployeeChildRequest',{is_actual:is_actual})
            setTimeout(function () {
                        $("#Delete_Employee_Child").modal("hide")
                    }, 1000)
                } else {
                    $("#DeleteEmployeeChild_modalAlert").attr("class", "alert alert-danger").html(Failed_Submit).show()

                }
            }});
    })

</script>
