<!-- Form -->
<div class="content-animation animated">
    <div class="row clearfix fBTitrBold ">
        <!-- Exportable Table -->
        <div class="row clearfix text-center">
            <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 ">
                <div class="card ">
                    <div class="header">
                        <h2>پیام های دریافت شده</h2>
                    </div>
                    <div class="body ">
                        <div class="row">
                            <div class="col-md-12 ">
                                <div class="table-responsive text-center p-t-20 align-center no-overflow-y no-overflow-x">
                                    <table class="table table-bordered table-striped table-hover dataTable js-exportable-accept text-center full_width">
                                        <thead>
                                        <tr>
                                            <td class="text-center">تنظیمات</td>
                                            <td class="text-center">متن پیام</td>
                                            <td class="text-center">روز سپری شده</td>
                                            <td class="text-center">روز ارسال</td>
                                            <td class="text-center">راه ارتباطی</td>
                                            <td class="text-center">موضوع پیام</td>
                                            <td class="text-center">نام فرستنده</td>
                                            <td class="text-center">کد پیام</td>
                                            <td class="text-center">شماره</td>
                                        </tr>
                                        </thead>
                                        <tbody class="bordered"></tbody>
                                        <tfoot>
                                        <tr>
                                            <td class="text-center">تنظیمات</td>
                                            <td class="text-center">متن پیام</td>
                                            <td class="text-center">روز سپری شده</td>
                                            <td class="text-center">روز ارسال</td>
                                            <td class="text-center">راه ارتباطی</td>
                                            <td class="text-center">موضوع پیام</td>
                                            <td class="text-center">نام فرستنده</td>
                                            <td class="text-center">کد پیام</td>
                                            <td class="text-center">شماره</td>
                                        </tr>
                                        </tfoot>
                                    </table>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <!-- #END# Exportable Table -->
    </div>
</div>

<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title" id="exampleModalLabel">نمایش پیام</h4>
            </div>
            <div class="modal-body modal-content-message">
                Modal content
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
            </div>
        </div>
    </div>
</div>
<!-- #END# Form -->
<script type="text/javascript">
    $(function () {

        // DataStructuresComment.InitTableAccept();
        // DataStructuresComment.InitTableExpect();
        let DataStructuresComment = {
            InitTableAccept: null,
            AcceptingTable: null,
            OnEventListener: null,
            DataList: {},
            OnEvent: {
                OnAccept: null,
                OnDelete: null
            }
        };


        DataStructuresComment.OnEvent.OnDelete = function (id, tr, table) {
            swal({
                title: "آیا از حذف این پیام مطمئن هستید؟",
                text: "تایید",
                type: "info",
                showCancelButton: true,
                closeOnConfirm: false,
                showLoaderOnConfirm: true,
            }, function () {
                LoadData({
                    request: 'proxy',
                    object: {id: id},
                    action: 'commentsController',
                    'header-type': 'comment-delete'
                }, null, false, function (data) {
                    if (data === '1') {
                        swal("حذف شد", "", "success");
                        tr.fadeOut(function (e) {
                            DataStructuresComment[table].row(tr)
                                .remove()
                                .draw();
                        });
                    } else {
                        swal("خطا", "این درخواست انجام نشد", "error");
                    }
                });
            });
        };

        DataStructuresComment.OnEventListener = function () {
            $("button[data-mod='commend']")
                .unbind()
                .bind("tap, click", function (e) {
                    let btn = $(this);
                    let id = $(this).attr("data-id"),
                        tr = btn.parents('tr'),
                        index = btn.attr("data-index"),
                        action = btn.attr("data-action");
                    switch (action) {
                        case 'delete-item':
                            DataStructuresComment.OnEvent.OnDelete(id, tr, btn.attr("data-table"));
                            break;
                        case "model-item":
                            $('.modal-content-message').append().empty();
                            $('.modal-content-message').append("<p class='rtl text-center' dir='rtl'>" + DataStructuresComment.DataList[index].message + "</p>");
                            $('#myModal').modal('show');
                            break;
                        default:
                            break;
                    }
                });
        };

        DataStructuresComment.InitTableAccept = function () {
            //js-exportable-accept
            LoadData({
                request: 'proxy',
                action: 'commentsController',
                'header-type': 'comment-load'
            }, null, true, function (data) {
                DataStructuresComment.DataList = data;
                if (DataStructuresComment.AcceptingTable !== null)
                    DataStructuresComment.AcceptingTable.destroy();

                DataStructuresComment.AcceptingTable = $('.js-exportable-accept').DataTable({
                    "data": data,
                    "columns": [
                        {"data": "Option"},
                        {"data": "text"},
                        {"data": "left-data"},
                        {"data": "send-date"},
                        {"data": "communicate"},
                        {"data": "subject"},
                        {"data": "sender"},
                        {"data": "code"},
                        {"data": "counter"}
                    ],
                    "fnInitComplete": function (e) {
                        DataStructuresComment.OnEventListener();
                    },
                    "fnInfoCallback": function (oSettings, iStart, iEnd, iMax, iTotal, sPre) {
                        DataStructuresComment.OnEventListener();
                    },
                    responsive: true,
                    "language": {
                        "lengthMenu": "نمایش _MENU_ رکورد در صفحه",
                        "zeroRecords": " چیزی یافت نشد",
                        "info": "نمایش از _START_ تا _END_ در _TOTAL_ رکورد",
                        "infoEmpty": "<center>رکوردی پیدا نشد</center>",
                        "infoFiltered": "(filtered from _MAX_ total records)",
                        "paginate": {
                            "next": "بعدی",
                            "previous": "قبلی"
                        }
                    }
                });
            });
        };
        $(document).ready(function () {
            DataStructuresComment.InitTableAccept();
        });
    }(jQuery));
</script>