{% extends base_template %}

{% block content %}
  <div class="row">
    <div class="col-xs-12">
      <div class="btn-toolbar">
        {%- for action_items in module.get_grouped_actions().values() %}
          <div class="btn-group">
            {%- for item in action_items %}
              {{ item.render() }}
            {%- endfor %}
          </div>
        {%- endfor %}

        <div class="btn-group">
          {%- set EXCEL_ACTIONS = module.excel_export_actions %}
          {%- set EXCEL_SUPPORT_IMPORT = module.EXCEL_IMPORT_EXPORT and g.is_manager %}

          {%- if EXCEL_ACTIONS or EXCEL_SUPPORT_IMPORT or module.export_to_xls %}
            {%- set BUTTON_CLASS = '' %}
            <a class="btn btn-default dropdown-toggle" data-toggle="dropdown" href="#-">Excel<span class="caret"></span></a>
            <ul class="dropdown-menu">
            <li>
          {%- else %}
            {%- set BUTTON_CLASS = ' btn btn-default' %}
          {%- endif %}
          {%- if module.export_to_xls %}
            <a class="datatable-export{{ BUTTON_CLASS }}" data-toggle="dropdown" href="{{ url_for('.export_to_xls') }}"><i
                class="fa fa-align-justify"></i>{{ _("Export to Excel") }}</a>
          {%- endif %}
          {%- if EXCEL_ACTIONS or EXCEL_SUPPORT_IMPORT %}
            </li>
            {%- for action_url, label in EXCEL_ACTIONS %}
              <li>
                <a class="datatable-export" data-toggle="dropdown" href="{{ action_url }}"><i
                    class="fa fa-align-justify"></i>{{ label }}</a>
              </li>
            {%- endfor %}

            {%- if EXCEL_SUPPORT_IMPORT %}
              <li class="divider"></li>
              <li><a href="#modal-excel-upload" data-toggle="modal"><i
                  class="fa fa-upload"></i>{{ _("Import from Excel") }}</a></li>
              <li class="divider"></li>
              <li><a href="{{ url_for('.export_to_xls', import_template=1) }}"
                  title="{{ _("Download a file suitable for importing new objects") }}"><i
                  class="fa fa-download"></i>{{ _("Download import template") }}</a></li>
            {%- endif %}
            </ul>
          {%- endif %}

          {%- if EXCEL_SUPPORT_IMPORT %}
            <div class="modal fade" id="modal-excel-upload" role="dialog" aria-hidden="true">
              <form method="POST" action="{{ url_for(".import_xls_file") }}" enctype="multipart/form-data"
                  style="margin-bottom: 0;">
                <div class="modal-dialog">
                  <div class="modal-content">
                    <div class="modal-header">
                      <button class="close" data-dismiss="modal">&times;</button>
                      <h3>{{ _("Upload Excel file") }}</h3>
                    </div>

                    <div class="modal-body">
                      {{ csrf.field() }}
                      <input type="file" name="file"/>
                    </div>

                    <div class="modal-footer">
                      <button data-dismiss="modal" class="btn">{{ _("Cancel") }}</button>
                      <button class="btn btn-primary" type="submit" name="action"
                          value="upload">{{ _("Upload") }}</button>
                    </div>
                  </div>
                </div>
              </form>
            </div>
          {%- endif %}
        </div>

        {%- if module.export_xml %}
          <div class="btn-group">
            <a class="btn btn-default" href="{{ url_for('.export_xml') }}"><i>
              <small>&lt;/&gt;</small>
            </i>&nbsp;{{ _("Export XML") }}</a>
          </div>
        {% endif %}

      </div>
    </div>
  </div> <!-- row -->
  <hr/>

  <div class="row">
    <div class="col-xs-12">
      {{ rendered_table }}
    </div>
  </div>

{% endblock %}
