<?php
if ($permissions->hasPermission('add_volunteer_notice')) {
    include('Views/HRM/add_volunteer_notice.php');
}
?>
<style>

    .table thead tr th {
        background-color:#4c0870; 
        color:#fff;
        text-align: center !important;
    }
</style>
<div class="col-md-12">    
    <div class="panel panel-white">
        <div class="panel-heading clearfix no-print">
            <h4 class="panel-title"> <?php echo CommonLanguage::getMessage('volunteer_notice'); ?></h4>
            <div id="alert_team" ></div>
            <?php
            if ($permissions->hasPermission('add_volunteer_notice')) {
                echo Forms::FloatingAddButton('4c0870', '#add_volunteer_notice', CommonLanguage::getMessage('add'), null, "AddVolunteerNotice");
            }
            ?>
        </div>
        <div class="panel-body">
            <div class="col-md-12">
                <div class="row">
                    <div class="col-md-12">
                      
                            <table class="table table-bordered " id='tableWithSearch'>
                                <thead>
                                    <tr>
                                        <th ><?php print CommonLanguage::getMessage('notice_name'); ?></th>
                                        <th  ><?php print CommonLanguage::getMessage('Action'); ?></th>
                                    </tr>
                                </thead>
                                <tbody>

                                </tbody>
                            </table>
                       
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<div class="modal fade bs-example-modal-sm" id="DeleteVNoticeFromList" 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="DeleteNotice_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('About_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="Notice_Delete" style="width:auto"><?php print CommonLanguage::getMessage('delete'); ?></button>
            </div>
        </div>
    </div>
</div>

<script>
    var title = <?php echo json_encode(CommonLanguage::getMessage('volunteer_notice')); ?>;
    var Submitted_Successfully = <?php echo json_encode(CommonLanguage::getMessage('Submitted_Successfully')); ?>,
            Failed_Submit = <?php echo json_encode(CommonLanguage::getMessage('Failed_Submit')); ?>;
    $(function () {
        RebuildDataTable(title, [0], 'HRMAjax/ViewVolunteerNoticeRequest');
        $("#tableWithSearch").on("click", ".Action .Delete", function () {
            CurrentID = $(this).parents('div.Action').attr('data-id');
            var name = $(this).parents("tr").find("td:eq(0)").text();
            $("#DeleteVNoticeFromList").find(".Name").text(name).end().modal("show");
            $("#DeleteNotice_modalAlert").hide();
        });
        $("#Notice_Delete").on("click", function () {
            $.ajax({
                type: 'POST',
                url: 'HRMAjax/ViewVolunteerNoticeRequest',
                data: {GetID: CurrentID},
                dataType: 'JSON',
                complete: function (data, vv) {
                    if (vv == "success") {
                        if (data.responseJSON[0] == "OK") {
                            $("#DeleteNotice_modalAlert").attr("class", "alert alert-success").html(Submitted_Successfully).show();
                            setTimeout(function () {
                                $("#DeleteVNoticeFromList").modal("hide")
                                $("#DeleteNotice_modalAlert").remove()
                            }, 1000)
                            RebuildDataTable(title, [0], 'HRMAjax/ViewVolunteerNoticeRequest');
                        } else {
                            $("#DeleteNotice_modalAlert").attr("class", "alert alert-danger").html(data.responseJSON[1]).show();
                        }

                    } else {
                        $("#DeleteNotice_modalAlert").attr("class", "alert alert-danger").html(Failed_Submit).show();
                    }
                }

            });
        });

    });

</script>