Set up search-as-you-type as a standard feature of generic IndexView

pull/10542/head
Matt Westcott 2023-06-08 22:39:19 +01:00
rodzic 1f9c48400d
commit e54a2f568a
4 zmienionych plików z 18 dodań i 6 usunięć

Wyświetl plik

@ -18,6 +18,16 @@
{% block extra_js %}
{{ block.super }}
{{ media.js }}
{% if search_form %}
<script>
window.headerSearch = {
url: "{{ index_results_url }}",
termInput: "#id_q",
targetOutput: "#index-results"
}
</script>
{% endif %}
{% endblock %}
{% block extra_css %}

Wyświetl plik

@ -75,6 +75,7 @@ class IndexView(
):
model = None
index_url_name = None
index_results_url_name = None
add_url_name = None
add_item_label = _("Add")
edit_url_name = None
@ -333,6 +334,10 @@ class IndexView(
if self.index_url_name:
return reverse(self.index_url_name)
def get_index_results_url(self):
if self.index_results_url_name:
return reverse(self.index_results_url_name)
def get_edit_url(self, instance):
if self.edit_url_name:
return reverse(self.edit_url_name, args=(quote(instance.pk),))
@ -390,6 +395,7 @@ class IndexView(
context["table"] = table
context["index_url"] = index_url
context["index_results_url"] = self.get_index_results_url()
context["is_paginated"] = bool(self.paginate_by)
context["is_searchable"] = self.is_searchable
context["search_url"] = self.get_search_url()

Wyświetl plik

@ -40,6 +40,7 @@ class ModelViewSet(ViewSet):
"model": self.model,
"permission_policy": self.permission_policy,
"index_url_name": self.get_url_name("index"),
"index_results_url_name": self.get_url_name("index_results"),
"add_url_name": self.get_url_name("add"),
"edit_url_name": self.get_url_name("edit"),
"header_icon": self.icon,

Wyświetl plik

@ -5,11 +5,6 @@
{% block extra_js %}
<script>
window.headerSearch = {
url: "{% url view.index_results_url_name %}",
termInput: "#id_q",
targetOutput: "#snippet-results"
}
window.wagtailConfig.BULK_ACTION_ITEM_TYPE = 'SNIPPET';
</script>
<script defer src="{% versioned_static 'wagtailadmin/js/bulk-actions.js' %}"></script>
@ -24,7 +19,7 @@
{% include 'wagtailadmin/shared/header.html' with breadcrumb=breadcrumb title=model_opts.verbose_name_plural|capfirst icon=header_icon search_url=search_url base_actions=base_action_locale action_url=action_url_add_snippet action_icon="plus" action_text=action_text_snippet %}
<div class="nice-padding{% if filters %} filterable{% endif %}">
<div id="snippet-results" class="snippets">
<div id="index-results" class="snippets">
{% include "wagtailsnippets/snippets/index_results.html" %}
</div>
{% if filters %}