{% extends g.theme.master %}

{% block title %}{{c.project.name}} / {{c.app.config.options.mount_label}} / Forums{% endblock %}

{% block header %}{{c.app.config.options.mount_label}}{% endblock %}

{% block actions %}
  <a href="feed" class="follow" title="Follow"><b data-icon="{{g.icons['feed'].char}}" class="ico {{g.icons['feed'].css}}"></b></a>
{% endblock %}

{% if h.has_access(c.app, 'configure')() and (not hide_forum) %}
  {% block edit_box %}
    <div id="add_forum_form"{% if hide_forum %} style="display:none"{% endif %} class="editbox">
      {{c.add_forum.display(method='POST', action=c.project.url() + c.app.config.options.mount_point + '/add_forum_short', app=c.app, value=add_forum)}}
    </div>
  {% endblock %}
{% endif %}

{% block content %}
  {% if announcements %}
    <h3>Announcements</h3>
    {{c.announcements_table.display(value=announcements)}}
  {% endif %}
  {% set visible=0 %}
  <table id="discussion-forums">
    <thead>
      <tr>
        <th>FORUM</th>
        <th>LATEST POST</th>
        <th># TOPICS</th>
      </tr>
    </thead>
    <tbody>
    {% for forum in forums %}
      <tr>
        <td>
          <strong><a href="{{forum.url()}}">{{forum.name}}</a></strong><br>
          {{forum.description}}
          {% if forum.deleted %}
            <div class="notice">This forum has been deleted and is not visible to non-admin users</div>
          {% endif %}
        </td>
        <td>
          {% if forum.last_post %}
          <a href="{{forum.last_post.url()}}">{{h.text.truncate(h.really_unicode(forum.last_post.subject or '(no subject)'),75)}}</a><br>
          by <a href="{{forum.last_post.author().url()}}">{{forum.last_post.author().display_name}}</a><br>
          {{h.ago(forum.last_post.mod_date)}}
          {% else %}
          No posts yet
          {% endif %}
        </td>
        <td class="count">
          <span class="forum-topic-count">{{forum.num_topics}}</span>
        </td>
      </tr>
    {% else %}
      <tr>
        <td colspan="3">No forums exist.</td>
      </tr>
    {% endfor %}
    </tbody>
  </table>
{% endblock %}

{% block extra_js %}
  {% if h.has_access(c.app, 'configure')() %}
    <script type="text/javascript">
      $(function() {
        $("#add_forum").click(function(){
          $("div.editbox").show();
          return false;
        });
        $("#add_forum_cancel").click(function(){
          $("div.editbox").hide();
          return false;
        });
      });
    </script>
  {% endif %}
{% endblock %}
