{{header}}{{column_left}}
<div id="content">
    <div class="page-header">
        <div class="container-fluid">
            <div class="pull-right"><a href="{{add}}" data-toggle="tooltip" title="{{button_add}}" class="btn btn-primary"><i class="fa fa-plus"></i></a>
                <button type="button" data-toggle="tooltip" title="{{button_copy}}" class="btn btn-default" onclick="$('#form-post').attr('action', '{{copy}}').submit();"><i class="fa fa-copy"></i></button>
                <button type="button" data-toggle="tooltip" title="{{button_delete}}" class="btn btn-danger" onclick="confirm('{{text_confirm}}') ? $('#form-post').submit() : false;"><i class="fa fa-trash-o"></i></button>
            </div>
            <h1>{{heading_title}}</h1>
            <ul class="breadcrumb">
                {% for breadcrumb in breadcrumbs %}
                <li><a href="{{breadcrumb['href']}}">{{breadcrumb.text}}</a></li>
                {% endfor %}
            </ul>
        </div>
    </div>
    <div class="container-fluid">
        {% if error_warning %}
        <div class="alert alert-danger"><i class="fa fa-exclamation-circle"></i> {{error_warning}}
            <button type="button" class="close" data-dismiss="alert">&times;</button>
        </div>
        {% endif %}
        {% if success %}
        <div class="alert alert-success"><i class="fa fa-check-circle"></i> {{success}}
            <button type="button" class="close" data-dismiss="alert">&times;</button>
        </div>
        {% endif %}
        <div class="panel panel-default">
            <div class="panel-heading">
                <h3 class="panel-title"><i class="fa fa-list"></i> {{text_list}}</h3>
            </div>
            <div class="panel-body">
                <div class="well">
                    <div class="row">
                        <div class="col-sm-4">
                            <div class="form-group">
                                <label class="control-label" for="input-title">{{entry_title}}</label>
                                <input type="text" name="filter_title" value="{{filter_title}}" placeholder="{{entry_title}}" id="input-title" class="form-control" />
                            </div>
                            <div class="form-group">
                                <label class="control-label" for="input-status">{{entry_status}}</label>
                                <select name="filter_status" id="input-status" class="form-control">
                                    <option value="*"></option>
                                    {% if filter_status == '1' %}
                                    <option value="1" selected="selected">{{text_enabled}}</option>
                                    {% else %}
                                    <option value="1">{{text_enabled}}</option>
                                    {% endif %}
                                    {% if filter_status == '0' %}
                                    <option value="0" selected="selected">{{text_disabled}}</option>
                                    {% else %}
                                    <option value="0">{{text_disabled}}</option>
                                    {% endif %}
                                </select>
                            </div>                                                                                                              
                        </div>
                        <div class="col-sm-4">                            
                            <div class="form-group">
                                <label class="control-label" for="input-category">{{entry_category}}</label>

                                <select name="filter_category" id="input-category" class="form-control">
                                    <option value="*"></option>                                                                                                                                             
                                    {% for post_category in post_categories %}
                                    {% if post_category.category_id == filter_category %}
                                    <option value="{{post_category.category_id}}" selected="selected">{{post_category.title}}</option>
                                    {% else %}
                                    <option value="{{post_category.category_id}}">{{post_category.title}}</option>
                                    {% endif %}
                                    {% endfor %}
                                </select>
                            </div>
                            <div class="form-group">
                                <label class="control-label" for="input-tag">{{entry_tag}}</label>
                                <input type="text" name="filter_tag" value="{{filter_tag}}" placeholder="{{entry_tag}}" id="input-tag" class="form-control" />
                            </div>
                        </div>
                        <div class="col-sm-4">                                                                                                              
                            <div class="form-group">
                                <label class="control-label" for="input-date-published">{{entry_date_published}}</label>
                                <div class="input-group date">
                                    <input type="text" name="filter_date_published" value="{{filter_date_published}}" placeholder="{{entry_date_published}}" data-date-format="YYYY-MM-DD" id="input-date-published" class="form-control" />
                                    <span class="input-group-btn">
                                        <button type="button" class="btn btn-default"><i class="fa fa-calendar"></i></button>
                                    </span>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="control-label" for="input-date-modified">{{entry_date_modified}}</label>
                                <div class="input-group date">
                                    <input type="text" name="filter_date_modified" value="{{filter_date_modified}}" placeholder="{{entry_date_modified}}" data-date-format="YYYY-MM-DD" id="input-date-modified" class="form-control" />
                                    <span class="input-group-btn">
                                        <button type="button" class="btn btn-default"><i class="fa fa-calendar"></i></button>
                                    </span>
                                </div>
                            </div>
                            <button type="button" id="button-filter" class="btn btn-primary pull-right"><i class="fa fa-search"></i> {{button_filter}}</button>
                        </div>                                                                                              

                    </div>
                </div>
            </div>
        </div>
        <form action="{{delete}}" method="post" enctype="multipart/form-data" id="form-post">
            <div class="table-responsive">
                <table class="table table-bordered table-hover">
                    <thead>
                        <tr>
                            <td style="width: 1px;" class="text-center"><input type="checkbox" onclick="$('input[name*=\'selected\']').prop('checked', this.checked);" /></td>
                            <td class="text-center">{{column_image}}</td>
                            <td class="text-left">{% if sort == 'pd.title' %}
                                <a href="{{sort_title}}" class="{{order|lower}}">{{column_title}}</a>
                                {% else %}
                                <a href="{{sort_title}}">{{column_title}}</a>
                                {% endif %}
                            </td>                            
                            <td class="text-left">{% if sort == 'p.tag' %}
                                <a href="{{sort_tag}}" class="{{order|lower}}">{{column_tag}}</a>
                                {% else %}
                                <a href="{{sort_tag}}">{{column_tag}}</a>
                                {% endif %}
                            </td>                            
                            <td class="text-left">{% if sort == 'p2c.category_id' %}
                                <a href="{{sort_category_id}}" class="{{order|lower}}">{{column_categores}}</a>
                                {% else %}
                                <a href="{{sort_category_id}}">{{column_categores}}</a>
                                {% endif %}
                            </td>                            
                            <td class="text-left">{% if sort == 'p.status' %}
                                <a href="{{sort_status}}" class="{{order|lower}}">{{column_status}}</a>
                                {% else %}
                                <a href="{{sort_status}}">{{column_status}}</a>
                                {% endif %}
                            </td>
                            <td class="text-left">{% if sort == 'p.date_published' %}
                                <a href="{{sort_date_published}}" class="{{order|lower}}">{{column_date_published}}</a>
                                {% else %}
                                <a href="{{sort_date_published}}">{{column_date_published}}</a>
                                {% endif %}
                            </td>
                            <td class="text-left">{% if sort == 'p.date_modified' %}
                                <a href="{{sort_date_modified}}" class="{{order|lower}}">{{column_date_modified}}</a>
                                {% else %}
                                <a href="{{sort_date_modified}}">{{column_date_modified}}</a>
                                {% endif %}
                            </td>
                            <td class="text-right">{{column_action}}</td>
                        </tr>
                    </thead>
                    <tbody>
                        {% if posts %}
                        {% for post in posts %}
                        <tr>
                            <td class="text-center">{% if post.post_id in selected %}
                                <input type="checkbox" name="selected[]" value="{{post.post_id}}" checked="checked" />
                                {% else %}
                                <input type="checkbox" name="selected[]" value="{{post.post_id}}" />
                                {% endif %}
                            </td>
                            <td class="text-center">{% if post.image %}
                                <img src="{{post.image}}" alt="{{post.title}}" class="img-thumbnail" />
                                {% else %}
                                <span class="img-thumbnail list"><i class="fa fa-camera fa-2x"></i></span>
                                {% endif %}
                            </td>
                            <td class="text-left">{{post.title}}</td>                            
                            <td class="text-left">{{post.tag}}</td>                            
                            <td class="text-left">                                                                                                                      
                                {% for category in post.category %}
                                {{category.category_title}}</br>
                                {% endfor %}                                                                                                                                
                            </td>                            
                            <td class="text-left">{{post.status}}</td>
                            <td class="text-left">{{post.date_published}}</td>
                            <td class="text-left">{{post.date_modified}}</td>
                            <td class="text-right"><a href="{{post.edit}}" data-toggle="tooltip" title="{{button_edit}}" class="btn btn-primary"><i class="fa fa-pencil"></i></a></td>
                        </tr>
                        {% endfor %}
                        {% else %}
                        <tr>
                            <td class="text-center" colspan="9">{{text_no_results}}</td>
                        </tr>
                        {% endif %}
                    </tbody>
                </table>
            </div>
        </form>
        <div class="row">
            <div class="col-sm-6 text-left">{{pagination}}</div>
            <div class="col-sm-6 text-right">{{ results ? results : "" }}</div>
        </div>
    </div>
