{% extends "page.html" %}

{% block styles %}
  {{ super() }}
  {% asset 'feedback/feedback-management-comments-css' %}
{% endblock %}

{% block breadcrumb_content %}
  {{ super() }}
  <li class="active"><a href="{{ h.url_for('management.comments') }}">{{ _('Management Comments') }}</a></li>
{% endblock %}

{% block title %}{{ _('Management Comments') }} - CKAN{% endblock %}

{% block primary %}
  <article class="module">
    <header class="module-content page-header">
      <div class="top-centered-content">
        {% block select_categories %}
          <span>
            <h4>{{ _('Category') }}</h4>
            {% for category in categories %}
              <input type="checkbox" class="category-checkbox" id="{{ category.value }}" name="{{ category.value }}" onclick="refreshTable()" checked>
              <label for="{{ category.value }}" class="normal-font-weight middle-vertical-aligned">{{ _(category.value) }}</label>
            {% endfor %}
          </span>
        {% endblock %}
        {% block select_status %}
          <span>
            <h4>{{ _('Status') }}</h4>
            <input type="checkbox" id="waiting" name="waiting" onclick="refreshTable()" checked>
            <label for="waiting" class="normal-font-weight middle-vertical-aligned">{{ _('Waiting') }}</label>
            <input class="spaced-left" type="checkbox" id="approval" name="approval" onclick="refreshTable()" checked>
            <label for="approval" class="normal-font-weight middle-vertical-aligned">{{ _('Approved') }}</label>
          </span>
        {% endblock %}
      </div>
    </header>
    <div class="module-content">
      <form id="comments-form" method="post">
        <div class="tab">
          <input id="menu1" type="radio" name="tab-menu" value="utilization-comments" onclick="refreshTable()" {% if tab == 'utilization-comments' %}checked{% endif %}>
          <label class="tab-menu" for="menu1">{{ _('Utilization Comments') }}</label>
          <input id="menu2" type="radio" name="tab-menu" value="resource-comments" onclick="refreshTable()" {% if tab == 'resource-comments' %}checked{% endif %}>
          <label class="tab-menu" for="menu2">{{ _('Resource Comments') }}</label>
          <div class="tab-contents" id="menu1">
            {% block result_utilization_comments_table %}
              <h4 class="bottom-centered-content" id="data-count">
                {{ _('Results: ') }}
                <span id="utilization-comments-results-count">{{ utilization_comments|length }}</span>
              </h4>
              <span class="bottom-centered-content right-text">
                <button class="btn btn-primary" type="button" onclick="runBulkAction('/management/approve_bulk_utilization_comments')">{{ _('Bulk Approval')}}</button>
                <button class="btn btn-primary" type="button" onclick="runBulkAction('/management/delete_bulk_utilization_comments')">{{ _('Bulk Delete')}}</button>
              </span>
              <table class="table table-striped table-bordered table-condensed table-toggle-more bottom-centered-content" id="utilization-comments-table">
                <thead class="table-header">
                  <tr>
                    <th class="small-column">
                      <input type="checkbox" id="utilization-comments-checkbox-all" name="utilization-comments-checkbox-all" />
                    </th>
                    <th class="medium-column">{{ _('Comments Body') }}</th>
                    <th class="medium-column">{{ _('Utilization Title') }}</th>
                    <th class="medium-column">{{ _('Organization') }}</th>
                    <th class="medium-column">{{ _('Dataset') }}</th>
                    <th class="medium-column">{{ _('Resource') }}</th>
                    <th class="medium-column">{{ _('Category') }}</th>
                    <th class="small-column">{{ _('Created') }}</th>
                    <th class="medium-column">{{ _('Status') }}</th>
                  </tr>
                </thead>
                <tbody>
                  {% for row in utilization_comments %}
                    <tr>
                      <td class="small-column">
                        <input type="checkbox" id="utilization-comments-checkbox-{{ row.id }}" name="utilization-comments-checkbox" value="{{ row.id }}" />
                      </td>
                      <td class="left-aligned-text">
                        <a href="{{ h.url_for('utilization.details', utilization_id=row.utilization_id) }}">{{ row.content|truncate(20) }}</a>
                      </td>
                      <td>
                        <a href="{{ h.url_for('utilization.details', utilization_id=row.utilization_id) }}">{{ row.utilization.title|truncate(20) }}</a>
                      </td>
                      <td>
                        {{ h.get_organization(row.utilization.resource.package.owner_org).display_name|truncate(20) }}
                      </td>
                      <td>
                        <a href="{{ url_for('dataset.search') }}{{ row.utilization.resource.package.name }}">{{ row.utilization.resource.package.title|truncate(20) }}</a>
                      </td>
                      <td>
                        <a href="{{ h.url_for('dataset.search') }}{{ row.utilization.resource.package.name }}/resource/{{ row.utilization.resource.id }}">{{ row.utilization.resource.name|truncate(20) }}</a>
                      </td>
                      <td class="category-column" data-category="{{ row.category.value}}">{{ _(row.category.value) }}</td>
                      <td>{{ row.created.strftime('%Y/%m/%d') }}</td>
                      {% if row.approval == True %}
                        <td data-approval="true">{{ _('Approved') }}</td>
                      {% else %}
                        <td data-waiting="true">{{ _('Waiting') }}</td>
                      {% endif %}
                    </tr>
                  {% endfor %}
                </tbody>
              </table>
            {% endblock %}
          </div>
          <div class="tab-contents" id="menu2">
            {% block result_resource_comments_table %}
              <h4 class="bottom-centered-content" id="data-count">
                {{ _('Results: ') }}
                <span id="resource-comments-results-count">{{ resource_comments|length }}</span>
              </h4>
              <span class="bottom-centered-content right-text">
                <button class="btn btn-primary" id="bulk-approval-button" type="button" onclick="runBulkAction('/management/approve_bulk_resource_comments')">{{ _('Bulk Approval')}}</button>
                <button class="btn btn-primary" type="button" onclick="runBulkAction('/management/delete_bulk_resource_comments')">{{ _('Bulk Delete')}}</button>
              </span>
              <table class="table table-striped table-bordered table-condensed table-toggle-more bottom-centered-content" id="resource-comments-table">
                <thead class="table-header">
                  <tr>
                    <th class="small-column">
                      <input type="checkbox" id="resource-comments-checkbox-all" name="resource-comments-checkbox-all" />
                    </th>
                    <th class="medium-column">{{ _('Comments Body') }}</th>
                    {% if h.is_enabled_rating() %}
                      <th class="medium-column">{{ _('Rating') }}</th>
                    {% endif %}      
                    <th class="medium-column">{{ _('Organization') }}</th>
                    <th class="medium-column">{{ _('Dataset') }}</th>
                    <th class="medium-column">{{ _('Resource') }}</th>
                    <th class="medium-column">{{ _('Category') }}</th>
                    <th class="small-column">{{ _('Created') }}</th>
                    <th class="medium-column">{{ _('Status') }}</th>
                  </tr>
                </thead>
                <tbody>
                  {% for row in resource_comments %}
                    <tr>
                      <td class="small-column">
                        <input type="checkbox" id="resource-comments-checkbox-{{ row.id }}" name="resource-comments-checkbox" value="{{ row.id }}" />
                      </td>
                      <td class="left-aligned-text">
                        <a href="{{ h.url_for('resource_comment.comment', resource_id=row.resource_id) }}">{{ row.content|truncate(20) if row.content }}</a>
                      </td>
                      {% if h.is_enabled_rating() %}
                        <td>
                          {{ row.rating if row.rating }}
                        </td>
                      {% endif %}
                      <td>
                        {{ h.get_organization(row.resource.package.owner_org).display_name|truncate(20) }}
                      </td>
                      <td>
                        <a href="{{ url_for('dataset.search') }}{{ row.resource.package.name }}">{{ row.resource.package.title|truncate(20) }}</a>
                      </td>
                      <td>
                        <a href="{{ h.url_for('dataset.search') }}{{ row.resource.package.name }}/resource/{{ row.resource.id }}">{{ row.resource.name|truncate(20) }}</a>
                      </td>
                      <td class="category-column" data-category="{{ row.category.value}}">{{ _(row.category.value) }}</td>
                      <td>{{ row.created.strftime('%Y/%m/%d') }}</td>
                      {% if row.approval == True %}
                        <td data-approval="true">{{ _('Approved') }}</td>
                      {% else %}
                        <td data-waiting="true">{{ _('Waiting') }}</td>
                      {% endif %}
                    </tr>
                  {% endfor %}
                </tbody>
              </table>
            {% endblock %}
          </div>
        </div>
      </form>
    </div>
  </article>
{% endblock %}

{% block secondary %}{% endblock %}

{%- block scripts %}
  {{ super() }}
  {% asset 'feedback/feedback-management-comments-js' %}
{% endblock %}