<?php
include("Views/HRM/createUserGroup.php");
?>
<style>
    .table thead tr >th{
        background-color:#4c0870;
        color:#fff;
        text-align: center;
    }

    #error_list_row thead tr>th{
        background-color:#ba1d1d;
        text-align: center !important;
    }
    .table tbody tr >td,.table tbody tr >td input{

        text-align: center;
    }
    .table thead tr th[class*='sorting_'] {
        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('viewUserGroup'); ?></div>
            <div class="clearfix"></div>

            <?php
            if ($permissions->hasPermission('createUserGroup')) {
                echo Forms::FloatingAddButton('ed9421', '#createUserGroup', CommonLanguage::getMessage('Add'));
            }
            ?>
        </div>
        <div class="panel-body">





            <table class="table table-bordered table-hover demo-table-search" id="tableWithSearch">
                <thead>
                    <tr>
                        <th class="text-center"><?php print CommonLanguage::getMessage('grp_name'); ?></th>
                        <th class="text-center"><?php print CommonLanguage::getMessage('Action'); ?></th>

                    </tr>
                </thead>
                <tbody>
                </tbody>
            </table>



        </div>
    </div>
</div>
<div class="modal fade bs-example-modal-md" id="DeleteFromList" 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="DeleteEmployee_modalAlert"></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'); ?> <strong class="Name"></strong></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="Employee_Delete" style="width:auto"><?php print CommonLanguage::getMessage('delete'); ?></button>
            </div>
        </div>
    </div>
</div>

<script>
    var title = <?php echo json_encode(CommonLanguage::getMessage('viewEmployeeAlert')); ?>;
    var delete_trs = <?php echo json_encode(CommonLanguage::getMessage('delete_trs_dys')); ?>;
    var grp_name = <?php echo json_encode(CommonLanguage::getMessage('grp_name')); ?>;
    var id;
    $(function () {

        RebuildDataTable(title, [0], 'HRMAjax/viewUserGroupRequest');
        $("#tableWithSearch").on("click", ".Action .Delete", function () {
            var EmployeeName = $(this).parents("tr").find("td:eq(0)").text();
            $("#DeleteFromList").find(".Name").text(grp_name + ' ' + EmployeeName).end().modal("show"); // to set the name of employee in modal to delete 
            id = $(this).parents("tr").find('.Action').attr('data-id'); // current id to delete
        });
        $("#Employee_Delete").on("click", function () {

            $.ajax({
                url: "HRMAjax/viewUserGroupRequest",
                method: "POST",
                dataType: 'JSON',
                data: {Getid: id},
                complete: function (v1, v2) {
                    if (v2 == "success") {
                        if (v1.responseJSON[0] == "OK") {
                            $("#DeleteEmployee_modalAlert").attr("class", "alert alert-success").html(Submitted_Successfully);
                            RebuildDataTable(title, [0], 'HRMAjax/viewUserGroupRequest');
                            setTimeout(function () {
                                $("#DeleteFromList").modal("hide")
                                $("#DeleteEmployee_modalAlert").addClass('hidden')
                            }, 1000)
                        } else {
                            $("#DeleteEmployee_modalAlert").attr("class", "alert alert-danger").html(v1.responseJSON[1]);
                        }
                    } else {
                        $("#DeleteEmployee_modalAlert").attr("class", "alert alert-danger").html(Failed_Submit);
                    }

                }
            });
        });
    });


</script>