</div>
<script type="text/javascript"><!--
$('#button-filter').on('click', function () {
    var url = '{{post_search}}';

    var filter_title = $('input[name=\'filter_title\']').val();

    if (filter_title) {
        url += '&filter_title=' + encodeURIComponent(filter_title);
    }
    var filter_tag = $('input[name=\'filter_tag\']').val();

    if (filter_tag) {
        url += '&filter_tag=' + encodeURIComponent(filter_tag);
    }

    var filter_category = $('select[name=\'filter_category\']').val();

    if (filter_category !== '*') {
        url += '&filter_category=' + encodeURIComponent(filter_category);
    }

    var filter_status = $('select[name=\'filter_status\']').val();

    if (filter_status !== '*') {
        url += '&filter_status=' + encodeURIComponent(filter_status);
    }

    var filter_date_published = $('input[name=\'filter_date_published\']').val();

    if (filter_date_published) {
        url += '&filter_date_published=' + encodeURIComponent(filter_date_published);
    }

    var filter_date_modified = $('input[name=\'filter_date_modified\']').val();

    if (filter_date_modified) {
        url += '&filter_date_modified=' + encodeURIComponent(filter_date_modified);
    }

    location = url;
});
//--></script>
<script type="text/javascript"><!--
//              Posts
$('input[name=\'filter_title\']').autocomplete({
    'source': function (request, response) {
        $.ajax({
            url: '{{post_autocomplete}}&filter_title=' + encodeURIComponent(request),
            dataType: 'json',
            success: function (json) {
                response($.map(json, function (item) {
                    return {
                        label: item['title'],
                        value: item['post_id']
                    };
                }));
            }
        });
    },
    'select': function (item) {
        $('input[name=\'filter_title\']').val(item['label']);
    }
});

