{% extends "fretboard/base.html" %}

{% load paginator truncatechars typogrify_tags humanize fretboard_tags timesince_filters cache %}

{% block title %}{{ forum_name }}: {% endblock%}

{% block extrahead %}
{{ block.super }}
<style>
#forum_search {border-bottom:2px solid #ddd; margin-bottom:.5em }
#forum_search p {float:left; width:33.3%}
#forum_search p.note {float:none; clear:both;; width:100%}
#forum_search p input {width:90%}
#forum_search input[type=submit] {margin-top:1.6em}
mark {background:#ffc}
#content-main #forum_search {display:block}
</style>
{% endblock %}

{% block extrascript %}
<script src="{{ MEDIA_URL }}js/jquery/highlight.js"></script>
<script>
  $(document).ready(function() {
    $("#results").highlight("{{ query }}",  { element: 'mark', className: '' });
  });
</script>
{% endblock %}

{% block content %}
  <form action="" method="get" id="forum_search" class="boxedform">
    {{ filter.form.as_p }}
    {{ postfilter.form.as_p }}
    <p class="submit">
      <input type="submit" value="search">
    </p>
    <p class="note meta">Note: Topic search is much faster. Probably works better, too.</p>
  </form>
  <h1>
    <a href="/forum/">Forums:</a> 
      {{ search_type }} Search {% if query %}for  {{ query }}{% endif %}
  </h1>

{% ifequal search_type "Post" %}
<div id="results">
  {% for obj in object_list %}
  {% ifchanged obj.topic %}
    <h2>
      <a href="{{ obj.post_url }}">
        {{ obj.topic.name }}
      </a>
    </h2>
  {% endifchanged %}
  <p>{{ obj.text_formatted|safe|striptags|truncatewords:40 }}</p>
  <hr>
    {% endfor %}
  </div>
  {% else %}
  
  {% if filter.data and filter.qs %}
    <div id="topic_list">
      {% for topic in object_list %}
        {% cache 240 't_list_x' topic.id topic.modified_int 'filters' 8 %}
          {% with topic.forum as t_forum %}
            <article>
              <section class="t">
                <address class="author">{{topic.author }}</address>
                <h2>
                  <a href="{{ topic.get_absolute_url }}">
                    {{ topic.name|typogrify }}
                  </a>
                </h2>
                <!--googleoff: all-->
                  <p class="meta">
                    {% if topic.created %}
                      <time datetime="{{ topic.created|date:"Y-m-d\TH:i:00" }}">
                        {{ topic.created|short_timesince }} ago</time>
                    {% endif %}
                    in <a href="/forum/{{ t_forum.slug }}/">{{ t_forum.name }}</a>
                  </p>
                <!--googleon: all-->
              </section><!-- /.t -->
              <section class="last">
                {% with topic.get_latest_post as latest %}
                  {% topic_quick_links topic latest last_seen_time %}
                  {% if topic.post_count > 1 %}
                    <p class="clear">
                      <span class="meta">
                        {{ latest.author_name|title|truncatechars:"30" }} updated
                      </span>
                      <time datetime="{{ latest.post_date|date:"Y-m-d\TH:i:00" }}" title="{{ latest.post_date }}">
                        {{ latest.post_date|naturaltime }}
                      </time>
                    </p>
                  {% endif %}
                {% endwith %}
              </section>
            </article>
          {% endwith %}
        {% endcache %}
      {% endfor %}
    </div>
  {% endif %}
{% endifequal %}
{% endblock %}
