{% extends g.theme.master %}

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

{% block header %}{{app.config.options.mount_label}} Admin Forums{% endblock %}

{% block content %}
<form method="POST" action="update_forums" enctype="multipart/form-data">
  <table id="forums">
    <thead>
      <tr>
        <th></th>
        <th>Forum</th><th>Topics</th><th>Posts</th><th>Last Post</th>
        <th></th>
      </tr>
    </thead>
    <tbody>
      {% for forum in app.forums %}
      <tr class="{{loop.index0%2 and ' even' or ''}}">
        <td>
          <div class="editable viewing">
            <span class="viewer">
              {% if forum.icon %}
                <img src="{{forum.url()}}/icon"/>
              {% else %}
                <img src="{{g.forge_static('images/project_default.png')}}"/>
              {% endif %}
            </span>
            <span class="editor">{{lib.file_field('forum-%s.icon' % loop.index0, '')}}</span>
          </div>
        </td>
        <td>
          <div class="editable viewing">
            <span class="viewer"><a href="{{forum.url()}}">{{h.really_unicode(forum.name)}}</a></span>
            <span class="editor">
              {{lib.text_field('forum-%s.name' % loop.index0, 'Forum Title', h.really_unicode(forum.name))}}
            </span>
          </div>
          <div class="editable viewing">
            <span class="viewer">{{h.really_unicode(forum.shortname)}}</span>
            <span class="editor">
              {{lib.text_field('forum-%s.shortname' % loop.index0, 'Forum Short Name', h.really_unicode(forum.shortname))}}
            </span>
          </div>
          <div class="editable viewing">
            <div class="viewer">{{g.markdown.convert(forum.description)|safe}}</div>
            <span class="editor multiline">
              {{lib.text_area('forum-%s.description' % loop.index0, 'Description', h.really_unicode(forum.description))}}
            </span>
          </div>
          {% if forum.subforums %}
            <b>Subforums:</b>
            {% for sf in forum.subforums %}
              <span>
                {% if loop.index1 != 0 %}, {% endif %}
                <a href="{{sf.url()}}">{{sf.name}}</a>
              </span>
            {% endfor %}
          {% endif %}
        </td>
        <td>{{forum.num_topics}}</td>
        <td>{{forum.num_posts}}</td>
        <td>{{lib.post_summary(forum.last_post)}}</td>
        <td>
          <input name="{{'forum-%s.id' % loop.index0}}" type="hidden" value="{{forum._id}}"/>
          {% if forum.deleted %}
            <input type="submit" name="{{'forum-%s.undelete' % loop.index0}}" value="Undelete"/><br/>
          {% else %}
            <input type="submit" name="{{'forum-%s.delete' % loop.index0}}" value="Delete"/><br/>
          {% endif %}
        </td>
      </tr>
      {% endfor %}
    </tbody>
  </table>
  <div class="grid-19"><input type="button" id="add_forum" value="Add another forum"></div>
</form>
{{c.add_forum.display(method='POST',action='add_forum',app=app, value=add_forum)}}
{% endblock %}

{% block extra_js %}
  <script type="text/javascript">
    $(function() {
      $("#add_forum").click(function(){
        $("#add_forum_form").show();
        $(this).hide();
        return false;
      });
      $("#add_forum_cancel").click(function(){
        $("#add_forum_form").hide();
        $("#add_forum").show();
        return false;
      });
    });
  </script>
{% endblock %}