<?php echo $header; ?>
<div class="container-fluid">
    <div class="row">
        <div class="col-lg-8">
            <h1 class="page-header">
                <?php echo $this->lang->line('comments_header'); ?>
            </h1>
        </div>
        <div class="col-lg-4">
            <form action="/admin/comments">
                <div class="input-group searchContainer">
                    <input type="text" class="form-control" id="searchString" name="term"
                        placeholder="<?php echo getSearchTerm()?>">
                    <span class="input-group-btn">
                        <button class="btn btn-default" type="submit" id="searchBtn"><span
                                class="fa fa-search"></span></button>
                    </span>
                </div><!-- /input-group -->
            </form>
        </div>
        <div class="col-lg-12">
            <ol class="breadcrumb">
                <li>
                    <i class="fa fa-dashboard"></i>
                    <a href="<?php echo BASE_URL; ?>/admin"><?php echo $this->lang->line('nav_dash'); ?></a>
                </li>
                <li class="active">
                    <i class="fa fa-fw fa-newspaper-o"></i>
                    <a href="<?php echo BASE_URL; ?>/admin/posts"><?php echo $this->lang->line('nav_posts_all'); ?></a>
                </li>
            </ol>
        </div>

    </div>
</div>

<div class="container-fluid">
    <div class="row">
        <div class="col-md-12">
            <table class="table table-striped table-bordered">
                <thead>
                    <tr>
                        <th> ID </th>
                        <th> Comment </th>
                        <th> User </th>                        
                        <th> Posted Date </th>
                        <th class="td-actions"> </th>
                    </tr>
                </thead>
                <tbody id="postContainer">
                    <?php 
					foreach ($comments as $c) {
						echo '<tr>';
							echo '<td>'.$c->commentID.'</td>';
							echo '<td>'.$c->comment.'</td>';                            
                            echo '<td>'.$c->nickname.'</td>';
                            echo '<td>'.$c->datePosted.'</td>';
                            echo '<td class="td-actions"><a href="'.BASE_URL.'/admin/comments/edit/'.$c->commentID.'" class="btn btn-small btn-success"><i class="fa fa-pencil"> </i></a> <a data-toggle="modal" data-target="#ajaxModal" class="btn btn-danger btn-small" href="'.BASE_URL.'/admin/comments/delete/'.$c->commentID.'"><i class="fa fa-remove"> </i></a></td>';
						echo '</tr>';
					} ?>
                </tbody>
            </table>
            <div class="text-center" id="loadingSpinner">
                <i class="fa fa-cog fa-spin fa-3x fa-fw"></i>
            </div>
            <div id="paginationContainer">
                <?php echo $this->pagination->create_links(); ?>
            </div>
        </div>
    </div>

</div>

<div class="modal fade schedule-publish-modal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel"
    aria-hidden="true">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="exampleModalLabel">New message</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body">
                <form>
                    <div class="form-group">
                        <label for="postID" class="col-form-label">PostID:</label>
                        <input type="text" class="form-control" name="postID" readonly>
                    </div>
                    <div class="form-group">
                        <label for="postTitle" class="col-form-label">Post Title:</label>
                        <input type="text" class="form-control" name="postTitle" readonly>
                    </div>
                    <div class="form-group">
                        <label for="run_at" class="col-form-label">Reserved Date:</label>
                        <div class="form-group">
                            <div class='input-group date' id='datetimepicker1'>
                                <input type='text' class="form-control" name="run_at" />
                                <span class="input-group-addon">
                                    <span class="fa fa-calendar"></span>
                                </span>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                <button type="button" class="btn btn-primary submit-schedule">Save</button>
            </div>
        </div>
    </div>
</div>
<script>
$(function() {
    $('#datetimepicker1').datetimepicker({
        format: 'YYYY-MM-DD HH:mm',
        dayViewHeaderFormat: 'YYYY-MM-DD',
        sideBySide: true,
        icons: {
            up: "fa fa-chevron-circle-up",
            down: "fa fa-chevron-circle-down",
            next: 'fa fa-chevron-circle-right',
            previous: 'fa fa-chevron-circle-left'
        }
    });
    $('.settime-publish').on('click', function(e) {
        e.preventDefault();
        $('.schedule-publish-modal form input[name=postID]').val($(this).prop('tabindex'));
        $('.schedule-publish-modal form input[name=postTitle]').val($(this).parent().siblings().eq(0)
            .text());
        $('.schedule-publish-modal').modal('show')
    });
    $('.submit-schedule').on('click', function(e) {
        var frm = $('.schedule-publish-modal form').get(0);
        var params = {
            postID: frm.postID.value,
            run_at: frm.run_at.value
        };
        $.post('/admin/posts/schedule/' + params.postID, params, function(res) {
            if (res.code == 200) {
                alert('Saved!');
                $('.schedule-publish-modal').modal('hide')
            }
        }, 'json')
    })
})
</script>
<?php echo $footer; ?>