<% provide :title, t('.title') %>
<div id="forum">
  <div id="search" style="margin-bottom: 1em;">
    <%= form_tag({:action => "search"}, :method => :get) do %>
      <%= text_field_tag "query", params[:query], :size => 40 %>
      <%= submit_tag t('.search')%>
    <% end %>
  </div>

  <table class="nowrap highlightable" width="100%">
    <thead>
      <tr>
        <th><%= t('.post_title') %></th>
        <th><%= t('.created_by') %></th>
        <th><%= t('.updated_by') %></th>
        <th><%= t('.updated') %></th>
        <th><%= t('.responses') %></th>
      </tr>
    </thead>
    <tbody>
      <% @forum_posts.each do |fp| %>
        <%= content_tag :tr, :class => cycle('even', 'odd') do %>
          <td class="wrap full">
            <% if @current_user.is_a?(User) && fp.updated_at > @current_user.last_forum_topic_read_at %>
              <span class="forum-topic unread-topic"><% if fp.is_sticky? %><%= t('.sticky') %>: <% end %><%= link_to h(fp.title), :action => "show", :id => fp.id %></span>
            <% else %>
              <span class="forum-topic"><% if fp.is_sticky? %><%= t('.sticky') %>: <% end %><%= link_to h(fp.title), :action => "show", :id => fp.id %></span>
            <% end %>

            <% if fp.response_count > 30 %>
              <%= link_to t('.last'), {:action => "show", :id => fp.id, :page => (fp.response_count / 30.0).ceil}, :class => "last-page" %>
            <% end %>

            <% if fp.is_locked? %>
              <span class="locked-topic"><%= t('.is_locked') %></span>
            <% end %>
          </td>
          <td><%= h fp.author %></td>
          <td><%= h fp.last_updater %></td>
          <td><%= timeago fp.updated_at %></td>
          <td><%= fp.response_count %></td>
        <% end %>
      <% end %>
    </tbody>
  </table>

  <div id="paginator">
    <%= will_paginate(@forum_posts) %>
  </div>

  <% content_for :subnavbar do %>
    <li><%= link_to t('.new'), :action => "new" %></li>
    <% unless @current_user.is_anonymous? %>
      <li><%= link_to_function t('.mark'), "Forum.mark_all_read()" %></li>
    <% end %>
    <li><%= link_to t('.help'), help_path("forum") %></li>
  <% end %>

  <div id="preview" style="display: none; margin: 1em 0;">
  </div>

  <div id="reply" style="display: none;">
    <%= form_tag({:action => "create"}, :level => :member) do %>
      <%= render "shared/filter_spam" %>
      <%= hidden_field "forum_post", "parent_id", :value => params["parent_id"] %>
      <table>
        <tr>
          <td><label for="forum_post_title"><%= t('.post_title') %></label></td>
          <td><%= text_field "forum_post", "title", :size => 60 %></td>
        </tr>
        <tr>
          <td colspan="2"><%= text_area "forum_post", "body", :rows => 20, :cols => 80 %></td>
        </tr>
        <tr>
          <td colspan="2"><%= submit_tag t('.post') %><%= submit_to_remote "preview", t('.preview'), :url => {:action => "preview"}, :update => "preview", :method => :get, :success => "$('preview').show()" %></td>
        </tr>
      </table>
    <% end %>
  </div>
</div>
