From 0800764bd6fd219c778d6410442460c3b54bf605 Mon Sep 17 00:00:00 2001 From: bmoe872 Date: Thu, 17 Feb 2022 10:09:05 -0700 Subject: [PATCH] Add the chooser-url as a url path. --- wagtail_draftail_snippet/urls.py | 18 ++++++++++++++-- wagtail_draftail_snippet/wagtail_hooks.py | 26 +++++++++++------------ 2 files changed, 29 insertions(+), 15 deletions(-) diff --git a/wagtail_draftail_snippet/urls.py b/wagtail_draftail_snippet/urls.py index 495edd6..ddd4e83 100644 --- a/wagtail_draftail_snippet/urls.py +++ b/wagtail_draftail_snippet/urls.py @@ -1,11 +1,25 @@ +from django.urls import path from django.conf.urls import url +from wagtail.snippets.views import chooser + from .views import choose_snippet_link_model, choose_snippet_embed_model app_name = "wagtaildraftailsnippet" urlpatterns = [ - url(r"^choose-link-model/$", choose_snippet_link_model, name="choose-snippet-link-model"), - url(r"^choose-embed-model/$", choose_snippet_embed_model, name="choose-snippet-embed-model"), + url( + r"^choose-link-model/$", + choose_snippet_link_model, + name="choose-snippet-link-model", + ), + url( + r"^choose-embed-model/$", + choose_snippet_embed_model, + name="choose-snippet-embed-model", + ), + path( + "choose/", chooser.ChooseView.as_view(), name="choose_generic" + ), # This exists only to get the additional URL params added via JS in wagtail-draftail-snippet.js line 50 ] diff --git a/wagtail_draftail_snippet/wagtail_hooks.py b/wagtail_draftail_snippet/wagtail_hooks.py index e56fddd..bb7967a 100644 --- a/wagtail_draftail_snippet/wagtail_hooks.py +++ b/wagtail_draftail_snippet/wagtail_hooks.py @@ -8,8 +8,10 @@ from wagtail.core import hooks from . import urls from .richtext import ( - ContentstateSnippetLinkConversionRule, ContentstateSnippetEmbedConversionRule, - SnippetLinkHandler, SnippetEmbedHandler, + ContentstateSnippetLinkConversionRule, + ContentstateSnippetEmbedConversionRule, + SnippetLinkHandler, + SnippetEmbedHandler, ) @@ -65,18 +67,16 @@ def register_snippet_embed_feature(features): @hooks.register("insert_editor_js") def editor_js(): - return format_html( - """ + + html = f""" - """, - reverse('wagtailsnippets:choose_generic'), - reverse("wagtaildraftailsnippet:choose-snippet-link-model"), - reverse("wagtaildraftailsnippet:choose-snippet-embed-model"), - ) + window.chooserUrls.snippetChooser = '{reverse('wagtaildraftailsnippet:choose_generic')}'; + window.chooserUrls.snippetLinkModelChooser = '{reverse("wagtaildraftailsnippet:choose-snippet-link-model")}'; + window.chooserUrls.snippetEmbedModelChooser = '{reverse("wagtaildraftailsnippet:choose-snippet-embed-model")}'; + + """ + + return format_html(html) @hooks.register("register_admin_urls")