{% extends 'admin/master.html' %}
{% import 'admin/lib.html' as lib with context %}
{% import 'admin/actions.html' as actionslib with context %}

{% block body %}
    {% block breadcrums %}
    <ul class="breadcrumb">
        <li>
            <a href="{{ get_dir_url('.index', path=None) }}">{{ _gettext('Root') }}</a>
        </li>
        {% for name, path in breadcrumbs[:-1] %}
        <li>
            <a href="{{ get_dir_url('.index', path=path) }}">{{ name }}</a>
        </li>
        {% endfor %}
        {% if breadcrumbs %}
        <li>
            <a href="{{ get_dir_url('.index', path=breadcrumbs[-1][1]) }}">{{ breadcrumbs[-1][0] }}</a>
        </li>
        {% endif %}
    </ul>
    {% endblock %}

    {% block file_list_table %}
    <table class="table table-striped table-bordered model-list">
        <thead>
            <tr>
                {% block list_header scoped %}
                {% if actions %}
                <th class="list-checkbox-column">
                    <input type="checkbox" name="rowtoggle" class="action-rowtoggle" />
                </th>
                {% endif %}
                <th class="col-md-1">&nbsp;</th>
                <th>{{ _gettext('Name') }}</th>
                <th>{{ _gettext('Size') }}</th>
                {% endblock %}
            </tr>
        </thead>
        {% for name, path, is_dir, size, date in items %}
        <tr>
            {% block list_row scoped %}
            {% if actions %}
            <td>
                {% if not is_dir %}
                <input type="checkbox" name="rowid" class="action-checkbox" value="{{ path }}" />
                {% endif %}
            </td>
            {% endif %}
            <td>
                {% block list_row_actions scoped %}
                {% if admin_view.can_rename and path and name != '..' %}
                <a class="icon" href="{{ get_url('.rename', path=path) }}">
                        <i class="glyphicon glyphicon-pencil"></i>
                </a>
                {% endif %}
                {%- if admin_view.can_delete and path -%}
                    {% if is_dir %}
                        {% if name != '..' and admin_view.can_delete_dirs %}
                        <form class="icon" method="POST" action="{{ get_url('.delete') }}">
                            <input type="hidden" name="path" value="{{ path }}"></input>
                            <button onclick="return confirm('{{ _gettext('Are you sure you want to delete \\\'%(name)s\\\' recursively?', name=name) }}')">
                                <i class="glyphicon glyphicon-remove"></i>
                            </button>
                        </form>
                        {% endif %}
                    {% else %}
                    <form class="icon" method="POST" action="{{ get_url('.delete') }}">
                        <input type="hidden" name="path" value="{{ path }}"></input>
                        <button onclick="return confirm('{{ _gettext('Are you sure you want to delete \\\'%(name)s\\\'?', name=name) }}')">
                            <i class="glyphicon glyphicon-trash"></i>
                        </button>
                    </form>
                    {% endif %}
                {%- endif -%}
                {% endblock %}
            </td>
            {% if is_dir %}
            <td colspan="2">
                <a href="{{ get_dir_url('.index', path)|safe }}">
                    <i class="glyphicon glyphicon-folder-close"></i> <span>{{ name }}</span>
                </a>
            </td>
            {% else %}
            <td>
                {% if admin_view.can_download %}
                <a href="{{ get_file_url(path)|safe }}">{{ name }}</a>
                {% else %}
                {{ name }}
                {% endif %}
            </td>
            <td>
                {{ size|filesizeformat }}
            </td>
            {% endif %}
            {% endblock %}
        </tr>
        {% endfor %}
    </table>
    {% endblock %}
    {% block toolbar %}
    <div class="btn-toolbar">
        {% if admin_view.can_upload %}
        <div class="btn-group">
            <a class="btn btn-default btn-large" href="{{ get_dir_url('.upload', path=dir_path) }}">{{ _gettext('Upload File') }}</a>
        </div>
        {% endif %}
        {% if admin_view.can_mkdir %}
        <div class="btn-group">
            <a class="btn btn-default btn-large" href="{{ get_dir_url('.mkdir', path=dir_path) }}">{{ _gettext('Create Directory') }}</a>
        </div>
        {% endif %}
        {% if actions %}
        <div class="btn-group">
            {{ actionslib.dropdown(actions, 'dropdown-toggle btn btn-default btn-large') }}
        </div>
        {% endif %}
    </div>
    {% endblock %}
    {% block actions %}
    {{ actionslib.form(actions, get_url('.action_view')) }}
    {% endblock %}
{% endblock %}

{% block tail %}
    {{ super() }}
    {{ actionslib.script(_gettext('Please select at least one file.'),
                      actions,
                      actions_confirmation) }}
{% endblock %}
