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

    .table thead tr >th{
        background-color:#4c0870;
        color:#fff;
        /*width: 16% !important;*/
    }
    .table thead tr th[class*='sorting_'] {
        color: #fff;
    }

    .table-responsive {
        overflow-x: visible; 
    }
</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('pro_list'); ?></div>
            <div class="clearfix"></div>

            <?php
            if ($permissions->hasPermission('add_pro_list')) {
                echo Forms::FloatingAddButton('4c0870', '#Add_Pro', 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"  style="width:30%" ><?php print CommonLanguage::getMessage('Name'); ?></th>
                        <th class="text-center" style="width:15%" ><?php print CommonLanguage::getMessage('Date'); ?></th>
                        <th class="text-center" style="width:15%" ><?php print CommonLanguage::getMessage('description'); ?></th>
                        <th class="text-center" style="width:10%" ><?php print CommonLanguage::getMessage('location'); ?></th>
                        <th class="text-center" style="width:5%" ><?php print CommonLanguage::getMessage('Action'); ?></th>
                    </tr>
                </thead>
                <tbody>

                </tbody>
            </table>

        </div>

    </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="DeleteVolunteer_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_to_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="Volunteer_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('volunteer_list')); ?>;
    $(function () {

        RebuildDataTable(title, [0, 1, 2, 3], 'HRMAjax/viewProListRequest');
    })
    var Cuurent_ToDelete;
    $("#tableWithSearch").on("click", ".Action .Delete", function () {
        var EmployeeName = $(this).parents("tr").find("td:eq(0)").text();


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

        Cuurent_ToDelete = $(this).parents("tr").find('.Action').attr('data-id'); // current id to delete
    })
    $("#DeleteVolunteer_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 
    $("#Volunteer_Delete").on("click", function () {

        $.ajax({
            type: 'POST',
            url: 'HRMAjax/viewProListRequest',
            data: {GetID: Cuurent_ToDelete},
            complete: function (data, vv) {
                if (vv == "success" && data.responseText == "OK") {
                    $("#DeleteVolunteer_modalAlert").attr("class", "alert alert-success").html(Submitted_Successfully).show();
                    RebuildDataTable(title, [0, 1, 2, 3], 'HRMAjax/viewProListRequest');
                    setTimeout(function () {
                        $("#DeleteFromList").modal("hide")
                    }, 1000)
                } else {
                    $("#DeleteVolunteer_modalAlert").attr("class", "alert alert-danger").html(Failed_Submit).show();
                }
            }
        });
    })






    $("#tableWithSearch").on("click", ".Action .Edit", function () {
        Cuurent_ToDelete = $(this).parents('div.Action').attr('data-id');
        $("#Add_Pro").modal('show');
        $("#ProDisabled").addClass('hidden');
        $("#IsEdit").val('1');
        $.ajax({
            type: 'POST',
            url: 'HRMAjax/ProSettingRequest',
            data: {EditID: Cuurent_ToDelete},
            complete: function (data, vv) {
                if (vv == "success") {
                    var Data = $.parseJSON(data.responseText);
                    var details = Data['details'];
                    $('.pro_desc').val(Data['pro_desc']);
                    $('.pro_name').val(Data['pro_name']);
                    $('.pro_link').val(Data['pro_link']);
                    $('.pro_date').val(Data['pro_date']);
                    $('.pro_loc').val(Data['pro_loc']);
                    $("#ProSetting .Setting").remove();
                    var clone_item = $('#ProSetting .Setting_clone');
                    var NewItem = null;
                    for (var i = 0; i < details.length; i++) {
                        var NewItem = clone_item.clone(false).insertAfter(NewItem === null ? clone_item : NewItem);
                        NewItem.addClass('Setting ExistSetting').removeClass('Setting_clone hidden');
                        NewItem.find(".fa-minus-circle").css("display", "");
                        NewItem.find("input").val("");
                        NewItem.find("input.vlnt_hours").val(details[i]['vlnt_hours']);
                        $(".select2-container", NewItem).empty().remove();
                        NewItem.find(".vlnt_id").show();
                        NewItem.find(".vlnt_id").attr('data-select-name', JSON.stringify(details[i]['Volunteer_Name'])).val(details[i]['vlnt_id']);
                        build_select2(NewItem.find(".vlnt_id"), "xhr/CommonSearch?col_id=volunteer_id&col_name=Volunteer_Name&table=view_volunteers");
                    }
                    if (details.length > 1)
                        $(".Setting  .fa-minus-circle").css("display", "");
                }
            }
        });
    })








</script>