//--></script>
<script type="text/javascript"><!--
//              Tags
$('input[name=\'filter_tag\']').autocomplete({
    'source': function (request, response) {
        $.ajax({
            url: '{{post_autocomplete}}&filter_tag=' + encodeURIComponent(request),
            dataType: 'json',
            success: function (json) {
                response($.map(json, function (item) {
                    return {
                        label: item['tag'],
                        value: item['post_id']
                    };
                }));
            }
        });
    },
    'select': function (item) {
        $('input[name=\'filter_tag\']').val(item['label']);
    }
});

//--></script>
<script type="text/javascript"><!--
// Category
$('select[name=\'filter_category\']').autocomplete({
    'source': function (request, response) {
        $.ajax({
            url: '{{category_autocomplete}}&filter_category=' + encodeURIComponent(request),
            dataType: 'json',
            success: function (json) {
                response($.map(json, function (item) {
                    return {
                        label: item['title'],
                        value: item['category_id']
                    };
                }));
            }
        });
    },
    'select': function (item) {
        $('select[name=\'filter_category\']').val('');

        $('#post-category' + item['value']).remove();

        $('#post-category').append('<div id="post-category' + item['value'] + '"><i class="fa fa-minus-circle"></i> ' + item['label'] + '<input type="hidden" name="post_category[]" value="' + item['value'] + '" /></div>');
    }
});

$('#post-category').delegate('.fa-minus-circle', 'click', function () {
    $(this).parent().remove();
});

$('#post-filter').delegate('.fa-minus-circle', 'click', function () {
    $(this).parent().remove();
});
//--></script>
<script src="view/javascript/jquery/datetimepicker/bootstrap-datetimepicker.min.js" type="text/javascript"></script>
<link href="view/javascript/jquery/datetimepicker/bootstrap-datetimepicker.min.css" type="text/css" rel="stylesheet" media="screen" />
<script type="text/javascript"><!--
$('.date').datetimepicker({
    pickTime: false
});
//--></script>
{{footer}}