kopia lustrzana https://github.com/wagtail/wagtail
				
				
				
			Make title into a label rather than a link when in multiple choice mode
							rodzic
							
								
									32f8c78b58
								
							
						
					
					
						commit
						2574204b27
					
				| 
						 | 
				
			
			@ -132,7 +132,8 @@ ul.listing {
 | 
			
		|||
      color: $color-white;
 | 
			
		||||
 | 
			
		||||
      .title a,
 | 
			
		||||
      .title a:hover {
 | 
			
		||||
      .title a:hover,
 | 
			
		||||
      .title label {
 | 
			
		||||
        color: $color-white;
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -125,12 +125,8 @@ const PAGE_CHOOSER_MODAL_ONLOAD_HANDLERS = {
 | 
			
		|||
      /* Set up behaviour of choose-page links, to pass control back to the calling page */
 | 
			
		||||
      // eslint-disable-next-line func-names
 | 
			
		||||
      $('a.choose-page', modal.body).on('click', function () {
 | 
			
		||||
        let pageData = $(this).data();
 | 
			
		||||
        const pageData = $(this).data();
 | 
			
		||||
        pageData.parentId = jsonData.parent_page_id;
 | 
			
		||||
        if ($('form[data-multiple-choice-form]', modal.body).length) {
 | 
			
		||||
          /* this is a multiple-choice chooser, so wrap in a list before returning */
 | 
			
		||||
          pageData = [pageData];
 | 
			
		||||
        }
 | 
			
		||||
        modal.respond('pageChosen', pageData);
 | 
			
		||||
        modal.close();
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,4 +1,4 @@
 | 
			
		|||
{% load i18n %}
 | 
			
		||||
<td {% if column.classname %}class="{{ column.classname }}"{% endif %}>
 | 
			
		||||
    <input type="checkbox" data-multiple-choice-select name="id" value="{{ value }}" {% if not instance.can_choose %}disabled{% endif %} title="{% blocktrans trimmed with title=instance %}Select {{ title }}{% endblocktrans %}">
 | 
			
		||||
    <input type="checkbox" id="chooser-modal-select-{{ value }}" data-multiple-choice-select name="id" value="{{ value }}" {% if not instance.can_choose %}disabled{% endif %} title="{% blocktrans trimmed with title=instance %}Select {{ title }}{% endblocktrans %}">
 | 
			
		||||
</td>
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2,7 +2,11 @@
 | 
			
		|||
<td class="{% if column.classname %}{{ column.classname }} {% endif %}title">
 | 
			
		||||
    <div class="title-wrapper">
 | 
			
		||||
        {% if page.can_choose %}
 | 
			
		||||
            <a class="choose-page" href="#{{ page.id|unlocalize }}" data-id="{{ page.id|unlocalize }}" data-title="{{ page.title }}" data-admin-title="{{ page.get_admin_display_title }}" data-url="{{ page.url }}" data-parent-id="{{ page.get_parent.id|unlocalize }}" data-edit-url="{% url 'wagtailadmin_pages:edit' page.id %}">{{ value }}</a>
 | 
			
		||||
            {% if column.is_multiple_choice %}
 | 
			
		||||
                <label for="chooser-modal-select-{{ page.id|unlocalize }}">{{ value }}</label>
 | 
			
		||||
            {% else %}
 | 
			
		||||
                <a class="choose-page" href="#{{ page.id|unlocalize }}" data-id="{{ page.id|unlocalize }}" data-title="{{ page.title }}" data-admin-title="{{ page.get_admin_display_title }}" data-url="{{ page.url }}" data-parent-id="{{ page.get_parent.id|unlocalize }}" data-edit-url="{% url 'wagtailadmin_pages:edit' page.id %}">{{ value }}</a>
 | 
			
		||||
            {% endif %}
 | 
			
		||||
        {% else %}
 | 
			
		||||
            {{ value }}
 | 
			
		||||
        {% endif %}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,4 +1,4 @@
 | 
			
		|||
{% load i18n %}
 | 
			
		||||
<td {% if column.classname %}class="{{ column.classname }}"{% endif %}>
 | 
			
		||||
    <input type="checkbox" data-multiple-choice-select name="id" value="{{ value }}" title="{% blocktrans trimmed with title=instance %}Select {{ title }}{% endblocktrans %}">
 | 
			
		||||
    <input type="checkbox" id="chooser-modal-select-{{ value }}" data-multiple-choice-select name="id" value="{{ value }}" title="{% blocktrans trimmed with title=instance %}Select {{ title }}{% endblocktrans %}">
 | 
			
		||||
</td>
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2,6 +2,8 @@
 | 
			
		|||
    <div class="title-wrapper">
 | 
			
		||||
        {% if link_url %}
 | 
			
		||||
            <a {% include "wagtailadmin/tables/attrs.html" with attrs=link_attrs %}>{{ value }}</a>
 | 
			
		||||
        {% elif label_id %}
 | 
			
		||||
            <label for="{{ label_id }}">{{ value }}</label>
 | 
			
		||||
        {% else %}
 | 
			
		||||
            {{ value }}
 | 
			
		||||
        {% endif %}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -128,7 +128,7 @@ class Column(metaclass=MediaDefiningClass):
 | 
			
		|||
 | 
			
		||||
 | 
			
		||||
class TitleColumn(Column):
 | 
			
		||||
    """A column where data is styled as a title and wrapped in a link"""
 | 
			
		||||
    """A column where data is styled as a title and wrapped in a link or <label>"""
 | 
			
		||||
 | 
			
		||||
    cell_template_name = "wagtailadmin/tables/title_cell.html"
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -137,6 +137,8 @@ class TitleColumn(Column):
 | 
			
		|||
        name,
 | 
			
		||||
        url_name=None,
 | 
			
		||||
        get_url=None,
 | 
			
		||||
        label_prefix=None,
 | 
			
		||||
        get_label_id=None,
 | 
			
		||||
        link_classname=None,
 | 
			
		||||
        link_attrs=None,
 | 
			
		||||
        id_accessor="pk",
 | 
			
		||||
| 
						 | 
				
			
			@ -145,6 +147,8 @@ class TitleColumn(Column):
 | 
			
		|||
        super().__init__(name, **kwargs)
 | 
			
		||||
        self.url_name = url_name
 | 
			
		||||
        self._get_url_func = get_url
 | 
			
		||||
        self.label_prefix = label_prefix
 | 
			
		||||
        self._get_label_id_func = get_label_id
 | 
			
		||||
        self.link_attrs = link_attrs or {}
 | 
			
		||||
        self.link_classname = link_classname
 | 
			
		||||
        self.id_accessor = id_accessor
 | 
			
		||||
| 
						 | 
				
			
			@ -157,15 +161,23 @@ class TitleColumn(Column):
 | 
			
		|||
        )
 | 
			
		||||
        if self.link_classname is not None:
 | 
			
		||||
            context["link_attrs"]["class"] = self.link_classname
 | 
			
		||||
        context["label_id"] = self.get_label_id(instance, parent_context)
 | 
			
		||||
        return context
 | 
			
		||||
 | 
			
		||||
    def get_link_url(self, instance, parent_context):
 | 
			
		||||
        if self._get_url_func:
 | 
			
		||||
            return self._get_url_func(instance)
 | 
			
		||||
        else:
 | 
			
		||||
        elif self.url_name:
 | 
			
		||||
            id = multigetattr(instance, self.id_accessor)
 | 
			
		||||
            return reverse(self.url_name, args=(quote(id),))
 | 
			
		||||
 | 
			
		||||
    def get_label_id(self, instance, parent_context):
 | 
			
		||||
        if self._get_label_id_func:
 | 
			
		||||
            return self._get_label_id_func(instance)
 | 
			
		||||
        elif self.label_prefix:
 | 
			
		||||
            id = multigetattr(instance, self.id_accessor)
 | 
			
		||||
            return "%s-%s" % (self.label_prefix, id)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class StatusFlagColumn(Column):
 | 
			
		||||
    """Represents a boolean value as a status tag (or lack thereof, if the corresponding label is None)"""
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -116,9 +116,12 @@ class PageChooserTable(Table):
 | 
			
		|||
class PageTitleColumn(Column):
 | 
			
		||||
    cell_template_name = "wagtailadmin/chooser/tables/page_title_cell.html"
 | 
			
		||||
 | 
			
		||||
    def __init__(self, *args, show_locale_labels=False, **kwargs):
 | 
			
		||||
    def __init__(
 | 
			
		||||
        self, *args, show_locale_labels=False, is_multiple_choice=False, **kwargs
 | 
			
		||||
    ):
 | 
			
		||||
        super().__init__(*args, **kwargs)
 | 
			
		||||
        self.show_locale_labels = show_locale_labels
 | 
			
		||||
        self.is_multiple_choice = is_multiple_choice
 | 
			
		||||
 | 
			
		||||
    def get_value(self, instance):
 | 
			
		||||
        return instance.get_admin_display_title()
 | 
			
		||||
| 
						 | 
				
			
			@ -165,7 +168,10 @@ class BrowseView(View):
 | 
			
		|||
    def columns(self):
 | 
			
		||||
        cols = [
 | 
			
		||||
            PageTitleColumn(
 | 
			
		||||
                "title", label=_("Title"), show_locale_labels=self.i18n_enabled
 | 
			
		||||
                "title",
 | 
			
		||||
                label=_("Title"),
 | 
			
		||||
                show_locale_labels=self.i18n_enabled,
 | 
			
		||||
                is_multiple_choice=self.is_multiple_choice,
 | 
			
		||||
            ),
 | 
			
		||||
            DateColumn(
 | 
			
		||||
                "updated",
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -190,10 +190,25 @@ class BaseChooseView(
 | 
			
		|||
            reverse(self.chosen_multiple_url_name)
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
    @cached_property
 | 
			
		||||
    def is_multiple_choice(self):
 | 
			
		||||
        return self.request.GET.get("multiple")
 | 
			
		||||
 | 
			
		||||
    @property
 | 
			
		||||
    def columns(self):
 | 
			
		||||
        return [
 | 
			
		||||
            TitleColumn(
 | 
			
		||||
        return [self.title_column]
 | 
			
		||||
 | 
			
		||||
    @property
 | 
			
		||||
    def title_column(self):
 | 
			
		||||
        if self.is_multiple_choice:
 | 
			
		||||
            return TitleColumn(
 | 
			
		||||
                "title",
 | 
			
		||||
                label=_("Title"),
 | 
			
		||||
                accessor=str,
 | 
			
		||||
                label_prefix="chooser-modal-select",
 | 
			
		||||
            )
 | 
			
		||||
        else:
 | 
			
		||||
            return TitleColumn(
 | 
			
		||||
                "title",
 | 
			
		||||
                label=_("Title"),
 | 
			
		||||
                accessor=str,
 | 
			
		||||
| 
						 | 
				
			
			@ -203,8 +218,7 @@ class BaseChooseView(
 | 
			
		|||
                    )
 | 
			
		||||
                ),
 | 
			
		||||
                link_attrs={"data-chooser-modal-choice": True},
 | 
			
		||||
            ),
 | 
			
		||||
        ]
 | 
			
		||||
            )
 | 
			
		||||
 | 
			
		||||
    @property
 | 
			
		||||
    def checkbox_column(self):
 | 
			
		||||
| 
						 | 
				
			
			@ -223,7 +237,6 @@ class BaseChooseView(
 | 
			
		|||
    def get(self, request):
 | 
			
		||||
        self.filter_form = self.get_filter_form()
 | 
			
		||||
        self.results = self.get_results_page(request)
 | 
			
		||||
        self.is_multiple_choice = request.GET.get("multiple")
 | 
			
		||||
 | 
			
		||||
        columns = self.columns
 | 
			
		||||
        if self.is_multiple_choice:
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -8,13 +8,13 @@
 | 
			
		|||
        {% for image in results %}
 | 
			
		||||
            <li>
 | 
			
		||||
                {% 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 }}">
 | 
			
		||||
                    <label title="Select {% if collections %}{{ image.collection.name }} » {% endif %}{{ image.title }}">
 | 
			
		||||
                        <div class="image">{% image image max-165x165 class="show-transparency" %}</div>
 | 
			
		||||
                    </a>
 | 
			
		||||
                    <h3>
 | 
			
		||||
                        <input type="checkbox" data-multiple-choice-select name="id" value="{{ image.id }}" title="{% blocktrans trimmed with title=image.title %}Select {{ title }}{% endblocktrans %}">
 | 
			
		||||
                        {{ image.title|ellipsistrim:60 }}
 | 
			
		||||
                    </h3>
 | 
			
		||||
                        <h3>
 | 
			
		||||
                            <input type="checkbox" data-multiple-choice-select name="id" value="{{ image.id }}" title="{% blocktrans trimmed with title=image.title %}Select {{ title }}{% endblocktrans %}">
 | 
			
		||||
                            {{ image.title|ellipsistrim:60 }}
 | 
			
		||||
                        </h3>
 | 
			
		||||
                    </label>
 | 
			
		||||
                {% 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>
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Ładowanie…
	
		Reference in New Issue