kopia lustrzana https://github.com/wagtail/wagtail
Pass the complete snippet chooser URL as a data attribute, rather than tacking on the model parameter in JS.
I think that's a throwback to when the chooser URL was being passed to the page as a constant in window.chooserUrls...pull/7389/head
rodzic
728b48ceca
commit
74a8cfd862
|
@ -7,7 +7,7 @@ function createSnippetChooser(id, modelString) {
|
||||||
const docTitle = chooserElement.find('.title');
|
const docTitle = chooserElement.find('.title');
|
||||||
const input = $('#' + id);
|
const input = $('#' + id);
|
||||||
const editLink = chooserElement.find('.edit-link');
|
const editLink = chooserElement.find('.edit-link');
|
||||||
const chooserBaseUrl = chooserElement.data('chooserUrl') + modelString + '/';
|
const chooserBaseUrl = chooserElement.data('chooserUrl');
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Construct initial state of the chooser from the rendered (static) HTML and arguments passed to
|
Construct initial state of the chooser from the rendered (static) HTML and arguments passed to
|
||||||
|
|
|
@ -4,4 +4,4 @@
|
||||||
{% block unchosen_icon %}{% icon name="snippet" %}{% endblock unchosen_icon %}
|
{% block unchosen_icon %}{% icon name="snippet" %}{% endblock unchosen_icon %}
|
||||||
{% block chosen_icon %}{% icon name="snippet" %}{% endblock chosen_icon %}
|
{% block chosen_icon %}{% icon name="snippet" %}{% endblock chosen_icon %}
|
||||||
{% block chooser_class %}snippet-chooser{% endblock %}
|
{% block chooser_class %}snippet-chooser{% endblock %}
|
||||||
{% block chooser_attributes %}data-chooser-url="{% url 'wagtailsnippets:choose_generic' %}"{% endblock %}
|
{% block chooser_attributes %}data-chooser-url="{{ chooser_url }}"{% endblock %}
|
||||||
|
|
|
@ -7,7 +7,6 @@ app_name = 'wagtailsnippets'
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('', snippets.index, name='index'),
|
path('', snippets.index, name='index'),
|
||||||
|
|
||||||
path('choose/', chooser.choose, name='choose_generic'),
|
|
||||||
path('choose/<slug:app_label>/<slug:model_name>/', chooser.choose, name='choose'),
|
path('choose/<slug:app_label>/<slug:model_name>/', chooser.choose, name='choose'),
|
||||||
path('choose/<slug:app_label>/<slug:model_name>/<str:pk>/', chooser.chosen, name='chosen'),
|
path('choose/<slug:app_label>/<slug:model_name>/<str:pk>/', chooser.chosen, name='chosen'),
|
||||||
|
|
||||||
|
|
|
@ -48,6 +48,9 @@ class AdminSnippetChooser(AdminChooser):
|
||||||
value_data = value_data or {}
|
value_data = value_data or {}
|
||||||
|
|
||||||
original_field_html = super().render_html(name, value_data.get('id'), attrs)
|
original_field_html = super().render_html(name, value_data.get('id'), attrs)
|
||||||
|
chooser_url = reverse(
|
||||||
|
'wagtailsnippets:choose', args=[self.target_model._meta.app_label, self.target_model._meta.model_name]
|
||||||
|
)
|
||||||
|
|
||||||
return render_to_string("wagtailsnippets/widgets/snippet_chooser.html", {
|
return render_to_string("wagtailsnippets/widgets/snippet_chooser.html", {
|
||||||
'widget': self,
|
'widget': self,
|
||||||
|
@ -56,6 +59,7 @@ class AdminSnippetChooser(AdminChooser):
|
||||||
'value': bool(value_data), # only used by chooser.html to identify blank values
|
'value': bool(value_data), # only used by chooser.html to identify blank values
|
||||||
'display_title': value_data.get('string', ''),
|
'display_title': value_data.get('string', ''),
|
||||||
'edit_url': value_data.get('edit_url', ''),
|
'edit_url': value_data.get('edit_url', ''),
|
||||||
|
'chooser_url': chooser_url,
|
||||||
})
|
})
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|
Ładowanie…
Reference in New Issue