Implement multiple choice UI for image chooser

pull/9445/head
Matt Westcott 2023-01-13 01:31:48 +00:00
rodzic 45fe5c1b95
commit 2c8c381ca7
2 zmienionych plików z 22 dodań i 4 usunięć

Wyświetl plik

@ -7,10 +7,20 @@
<ul class="listing horiz images chooser">
{% for image in results %}
<li>
<a data-chooser-modal-choice class="image-choice" title="{% if collections %}{{ image.collection.name }} » {% endif %}{{ image.title }}" href="{{ image.chosen_url }}">
<div class="image">{% image image max-165x165 class="show-transparency" %}</div>
<h3>{{ image.title|ellipsistrim:60 }}</h3>
</a>
{% if is_multiple_choice %}
<a data-chooser-modal-choice class="image-choice" title="{% if collections %}{{ image.collection.name }} » {% endif %}{{ image.title }}" href="{{ image.chosen_url }}">
<div class="image">{% image image max-165x165 class="show-transparency" %}</div>
</a>
<h3>
<input type="checkbox" name="id" value="{{ image.id }}" title="{% blocktrans trimmed with title=image.title %}Select {{ title }}{% endblocktrans %}">
{{ image.title|ellipsistrim:60 }}
</h3>
{% else %}
<a data-chooser-modal-choice class="image-choice" title="{% if collections %}{{ image.collection.name }} » {% endif %}{{ image.title }}" href="{{ image.chosen_url }}">
<div class="image">{% image image max-165x165 class="show-transparency" %}</div>
<h3>{{ image.title|ellipsistrim:60 }}</h3>
</a>
{% endif %}
</li>
{% endfor %}
</ul>

Wyświetl plik

@ -14,6 +14,7 @@ from wagtail.admin.views.generic.chooser import (
BaseChooseView,
ChooseResultsViewMixin,
ChooseViewMixin,
ChosenMultipleViewMixin,
ChosenResponseMixin,
ChosenViewMixin,
CreateViewMixin,
@ -156,6 +157,12 @@ class ImageChosenView(ChosenViewMixin, ImageChosenResponseMixin, View):
return super().get(request, *args, pk, **kwargs)
class ImageChosenMultipleView(ChosenMultipleViewMixin, ImageChosenResponseMixin, View):
def get(self, request, *args, **kwargs):
self.model = get_image_model()
return super().get(request, *args, **kwargs)
class SelectFormatResponseMixin(PreserveURLParametersMixin):
def render_select_format_response(self, image, form):
action_url = self.append_preserved_url_parameters(
@ -299,6 +306,7 @@ class ImageChooserViewSet(ChooserViewSet):
choose_view_class = ImageChooseView
choose_results_view_class = ImageChooseResultsView
chosen_view_class = ImageChosenView
chosen_multiple_view_class = ImageChosenMultipleView
create_view_class = ImageUploadView
select_format_view_class = ImageSelectFormatView
permission_policy = permission_policy