{% 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()+'admin/'+c.app.config.options.mount_point+'/add_forum',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 %}
  {% for forum in forums %}
    {% if not forum.deleted or h.has_access(c.app, 'configure')() %}
      <div class="discussion_forum grid-9">
        <strong class="forum_name">{{forum.name}}:</strong>
        <br>{{forum.description}}<br>&nbsp;<br>
        {% if forum.deleted %}
          <div class="notice">This forum has been deleted and is not visible to non-admin users</div>
        {% endif %}
        {% for thread in threads[forum._id] %}
          {% if loop.index0 == 5 %}
            <a href="{{forum.url()}}">More</a>
          {% else %}
            {{thread.num_replies}} posts to <a href="{{thread.url()}}">{{h.text.truncate(h.really_unicode(thread.subject or '(no subject)'),75)}}</a><br>
          {% endif %}
        {% endfor %}
      </div>
      {% set visible = visible + 1 %}
      {% if visible%2==0 %}
        <div class="clear">&nbsp;</div>
      {% endif %}
    {% endif %}
  {% endfor %}
{% 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 %}

{% block extra_css %}
<style type="text/css">
  .forum_name{
    font-size: 1.2em;
  }
</style>
{% endblock %}
