<?php 
//echo '<pre>';
//print_r($_COOKIE);
//die('okk');
?>
<div class="container-fluid container-fixed-lg bg-white">
    <div class="panel panel-transparent">
        <div class="panel-heading">
            <div class="panel-title"><?php print $title; ?></div>
            <?php if ($permissions->hasPermission('add_lock_data') ) { ?>
            <div class="col-xs-12 p-0 m-b-10">  
                <div class="floatingContainer ">
                    <a href="" id="add_lock" data-target="#lock_modal" data-toggle="modal" >
                        <div class="actionButton bg-info-light" >
                            <p class="floatingText"><span class="floatingTextBG"><?php echo CommonLanguage::getMessage('add') ?></span></p>
                        </div>
                    </a>
                </div>
            </div>
            <?php } ?>
        </div>
        <div class="panel-body">
            <div class="row">
                <div class="col-md-12">
                    <div class="table-responsive">
                        <table class="table table-bordered setting-table" id="tableWithSearch">
                            <thead>
                                <tr>
                                    <th><?php print CommonLanguage::getMessage('Date') ?></th>
                                    <th><?php print CommonLanguage::getMessage('Action') ?></th>
                                </tr>
                            </thead>
                            <tbody>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<div class="modal fade" id="lock_modal" data-backdrop="static" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog modal-sm">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true"><i class="pg-close fs-20"></i>
                </button>
                <h5 class="add-label h-labels text-left bold hidden"><?php echo CommonLanguage::getMessage('add'); ?></h5>
                <h5 class="edit-label h-labels text-left bold hidden"><?php echo CommonLanguage::getMessage('Edit'); ?></h5>
            </div>
            <div class="modal-body">
                <form id="lock_form" method="POST" onsubmit="return false">
                    <input type="hidden" id="lock_id" name="lock_id"/>
                    <div class="row">
                        <?php echo Forms::AlertDiv('lock_alert'); ?>
                    </div>
                    <div class="row  m-t-10">
                        <div class="col-md-12 form-group">
                            <label><?php print CommonLanguage::getMessage('lock_until'); ?></label>
                            <input class="form-control empty" required id="lock_date" name="lock_date" type="text" autocomplete="off" />
                        </div>
                    </div> 
                </form>
            </div>
            <div class="modal-footer">
                <button class="btn btn-default" data-dismiss="modal"><?php print CommonLanguage::getMessage('Close'); ?></button>
                <button class="btn bg-info-light text-white" id="submit_lock"><?php print CommonLanguage::getMessage('Save'); ?></button>
            </div>
            <?php echo Forms::ModalLoader('lock_loader'); ?>
        </div>
    </div>
</div>
<script>
    $(function(){
        $("#lock_date").datepicker({autoclose:true});
        RebuildDataTable($('.panel-heading .panel-title').html(), [0], 'SettingsAjax/lock_data_ajax');
        $('#tableWithSearch').on('click', '.delete', function () {
            var entry_value = $(this).parents('div.Action').attr('data-id')
            IncludeDeleteModal(common_delete_modal, {lock_id: entry_value}, function () {
                RebuildDataTable($('.panel-heading .panel-title').html(), [0], 'SettingsAjax/lock_data_ajax');
            }, "SettingsAjax/delete_lock_data");
        });
        $("#add_lock").on("click", function () {
            $('#lock_id').val(0)
            $("#lock_modal .add-label").removeClass('hidden');
        });

        $("#tableWithSearch").on("click",'.edit', function () {
            var entry_value = $(this).parents('div.Action').attr('data-id')
            $('#lock_id').val(entry_value)
            $('#lock_date').val($('td:eq(0)',$(this).parents('tr')).html())
            $("#lock_modal .edit-label").removeClass('hidden');
        });
        $("#submit_lock").on("click", function () {
            if (!$("#lock_form").valid())
                return;
            var Data = new FormData(document.getElementById("lock_form"));
            $("#lock_loader").removeClass('hidden');
            $.ajax({
                url: "SettingsAjax/submit_lock",
                method: "POST",
                data: Data,
                processData: false,
                contentType: false,
                dataType: "JSON",
                complete: function (jqXHR, status) {
                    if (status == 'success') {
                        if (jqXHR.responseJSON[1] == "success") {
                            RebuildDataTable($('.panel-heading .panel-title').html(), [0], 'SettingsAjax/lock_data_ajax');
                            hideModalAlert('lock_modal', 'lock_alert');
                        }
                        AddAlert("#lock_alert", jqXHR.responseJSON[0], jqXHR.responseJSON[1]);
                    }
                    $("#lock_loader").addClass('hidden');
                }
            });
        });
    });
</script>