Commit fc7e4519 authored by Sli's avatar Sli Committed by Skia

forum: use pure jinja for search bar

parent 68911749
......@@ -22,7 +22,7 @@
{% if not forum.is_category %}
<a class="ib button" href="{{ url('forum:new_topic', forum_id=forum.id) }}">{% trans %}New topic{% endtrans %}</a>
{% endif %}
{{ display_search_bar() }}
{{ display_search_bar(request) }}
</p>
{% if forum.children.exists() %}
<div>
......
......@@ -155,33 +155,12 @@
{{ m.mark_as_read(user) or "" }}
{% endmacro %}
{% macro display_search_bar() %}
{% macro display_search_bar(request) %}
<form class="search_bar" action="{{ url('forum:search') }}" method="GET">
<input type="text" id="forum_search_input" placeholder="{% trans %}Search{% endtrans %}" name="query"/>
<input type="checkbox" id="forum_search_order_date" class="sreach_check" name="order" value="date" checked> {% trans %}Order by date{% endtrans %}<br>
<input type="text" placeholder="{% trans %}Search{% endtrans %}" name="query" value="{{ request.GET.query|default('') }}"/>
<input type="checkbox" class="sreach_check" name="order" value="date" {% if request.GET.order|default("") == "date" or (request.GET.order|default("") == "" and request.GET.query|default("") == "") -%}
checked
{%- endif -%}> {% trans %}Order by date{% endtrans %}<br>
<input type="submit" class="search_bouton" value="{% trans %}Search{% endtrans %}"/>
<script type="text/javascript">
// Uncheck the order by date checkbox if previously unchecked
const searchParams = new URLSearchParams(window.location.search);
var waitForJQuery = setInterval(function () {
if (typeof $ != 'undefined'){
fillSearchBar();
clearInterval(waitForJQuery);
}
}, 10);
function fillSearchBar() {
if (searchParams.has('query')){
$('#forum_search_input').val(searchParams.get('query'));
}
if (
(!searchParams.has('order') && searchParams.has('query') )||
(searchParams.has('order') && searchParams.get('order') != 'date')
) {
$('#forum_search_order_date').removeAttr('checked');
clearInterval(waitForJQuery);
}
}
</script>
</form>
{% endmacro %}
......@@ -15,7 +15,7 @@
<p>
<a class="ib button" href="{{ url('forum:last_unread') }}">{% trans %}View last unread messages{% endtrans %}</a>
<a class="ib button" href="{{ url('forum:favorite_topics') }}">{% trans %}Favorite topics{% endtrans %}</a>
{{ display_search_bar() }}
{{ display_search_bar(request) }}
</p>
{% if user.is_in_group(settings.SITH_GROUP_FORUM_ADMIN_ID) or user.is_in_group(settings.SITH_GROUP_COM_ADMIN_ID) %}
<p>
......
......@@ -11,7 +11,7 @@
{% block content %}
{% if topic %}
{{ display_search_bar() }}
{{ display_search_bar(request) }}
<p>
<a href="{{ url('forum:main') }}">{% trans %}Forum{% endtrans %}</a>
{% for f in topic.forum.get_parent_list() %}
......
......@@ -4,7 +4,7 @@
{% block content %}
<div id="forum">
{{ display_search_bar() }}
{{ display_search_bar(request) }}
{% if object_list|length != 0 %}
<br>
<div class="search-results">
......
......@@ -27,7 +27,7 @@
{% block content %}
<p>
{{ display_search_bar() }}
{{ display_search_bar(request) }}
<a href="{{ url('forum:main') }}">{% trans %}Forum{% endtrans %}</a>
{% for f in topic.forum.get_parent_list()|reverse %}
> <a href="{{ f.get_absolute_url() }}">{{ f }}</a>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment