{% extends theme('admin/master.html') %}
{% import theme('admin/lib.html') as lib with context %}
{% import theme( 'admin/model/layout.html') as model_layout with context %}
{% import theme('admin/actions.html') as actionlib with context %}

{% block head %}
    {{ super() }}
    <link href="{{ theme_static('select2/select2.css') }}" rel="stylesheet">
    <link href="{{ theme_static('datetimepicker/bootstrap-datetimepicker.css') }}" rel="stylesheet">
{% endblock %}

{% block body %}
    {% block model_menu_bar %}
    <ul class="nav nav-tabs">
	<li class="active">
	    <a href="javascript:void(0)">{{ _gettext('List') }} ({{ count }})</a>
	</li>
	{% if admin_view.can_create %}
	<li>
	    <a href="{{ url_for('.create_view', url=return_url) }}">{{ _gettext('Create') }}</a>
	</li>
	{% endif %}

	{% if filter_groups %}
	<li class="dropdown">
	    {{ model_layout.filter_options() }}
	</li>
	{% endif %}

	{% if actions %}
	<li class="dropdown">
	    {{ actionlib.dropdown(actions) }}
	</li>
	{% endif %}

	{% if search_supported %}
	<li>
	    {{ model_layout.search_form() }}
	</li>
	{% endif %}
    </ul>
    {% endblock %}

    {% if filter_groups %}
	{{ model_layout.filter_form() }}
	<div class="clearfix"></div>
    {% endif %}

    {% block model_list_table %}
    <table class="table table-striped table-bordered model-list table-condensed table-hover">
	<thead>
	    <tr>
		{% block list_header scoped %}
		    {% if actions %}
		    <th class="span1">
			<input type="checkbox" name="rowtoggle" class="action-rowtoggle" />
		    </th>
		    {% endif %}
		    {% block list_row_actions_header %}
		    <th class="span1">&nbsp;</th>
		    {% endblock %}
		    {% set column = 0 %}
		    {% for c, name in list_columns %}
		    <th>
			{% if admin_view.is_sortable(c) %}
			    {% if sort_column == column %}
				<a href="{{ sort_url(column, True) }}">
				    {{ name }}
				    {% if sort_desc %}
					<i class="icon-chevron-up"></i>
				    {% else %}
					<i class="icon-chevron-down"></i>
				    {% endif %}
				</a>
			    {% else %}
				<a href="{{ sort_url(column) }}">{{ name }}</a>
			    {% endif %}
			{% else %}
			    {{ name }}
			{% endif %}
			{% if admin_view.column_descriptions.get(c) %}
			    <a class="icon-question-sign"
			       title="{{ admin_view.column_descriptions[c] }}"
			       href="javascript:void(0)" data-role="tooltip"
			    ></a>
			{% endif %}
		    </th>
		    {% set column = column + 1 %}
		    {% endfor %}
		{% endblock %}
	    </tr>
	</thead>
	{% for row in data %}
	<tr>
	    {% block list_row scoped %}
		{% if actions %}
		<td>
		    <input type="checkbox" name="rowid" class="action-checkbox" value="{{ get_pk_value(row) }}" />
		</td>
		{% endif %}
		<td>
		    {% block list_row_actions scoped %}
			{%- if admin_view.can_edit -%}
			<a class="icon" href="{{ url_for('.edit_view', id=get_pk_value(row), url=return_url) }}">
			    <i class="icon-pencil"></i>
			</a>
			{%- endif -%}
			{%- if admin_view.can_delete -%}
			<form class="icon" method="POST" action="{{ url_for('.delete_view', id=get_pk_value(row), url=return_url) }}">
			    <button onclick="return confirm('{{ _gettext('You sure you want to delete this item?') }}');">
				<i class="icon-trash"></i>
			    </button>
			</form>
			{%- endif -%}
		    {% endblock %}
		</td>
		{% for c, name in list_columns %}
		<td>{{ get_value(row, c) }}</td>
		{% endfor %}
	    {% endblock %}
	</tr>
	{% else %}
	<tr>
	    <td colspan="999">
		{% block empty_list_message %}
		<div class="text-center">
		    {{ admin_view.get_empty_list_message() }}
		</div>
		{% endblock %}
	    </td>
	</tr>
	{% endfor %}
    </table>
    {{ lib.pager(page, num_pages, pager_url) }}
    {% endblock %}

    {{ actionlib.form(actions, url_for('.action_view')) }}
{% endblock %}

{% block tail %}
    {{ super() }}
    <script src="{{ theme_static('datetimepicker/bootstrap-datetimepicker.js') }}"></script>
    <script src="{{ theme_static('admin/js/form.js') }}"></script>
    <script src="{{ theme_static('admin/js/filters.js') }}"></script>

    {{ actionlib.script(_gettext('Please select at least one model.'),
		      actions,
		      actions_confirmation) }}

    <script language="javascript">
	(function($) {
	    $('[data-role=tooltip]').tooltip({
		html: true,
		placement: 'bottom'
	    });
	    {% if filter_groups is not none and filter_data is not none %}
		var filter = new AdminFilters(
		    '#filter_form', '.field-filters',
		    {{ admin_view._get_filter_dict()|tojson|safe }},
		    {{ filter_data|tojson|safe }},
		    {{ filter_types|tojson|safe }}
		);
	    {% endif %}
	})(jQuery);
    </script>
{% endblock %}
