<?php $__env->startSection('navBar'); ?>
    <?php echo $__env->make('layouts.navBar', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('mainMenu'); ?>
    <?php echo $__env->make('layouts.mainMenu', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('content'); ?>

    <div id="demo-settings" class="col-xs-12">
        <a id="demo-settings-toggler" class="fa fa-pencil"></a>
        <h5 class="header">Notification Information</h5>

        <div class="row" id="editPanel">
        </div>
    </div>

    <div class="row">
        <div class="col-md-6 col-md-offset-3">
            <div class="input-daterange input-group" id="notificationDateRange">
                <input type="text" class="input-sm form-control" name="startDate" id="startDate"
                       placeholder="Start date" value="<?php echo e(date('d/m/Y', strtotime($startDate))); ?>">
                <span class="input-group-addon">to</span>
                <input type="text" class="input-sm form-control" name="endDate" id="endDate" placeholder="End date"
                       value="<?php echo e(date('d/m/Y', strtotime($endDate))); ?>">
            </div>
        </div>
    </div>
    <br/>
    <div class="panel-group" id="accordion-notification">

        <div class="panel">
            <div class="panel-heading">
                <a class="accordion-toggle btn" data-toggle="collapse" data-parent="#accordion-notification"
                   href="#accordionAddNotification">
                    Add New Notification
                </a>
            </div>
            <!-- / .panel-heading -->
            <div id="accordionAddNotification" class="panel-collapse collapse">
                <div class="panel-body" id="formAddNotification">

                </div>
                <!-- / .panel-body -->
            </div>
            <!-- / .collapse -->
        </div>

        <div class="panel">
            <div class="panel-heading">
                <a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion-notification" href="#panelNotificationList">
                    Notification List
                </a>
            </div>
            <!-- / .panel-heading -->
            <div id="panelNotificationList" class="panel-collapse in">
                <div class="panel-body no-padding panelOverFlow" id="notificationList">
                    <div id="delete-confirmation" class="modal modal-alert modal-danger fade">
                        <div class="modal-dialog">
                            <div class="modal-content">
                                <div class="modal-header">
                                    <i class="fa fa-times-circle"></i>
                                </div>
                                <div class="modal-title" id="confirmDeletionTitle"></div>
                                <div class="modal-body">Confirm to delete this notification</div>
                                <div class="modal-footer">
                                    <a id="confirmDeletionLink"
                                       class="btn btn-danger" data-dismiss="modal">Confirm Deletion</a>
                                </div>
                            </div>
                            <!-- / .modal-content -->
                        </div>
                        <!-- / .modal-dialog -->
                    </div> <!-- / .modal -->

                    <div class="panel-body no-padding">
                        <table cellpadding="0" cellspacing="0" border="0" class="table table-striped"
                               id="notificationsTable">
                            <thead>
                            <tr>
                                <th><i class="fa fa-pencil"></i></th>
                                <th>About</th>
                                <th>Method</th>
                                <th>Content</th>
                                <th>Date</th>
                                <th>status</th>
                            </tr>
                            </thead>
                        </table>
                    </div>
                </div>
                <!-- / .panel-body -->
            </div>
            <!-- / .collapse -->
        </div>

    </div> <!-- / .panel-group -->

    <script type="text/javascript">
        generateFormAddNotification('<?php echo e(URL::action("NotificationController@generateFormAddNotification")); ?>', '<?php echo e(csrf_token()); ?>');
        //generateNotificationList('<?php echo e(URL::action("NotificationController@generateNotificationList")); ?>', '<?php echo e(csrf_token()); ?>');

        $(document).on('click', '.delete-notification', function(){
            confirmDeletionInitPost($(this).data("url"), $(this).data("id"), $(this).data("name"), $_token, refreshNotifications)
        });
        $(document).on('click', '.edit-notification', function(){
            generateNotificationDetail($(this).data("url"), $(this).data("id"), $_token)
        });

        $('#startDate').datepicker({
            format: 'dd/mm/yyyy'
        }).on('changeDate', function (ev) {
            refreshNotifications();
        });
        $('#endDate').datepicker({
            format: 'dd/mm/yyyy'
        }).on('changeDate', function (ev) {
            refreshNotifications();
        });

        var $_token = "<?php echo e(csrf_token()); ?>",
                notificationTable;

        notificationTable =
                $('#notificationsTable')
                        .dataTable({
                            processing: true,
                            serverSide: true,
                            bProcessing: true,
                            order: [[ 4, "desc" ]],
                            ajax: {
                                "url": "<?php echo e(URL::action("NotificationController@generateNotificationList")); ?>",
                                "type": "POST",
                                "data": function (data) {
                                    data._token = $_token;
                                    data.startDate = changeDateFormatToISO($('#startDate').val());
                                    data.endDate = changeDateFormatToISO($('#endDate').val());
                                }
                            },
                            columns: [
                                {data: 'edit', name: 'edit', orderable: false, searchable: false},
                                {data: 'relatedId', name: 'relatedId'},
                                {data: 'method', name: 'method'},
                                {data: 'content', name: 'content'},
                                {data: 'notifyDate', name: 'notifyDate'},
                                {data: 'status', name: "status"}
                            ],
                            iDisplayLength: 25
                        });
        $('#notificationsTable_wrapper .table-caption').text('Notifications');
        $('#notificationsTable_wrapper .dataTables_filter input').attr('placeholder', 'Search...');

        function refreshNotifications() {
            notificationTable.api().ajax.reload();
        }
    </script>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.master', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>