{% macro filter_options(btn_class='dropdown-toggle') %}
    <a class="{{ btn_class }}" data-toggle="dropdown" href="javascript:void(0)">
        {{ _gettext('Add Filter') }}<b class="caret"></b>
    </a>
    <ul class="dropdown-menu field-filters">
        {% for k in filter_groups %}
        <li>
            <a href="javascript:void(0)" class="filter" onclick="return false;">{{ k }}</a>
        </li>
        {% endfor %}
    </ul>
{% endmacro %}

{% macro filter_form() %}
    <form id="filter_form" method="GET" action="{{ return_url }}">
        <div class="pull-right">
            <button type="submit" class="btn btn-primary" style="display: none">{{ _gettext('Apply') }}</button>
            {% if active_filters %}
            <a href="{{ clear_search_url }}" class="btn">{{ _gettext('Reset Filters') }}</a>
            {% endif %}
        </div>

        <table class="filters">
            {%- for n, values in enumerate(active_filters) -%}
            <tr>
                {% set idx, value = values %}
                {% set filter = filters[idx] %}
                {% set filter_arg = admin_view.get_filter_arg(idx, filter) %}
                <td>
                    <a href="javascript:void(0)" class="btn remove-filter" title="{{ _gettext('Remove Filter') }}">
                        <span class="close-icon">&times;</span>&nbsp;{{ filter.name }}
                    </a>
                </td>
                <td>
                    <select class="filter-op" data-role="select2">
                        {% for op in filter_groups[filter.name] %}
                        <option value="{{ op['arg'] }}"{% if idx == op['index'] %} selected="selected"{% endif %}>{{ op['operation'] }}</option>
                        {% endfor %}
                    </select>
                </td>
                <td>
                    {%- if filter.options -%}
                    <select name="flt{{n}}_{{ filter_arg }}" class="filter-val" data-role="select2">
                        {%- for d in filter.options %}
                        <option value="{{ d[0] }}"{% if value == d[0] %} selected{% endif %}>{{ d[1] }}</option>
                        {%- endfor %}
                    </select>
                    {%- else -%}
                        <input name="flt{{n}}_{{ filter_arg }}" type="text" value="{{ value or '' }}" class="filter-val"{% if filter.data_type %} data-role="{{ filter.data_type }}"{% endif %} {% if filter.data_type == "datepicker" %}data-date-format="YYYY-MM-DD"{% elif filter.data_type == "datetimepicker" %}data-date-format="YYYY-MM-DD HH:mm:ss"{% elif filter.data_type == "timepicker" %}data-date-format="HH:mm:ss"{% endif %}></input>
                    {%- endif -%}
                </td>
            </tr>
            {%- endfor -%}
        </table>
    </form>
    <div class="clearfix"></div>
{% endmacro %}

{% macro search_form(input_class="span2") %}
<form method="GET" action="{{ return_url }}" class="search-form">
    {% if sort_column is not none %}
    <input type="hidden" name="sort" value="{{ sort_column }}"></input>
    {% endif %}
    {% if sort_desc %}
    <input type="hidden" name="desc" value="{{ sort_desc }}"></input>
    {% endif %}
    {% if search %}
    <div class="input-append">
            <input type="text" name="search" value="{{ search }}" class="{{ input_class }}" placeholder="{{ _gettext('Search') }}"></input>
            <a href="{{ clear_search_url }}" class="clear add-on">
                <i class="icon-remove"></i>
            </a>
    </div>
    {% else %}
    <div>
        <input type="text" name="search" value="" class="{{ input_class }}" placeholder="{{ _gettext('Search') }}"></input>
    </div>
    {% endif %}
</form>
{% endmacro %}
