mirror of
https://github.com/Hopiu/wagtail.git
synced 2026-05-11 00:33:17 +00:00
Add inline chooser panel templates for group page permissions formset
This commit is contained in:
parent
2e3d0fd03c
commit
ab6987194f
5 changed files with 86 additions and 1 deletions
|
|
@ -188,6 +188,10 @@ class GroupForm(forms.ModelForm):
|
|||
|
||||
|
||||
class GroupPagePermissionForm(forms.ModelForm):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(GroupPagePermissionForm, self).__init__(*args, **kwargs)
|
||||
self.fields['page'].widget = forms.HiddenInput()
|
||||
|
||||
class Meta:
|
||||
model = GroupPagePermission
|
||||
fields = ('page', 'permission_type')
|
||||
|
|
@ -197,6 +201,14 @@ class BaseGroupPagePermissionFormSet(forms.models.BaseInlineFormSet):
|
|||
def __init__(self, *args, **kwargs):
|
||||
super(BaseGroupPagePermissionFormSet, self).__init__(*args, **kwargs)
|
||||
self.form = GroupPagePermissionForm
|
||||
for form in self.forms:
|
||||
form.fields['DELETE'].widget = forms.HiddenInput()
|
||||
|
||||
@property
|
||||
def empty_form(self):
|
||||
empty_form = super(BaseGroupPagePermissionFormSet, self).empty_form
|
||||
empty_form.fields['DELETE'].widget = forms.HiddenInput()
|
||||
return empty_form
|
||||
|
||||
|
||||
class NotificationPreferencesForm(forms.ModelForm):
|
||||
|
|
|
|||
|
|
@ -15,9 +15,16 @@
|
|||
<ul class="fields">
|
||||
{% include "wagtailadmin/shared/field_as_li.html" with field=form.name %}
|
||||
{% format_permissions permission_bound_field=form.permissions %}
|
||||
{{ formset }}
|
||||
{% include "wagtailusers/groups/includes/page_permissions_formset.html" with formset=formset only %}
|
||||
<li><input type="submit" value="{% trans 'Save' %}" /></li>
|
||||
</ul>
|
||||
</div>
|
||||
</form>
|
||||
{% endblock %}
|
||||
{% block extra_js %}
|
||||
{% include "wagtailadmin/pages/_editor_js.html" %}
|
||||
|
||||
<script type="text/javascript">
|
||||
{% include "wagtailusers/groups/includes/page_permissions_formset.js" with formset=formset only %}
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,31 @@
|
|||
{% load i18n %}
|
||||
{% comment %}
|
||||
TODO - DRY this form with /wagtailsearch/templates/wagtailsearch/editorspicks/includes/editorspicks_form.html
|
||||
{% endcomment %}
|
||||
<li id="inline_child_{{ form.prefix }}"{% if form.DELETE.value %} style="display: none;"{% endif %}>
|
||||
<ul class="controls">
|
||||
<li class="icon text-replace icon-bin" id="{{ form.DELETE.id_for_label }}-button">{% trans "Delete" %}</li>
|
||||
</ul>
|
||||
|
||||
<fieldset>
|
||||
<legend>{% trans "Page permissions" %}</legend>
|
||||
<ul class="fields">
|
||||
<li class="model_choice_field">
|
||||
{% trans "Choose a different root page" as choose_another_text_str %}
|
||||
{% trans "Choose a root page" as choose_one_text_str %}
|
||||
{% if form.instance.page %}
|
||||
{% include "wagtailadmin/edit_handlers/page_chooser_panel.html" with field=form.page page=form.instance.page is_chosen=True choose_one_text_str=choose_one_text_str choose_another_text_str=choose_another_text_str only %}
|
||||
{% else %}
|
||||
{% include "wagtailadmin/edit_handlers/page_chooser_panel.html" with field=form.page is_chosen=False choose_one_text_str=choose_one_text_str choose_another_text_str=choose_another_text_str only %}
|
||||
{% endif %}
|
||||
</li>
|
||||
<li class="char_field">
|
||||
{% include "wagtailadmin/edit_handlers/field_panel_field.html" with field=form.permission_type only %}
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
{{ form.id }}
|
||||
{{ form.ORDER }}
|
||||
{{ form.DELETE }}
|
||||
</fieldset>
|
||||
</li>
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
{% load i18n %}
|
||||
{{ formset.management_form }}
|
||||
<ul class="multiple" id="id_{{ formset.prefix }}-FORMS">
|
||||
{% for form in formset.forms %}
|
||||
{% include "wagtailusers/groups/includes/page_permissions_form.html" with form=form only %}
|
||||
{% endfor %}
|
||||
</ul>
|
||||
|
||||
<script type="text/django-form-template" id="id_{{ formset.prefix }}-EMPTY_FORM_TEMPLATE">
|
||||
{% include "wagtailusers/groups/includes/page_permissions_form.html" with form=formset.empty_form only %}
|
||||
</script>
|
||||
|
||||
<p class="add">
|
||||
<a class="button bicolor icon icon-plus" id="id_{{ formset.prefix }}-ADD" value="Add">{% trans "Add another page permission" %}</a>
|
||||
</p>
|
||||
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
(function() {
|
||||
function fixPrefix(str) {return str;}
|
||||
|
||||
var panel = InlinePanel({
|
||||
formsetPrefix: fixPrefix("id_{{ formset.prefix }}"),
|
||||
emptyChildFormPrefix: fixPrefix("{{ formset.empty_form.prefix }}"),
|
||||
|
||||
onAdd: function(fixPrefix) {
|
||||
createPageChooser(fixPrefix('id_{{ formset.prefix }}-__prefix__-page'), 'wagtailcore.page', null);
|
||||
}
|
||||
});
|
||||
|
||||
{% for form in formset.forms %}
|
||||
createPageChooser(fixPrefix('id_{{ formset.prefix }}-{{ forloop.counter0 }}-page'), 'wagtailcore.page', null);
|
||||
panel.initChildControls('{{ formset.prefix }}-{{ forloop.counter0 }}');
|
||||
{% endfor %}
|
||||
|
||||
panel.updateMoveButtonDisabledStates();
|
||||
})();
|
||||
Loading…
Reference in a new issue