<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:py="http://genshi.edgewall.org/">
  <xi:include href="discussion-macros.html"/>
  <xi:include href="admin.html"/>
  <head>
    <title>Discussion Forums</title>
  </head>

  <py:with vars="is_edit = discussion.forum.id and not req.args.submit">
    <body>
      <h2>Forums</h2>

      <form id="${is_edit and 'edit-forum-form' or 'add-forum-form'}" class="addnew" method="post" action="${panel_href()}">
        <fieldset>
          <legend>
            ${is_edit and 'Edit Forum:' or 'Add Forum:'}
          </legend>

          <div class="field">
            <label for="name">Name:</label><br/>
            <input type="text" id="name" name="name" value="${is_edit and discussion.name or None}"/><br/>
          </div>

          <div class="field">
            <label for="subject">Subject:</label><br/>
            <input type="text" id="subject" name="subject" value="${is_edit and discussion.subject or None}"/><br/>
          </div>

          <div class="field">
            <label for="description">Description:</label><br/>
            <input type="text" id="description" name="description" value="${is_edit and discussion.description or None}"/><br/>
          </div>

          <div class="field">
            <label for="moderators">Moderators:</label><br/>
            <py:choose>
              <select py:when="len(discussion.users)" id="moderators" name="moderators" multiple="on">
                <py:for each="user in discussion.users">
                  <py:choose>
                    <option py:when="is_edit and user in discussion.moderators" value="$user" selected="selected">$user</option>
                    <option py:otherwise="" value="$user">$user</option>
                  </py:choose>
                </py:for>
              </select>
              <input py:otherwise="" type="text" id="moderators" name="moderators" value="${discussion.moderators}"/>
            </py:choose><br/>
          </div>

          <py:choose>
            <div py:when="len(discussion.groups) > 1" class="group">
              <label for="group">Forum Group:</label><br/>
              <select id="group" name="group">
                <py:for each="group in discussion.groups">
                  <py:choose>
                    <option py:when="is_edit and user in discussion.moderators" value="${group.id}" selected="selected">${group.name}</option>
                    <option py:otherwise="" value="${group.id}">${group.name}</option>
                  </py:choose>
                </py:for>
              </select><br/>
            </div>
            <input py:otherwise="" type="hidden" name="group" value=""/>
          </py:choose>

          <div class="buttons">
            <input type="submit" name="submit" value="${is_edit and 'Edit' or 'Add'}"/>
            <input py:if="is_edit" type="button" name="cancel" value="Cancel" onclick="location.href = '${panel_href()}'"/>
            <input py:if="is_edit" type="hidden" name="forum" value="${discussion.forum.id}"/>
            <input type="hidden" name="discussion_action" value="${is_edit and 'post-edit' or 'post-add'}"/>
          </div>
        </fieldset>
      </form>

      <py:choose>
        <form py:when="len(discussion.forums)" method="post" action="${panel_href()}">
          <table id="forum-list" class="listing">
            <thead>
              <tr>
                <th class="sel">&nbsp;</th>
                ${sortable_th(discussion.order, discussion.direction, 'id', 'ID', panel_href())}
                ${sortable_th(discussion.order, discussion.direction, 'name', 'Name', panel_href())}
                ${sortable_th(discussion.order, discussion.direction, 'subject', 'Subject', panel_href())}
                ${sortable_th(discussion.order, discussion.direction, 'description', 'Description', panel_href())}
                ${sortable_th(discussion.order, discussion.direction, 'moderators', 'Moderators', panel_href())}
                <py:if test="len(discussion.groups) > 1">
                  ${sortable_th(discussion.order, discussion.direction, 'forum_group', 'Group', panel_href())}
                </py:if>
              </tr>
            </thead>
            <tbody>
              <py:for each="line, forum in enumerate(discussion.forums)">
                <tr class="${line % 2 and 'even' or 'odd'}">
                  <td class="sel">
                    <input type="checkbox" name="selection" value="${forum.id}"/>
                  </td>
                  <td class="id">
                    <div class="id">
                      <a href="${panel_href(forum.id)}">
                        <span>${forum.id}</span>
                      </a>
                    </div>
                  </td>
                  <td class="name">
                    <div class="name">
                      <a href="${panel_href(forum.id)}">
                        <span>${forum.name or '&nbsp;'}</span>
                      </a>
                    </div>
                  </td>
                  <td class="subject">
                    <div class="subject">
                      <a href="${panel_href(forum.id)}">
                        <span>${forum.subject or '&nbsp;'}</span>
                      </a>
                    </div>
                  </td>
                  <td class="description">
                    <div class="description">
                      <a href="${panel_href(forum.id)}">
                        <span>${forum.description or '&nbsp;'}</span>
                      </a>
                    </div>
                  </td>
                  <td class="moderators">
                    <div class="moderators">
                      <a href="${panel_href(forum.id)}">
                        <span>${forum.moderators or '&nbsp;'}</span>
                      </a>
                    </div>
                  </td>
                  <td py:if="len(discussion.groups) > 1" class="group">
                    <div py:for="group in discussion.groups" py:if="group.id == forum.group" class="group">
                      <a href="${panel_href(forum.id)}">
                        <span>${group.name}</span>
                      </a>
                    </div>
                  </td>
                </tr>
              </py:for>
            </tbody>
          </table>
          <div class="buttons">
            <input type="submit" name="remove" value="Remove selected items" />
            <input type="hidden" name="discussion_action" value="delete"/>
          </div>
        </form>
        <div py:otherwise="">
          <p class="help">As long as you don't add any items to the list, this
            field will remain completely hidden from the user interface.</p>
          <br style="clear: right"/>
        </div>
      </py:choose>
    </body>
  </py:with>
</html>
