<?php if (empty($publications)) { ?>
    <div class="alert alert-danger" role="alert">
        <button class="close" data-dismiss="alert"></button>
        <strong><?php print CommonLanguage::getMessage('no_annoc'); ?> </strong>
    </div>
    <?php die();
}
?>
<style type="text/css">
    #Announcement_List .bg-success > th {
        color: rgb(255, 255, 255);
    }
    #Announcement_List .DisabledItem > td{
        position:relative;
    }
    .DisabledItem > td:after{
        content: "";
        position: absolute;
        left: 0;
        top: 0;
        width: 100%;
        height: 100%;
        background:#fff;
        opacity:0.5;
    }
    #EmptyTableResults {
        border: 1px dashed rgb(58, 143, 200);
        padding: 12px;
        margin:20px 10%;
        display:block;
    }
    .Edit_Announcement > a{
        color:#5e5e5e;
    }
</style>
<div class="col-md-12">
    <div class="panel panel-white">
        <div class="panel-heading">
            <div class="panel-title"> <?php print CommonLanguage::getMessage('hr_announcement'); ?></div>
            <div class="clearfix"></div>
        </div>
        <div class="panel-body">
            <input type = "hidden" id="Post_Time" value="" onload="clocktime()" />
            <div class="container">
                <div class="row">
                    <div class="col-md-12"  style="height: auto;text-align:center;">
                        <table class="table table-hover dataTable no-footer" id="Announcement_List">
                            <thead>
                                <tr class="bg-success">
                                    <th class="text-center"><?php print CommonLanguage::getMessage('title'); ?></th>
                                    <th class="text-center"><?php print CommonLanguage::getMessage('subtitle'); ?></th>
                                    <th class="text-center"><?php print CommonLanguage::getMessage('Date'); ?></th>

                                    <th class="text-center"><?php print CommonLanguage::getMessage('Status'); ?></th>
                                    <th class="text-center"><?php print CommonLanguage::getMessage('Action'); ?></th>
                                </tr>
                            </thead>
                            <tbody>

                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<div class="modal fade bs-example-modal-md" id="Delete_Category" 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="Category_KPI_modalAlert" class="alert"></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_annoc'); ?> <strong class="ItemTitle"></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="Announcement_Delete" style="width:auto"><?php print CommonLanguage::getMessage('delete'); ?></button>
            </div>
        </div>
    </div>
</div>
<script>
    var no_connect = <?php echo json_encode(CommonLanguage::getMessage('no_connect')); ?>,
            title = <?php echo json_encode(CommonLanguage::getMessage('hr_announcement')) ?>;
        var Failed_Submit = <?php echo json_encode(CommonLanguage::getMessage('Failed_Submit')); ?>,
            Submitted_Successfully = <?php echo json_encode(CommonLanguage::getMessage('Submitted_Successfully')); ?>;

    window.onload = clocktime();
    $(document).ready(function () {

        RebuildDataTable(title, [0,1,2], 'HRMAjax/ViewAnnouncmentRequest', '', '#Announcement_List');
        $("#Announcement_List").on("click", ".Action .Delete", function (e) {
            $("#Category_KPI_modalAlert").empty()
            $("#Category_KPI_modalAlert").removeClass("alert alert-success").empty()

            e.preventDefault();
            window.CurrentItem = $(this).parents('div.Action').attr('data-id');
            var AnnouncementName = $(this).parents("tr").find("td:eq(0)").text();
            $("#Delete_Category").find(".ItemTitle").text(AnnouncementName).end().modal("show")

        })
        $("#Announcement_Delete").on("click", function (e) {
            e.preventDefault();

            $("#Category_KPI_modalAlert").attr("class", "alert alert-success").empty().html(Submitted_Successfully)

            UpdateItemStatus(CurrentItem, "", true);

        })
        $('#Announcement_List').on("change", '.check', function () {

            UpdateItemStatus($(this).parents("tr").find('.Action').attr('data-id'), this.checked, false)

        })

    });

    function UpdateItemStatus(who, what, DoRemove) {

//who.addClass("DisabledItem")
        var Data = {Announcement_ID: who, Post_Time: $("#Post_Time").val()};
        if (DoRemove) {
            Data.RemoveAnnouncement = true
        } else {
            Data.Announcement_Status = what ? "1" : "0"
        }

        $.ajax({
            url: "HRMAjax/ViewAnnouncmentRequest",
            data: Data,
            complete: function (ff, fff) {
                if (fff == "success" && ff.responseText == "OK") {
                    RebuildDataTable(title, [0,1,2], 'HRMAjax/ViewAnnouncmentRequest', '', '#Announcement_List');
                    if (DoRemove) {
                        $("#Delete_Category").modal("hide")
                    }
                } else {
                    if (!DoRemove) {
                        new Switchery($(">input", $("[data-init-plugin='switchery']", who).parent().find(":not(input)").empty().remove().end()).each(function () {
                            this.checked = !what
                        }).get(0), {color: $.Pages.getColor("success")})
                    }
                    alert(no_connect);
                }
            }
        })
    }
//	function IsTableEmpty(){
//		$("#EmptyTableResults").remove();
//		var TableBody = $('#Announcement_List > tbody');
//		if($(">tr",TableBody).length == 0){
//			$('<div id="EmptyTableResults">No data available.</div>').insertAfter("#Announcement_List")
//		}
//	}
    function addZero(i) {
        if (i < 10) {
            i = "0" + i;
        }
        return i;
    }
    function clocktime() {
        var date = new Date();
        var hours = addZero(date.getHours());
        var minutes = addZero(date.getMinutes());
        var seconds = addZero(date.getSeconds());
        var ampm = hours >= 12 ? 'pm' : 'am';
        var clock = hours + ":" + minutes + ":" + seconds + " " + ampm + " ";
        $("#Post_Time").val(clock)
    }
</script>
