kopia lustrzana https://github.com/wagtail/wagtail
Move inline panel JS into inline_panel.html
rodzic
895ffaed83
commit
b884026d08
|
@ -13,5 +13,4 @@ wagtail/search/static
|
||||||
wagtail/snippets/static
|
wagtail/snippets/static
|
||||||
wagtail/users/static
|
wagtail/users/static
|
||||||
wagtail/contrib/*/static
|
wagtail/contrib/*/static
|
||||||
wagtail/admin/templates/wagtailadmin/panels/inline_panel.js
|
|
||||||
wagtail/contrib/search_promotions/templates/wagtailsearchpromotions/includes/searchpromotions_formset.js
|
wagtail/contrib/search_promotions/templates/wagtailsearchpromotions/includes/searchpromotions_formset.js
|
||||||
|
|
|
@ -11,5 +11,4 @@ _build
|
||||||
*.md
|
*.md
|
||||||
# Files which contain incompatible syntax.
|
# Files which contain incompatible syntax.
|
||||||
*.html
|
*.html
|
||||||
wagtail/admin/templates/wagtailadmin/panels/inline_panel.js
|
|
||||||
wagtail/contrib/search_promotions/templates/wagtailsearchpromotions/includes/searchpromotions_formset.js
|
wagtail/contrib/search_promotions/templates/wagtailsearchpromotions/includes/searchpromotions_formset.js
|
||||||
|
|
|
@ -20,7 +20,6 @@
|
||||||
"node_modules",
|
"node_modules",
|
||||||
"static",
|
"static",
|
||||||
// Files with template syntax.
|
// Files with template syntax.
|
||||||
"wagtail/admin/templates/wagtailadmin/panels/inline_panel.js",
|
|
||||||
"wagtail/contrib/search_promotions/templates/wagtailsearchpromotions/includes/searchpromotions_formset.js"
|
"wagtail/contrib/search_promotions/templates/wagtailsearchpromotions/includes/searchpromotions_formset.js"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,10 +42,6 @@ from .forms.models import ( # NOQA
|
||||||
from .forms.pages import WagtailAdminPageForm
|
from .forms.pages import WagtailAdminPageForm
|
||||||
|
|
||||||
|
|
||||||
def widget_with_script(widget, script):
|
|
||||||
return mark_safe("{0}<script>{1}</script>".format(widget, script))
|
|
||||||
|
|
||||||
|
|
||||||
def get_form_for_model(
|
def get_form_for_model(
|
||||||
model,
|
model,
|
||||||
form_class=WagtailAdminModelForm,
|
form_class=WagtailAdminModelForm,
|
||||||
|
@ -845,7 +841,6 @@ class InlinePanel(Panel):
|
||||||
|
|
||||||
class BoundPanel(Panel.BoundPanel):
|
class BoundPanel(Panel.BoundPanel):
|
||||||
template_name = "wagtailadmin/panels/inline_panel.html"
|
template_name = "wagtailadmin/panels/inline_panel.html"
|
||||||
js_template_name = "wagtailadmin/panels/inline_panel.js"
|
|
||||||
|
|
||||||
def __init__(self, panel, instance, request, form):
|
def __init__(self, panel, instance, request, form):
|
||||||
super().__init__(panel, instance, request, form)
|
super().__init__(panel, instance, request, form)
|
||||||
|
@ -910,25 +905,10 @@ class InlinePanel(Panel):
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
|
|
||||||
def render_html(self):
|
def get_context_data(self, parent_context=None):
|
||||||
formset = render_to_string(
|
context = super().get_context_data(parent_context)
|
||||||
self.template_name,
|
context["can_order"] = self.formset.can_order
|
||||||
{
|
return context
|
||||||
"self": self,
|
|
||||||
"can_order": self.formset.can_order,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
js = self.render_js_init()
|
|
||||||
return widget_with_script(formset, js)
|
|
||||||
|
|
||||||
def render_js_init(self):
|
|
||||||
return render_to_string(
|
|
||||||
self.js_template_name,
|
|
||||||
{
|
|
||||||
"self": self,
|
|
||||||
"can_order": self.formset.can_order,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
# This allows users to include the publishing panel in their own per-model override
|
# This allows users to include the publishing panel in their own per-model override
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
{% load i18n %}
|
{% load i18n l10n wagtailadmin_tags %}
|
||||||
{% load wagtailadmin_tags %}
|
|
||||||
|
|
||||||
{{ self.formset.management_form }}
|
{{ self.formset.management_form }}
|
||||||
|
|
||||||
|
@ -29,3 +28,21 @@
|
||||||
{% blocktrans trimmed with label=self.label|lower %}Add {{ label }}{% endblocktrans %}
|
{% blocktrans trimmed with label=self.label|lower %}Add {{ label }}{% endblocktrans %}
|
||||||
</button>
|
</button>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
(function() {
|
||||||
|
var panel = InlinePanel({
|
||||||
|
formsetPrefix: "id_{{ self.formset.prefix }}",
|
||||||
|
emptyChildFormPrefix: "{{ self.empty_child.form.prefix }}",
|
||||||
|
canOrder: {% if can_order %}true{% else %}false{% endif %},
|
||||||
|
maxForms: {{ self.formset.max_num|unlocalize }}
|
||||||
|
});
|
||||||
|
|
||||||
|
{% for child in self.children %}
|
||||||
|
panel.initChildControls("{{ child.form.prefix }}");
|
||||||
|
{% endfor %}
|
||||||
|
panel.setHasContent();
|
||||||
|
panel.updateMoveButtonDisabledStates();
|
||||||
|
panel.updateAddButtonState();
|
||||||
|
})();
|
||||||
|
</script>
|
||||||
|
|
|
@ -1,17 +0,0 @@
|
||||||
{% load l10n %}
|
|
||||||
{% load wagtailadmin_tags %}
|
|
||||||
(function() {
|
|
||||||
var panel = InlinePanel({
|
|
||||||
formsetPrefix: "id_{{ self.formset.prefix }}",
|
|
||||||
emptyChildFormPrefix: "{{ self.empty_child.form.prefix }}",
|
|
||||||
canOrder: {% if can_order %}true{% else %}false{% endif %},
|
|
||||||
maxForms: {{ self.formset.max_num|unlocalize }}
|
|
||||||
});
|
|
||||||
|
|
||||||
{% for child in self.children %}
|
|
||||||
panel.initChildControls("{{ child.form.prefix }}");
|
|
||||||
{% endfor %}
|
|
||||||
panel.setHasContent();
|
|
||||||
panel.updateMoveButtonDisabledStates();
|
|
||||||
panel.updateAddButtonState();
|
|
||||||
})();
|
|
|
@ -1187,7 +1187,7 @@ class TestInlinePanel(TestCase, WagtailTestUtils):
|
||||||
)
|
)
|
||||||
|
|
||||||
# render_js_init must provide the JS initializer
|
# render_js_init must provide the JS initializer
|
||||||
self.assertIn("var panel = InlinePanel({", panel.render_js_init())
|
self.assertIn("var panel = InlinePanel({", panel.render_html())
|
||||||
|
|
||||||
@override_settings(USE_L10N=True, USE_THOUSAND_SEPARATOR=True)
|
@override_settings(USE_L10N=True, USE_THOUSAND_SEPARATOR=True)
|
||||||
def test_no_thousand_separators_in_js(self):
|
def test_no_thousand_separators_in_js(self):
|
||||||
|
@ -1217,7 +1217,7 @@ class TestInlinePanel(TestCase, WagtailTestUtils):
|
||||||
instance=event_page, form=form, request=self.request
|
instance=event_page, form=form, request=self.request
|
||||||
)
|
)
|
||||||
|
|
||||||
self.assertIn("maxForms: 1000", panel.render_js_init())
|
self.assertIn("maxForms: 1000", panel.render_html())
|
||||||
|
|
||||||
def test_invalid_inlinepanel_declaration(self):
|
def test_invalid_inlinepanel_declaration(self):
|
||||||
with self.ignore_deprecation_warnings():
|
with self.ignore_deprecation_warnings():
|
||||||
|
|
Ładowanie…
Reference in New Issue