kopia lustrzana https://github.com/wagtail/wagtail
move collection chooser into filter form
rodzic
7fd45a6693
commit
cbe8e3e794
|
@ -7,7 +7,7 @@ class DocumentChooserModalOnloadHandlerFactory extends ChooserModalOnloadHandler
|
|||
|
||||
$('a.upload-one-now').on('click', (event) => {
|
||||
// Set current collection ID at upload form tab
|
||||
const collectionId = $('#collection_chooser_collection_id').val();
|
||||
const collectionId = $('#id_collection_id').val();
|
||||
if (collectionId) {
|
||||
$('#id_document-chooser-upload-collection').val(collectionId);
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ class DocumentChooserModalOnloadHandlerFactory extends ChooserModalOnloadHandler
|
|||
|
||||
window.DOCUMENT_CHOOSER_MODAL_ONLOAD_HANDLERS =
|
||||
new DocumentChooserModalOnloadHandlerFactory({
|
||||
searchFilterSelectors: ['#collection_chooser_collection_id'],
|
||||
searchFilterSelectors: ['#id_collection_id'],
|
||||
searchInputDelay: 50,
|
||||
chosenResponseName: 'documentChosen',
|
||||
creationFormFileFieldSelector: '#id_document-chooser-upload-file',
|
||||
|
|
|
@ -35,7 +35,6 @@
|
|||
{% for field in filter_form.visible_fields %}
|
||||
{% include "wagtailadmin/shared/field_as_li.html" with field=field %}
|
||||
{% endfor %}
|
||||
<li class="submit"><input type="submit" value="{% trans 'Search' %}" class="button" /></li>
|
||||
</ul>
|
||||
{% endif %}
|
||||
</form>
|
||||
|
|
|
@ -1,15 +1 @@
|
|||
{% extends "wagtailadmin/generic/chooser/chooser.html" %}
|
||||
|
||||
{% block filter_form %}
|
||||
<form data-chooser-modal-search class="search-bar" action="{{ results_url }}" method="GET" novalidate>
|
||||
{% for field in filter_form.hidden_fields %}{{ field }}{% endfor %}
|
||||
<ul class="fields">
|
||||
{% for field in filter_form.visible_fields %}
|
||||
{% include "wagtailadmin/shared/field_as_li.html" with field=field %}
|
||||
{% endfor %}
|
||||
{% if collections %}
|
||||
{% include "wagtailadmin/shared/collection_chooser.html" %}
|
||||
{% endif %}
|
||||
</ul>
|
||||
</form>
|
||||
{% endblock %}
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
from django import forms
|
||||
from django.core.paginator import Paginator
|
||||
from django.urls import reverse
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
@ -65,6 +66,20 @@ class DownloadColumn(Column):
|
|||
return context
|
||||
|
||||
|
||||
class DocumentFilterForm(SearchForm):
|
||||
def __init__(self, *args, collections, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
if collections:
|
||||
collection_choices = [
|
||||
("", _("All collections"))
|
||||
] + collections.get_indented_choices()
|
||||
self.fields["collection_id"] = forms.ChoiceField(
|
||||
label=_("Collection"),
|
||||
choices=collection_choices,
|
||||
required=False,
|
||||
)
|
||||
|
||||
|
||||
class BaseChooseView(ModalPageFurnitureMixin, ContextMixin, View):
|
||||
icon = "doc-full-inverse"
|
||||
page_title = _("Choose a document")
|
||||
|
@ -96,15 +111,23 @@ class BaseChooseView(ModalPageFurnitureMixin, ContextMixin, View):
|
|||
if self.collection_id:
|
||||
documents = documents.filter(collection=self.collection_id)
|
||||
|
||||
self.collections = permission_policy.collections_user_has_permission_for(
|
||||
request.user, "choose"
|
||||
)
|
||||
if len(self.collections) < 2:
|
||||
self.collections = None
|
||||
|
||||
if "q" in request.GET:
|
||||
self.filter_form = SearchForm(request.GET)
|
||||
self.filter_form = DocumentFilterForm(
|
||||
request.GET, collections=self.collections
|
||||
)
|
||||
if self.filter_form.is_valid():
|
||||
self.q = self.filter_form.cleaned_data["q"]
|
||||
|
||||
documents = documents.search(self.q)
|
||||
self.is_searching = True
|
||||
else:
|
||||
self.filter_form = SearchForm()
|
||||
self.filter_form = DocumentFilterForm(collections=self.collections)
|
||||
|
||||
if not self.is_searching:
|
||||
documents = documents.order_by("-created_at")
|
||||
|
@ -112,12 +135,6 @@ class BaseChooseView(ModalPageFurnitureMixin, ContextMixin, View):
|
|||
paginator = Paginator(documents, per_page=10)
|
||||
self.documents = paginator.get_page(request.GET.get("p"))
|
||||
|
||||
self.collections = permission_policy.collections_user_has_permission_for(
|
||||
request.user, "choose"
|
||||
)
|
||||
if len(self.collections) < 2:
|
||||
self.collections = None
|
||||
|
||||
columns = [
|
||||
TitleColumn(
|
||||
"title",
|
||||
|
|
Ładowanie…
Reference in New Issue