mirror of
https://github.com/Hopiu/wagtail.git
synced 2026-05-10 16:24:49 +00:00
Merge pull request #1620 from gasman/fix/page-permission-formset-cleanup
Fix behaviour of page permission formset on groups admin
This commit is contained in:
commit
24f5b78588
8 changed files with 41 additions and 32 deletions
|
|
@ -8,6 +8,12 @@ function buildExpandingFormset(prefix, opts) {
|
|||
var totalFormsInput = $('#' + prefix + '-TOTAL_FORMS');
|
||||
var formCount = parseInt(totalFormsInput.val(), 10);
|
||||
|
||||
if (opts.onInit) {
|
||||
for (var i = 0; i < formCount; i++) {
|
||||
opts.onInit(i);
|
||||
}
|
||||
}
|
||||
|
||||
var emptyFormTemplate = document.getElementById(prefix + '-EMPTY_FORM_TEMPLATE');
|
||||
if (emptyFormTemplate.innerText) {
|
||||
emptyFormTemplate = emptyFormTemplate.innerText;
|
||||
|
|
@ -20,9 +26,8 @@ function buildExpandingFormset(prefix, opts) {
|
|||
.replace(/__prefix__/g, formCount)
|
||||
.replace(/<-(-*)\/script>/g, '<$1/script>');
|
||||
formContainer.append(newFormHtml);
|
||||
if (opts.onAdd) {
|
||||
opts.onAdd(formCount);
|
||||
}
|
||||
if (opts.onAdd) opts.onAdd(formCount);
|
||||
if (opts.onInit) opts.onInit(formCount);
|
||||
|
||||
formCount++;
|
||||
totalFormsInput.val(formCount);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,13 @@
|
|||
$(function() {
|
||||
buildExpandingFormset('id_page_permissions', {
|
||||
onInit: function(index) {
|
||||
var deleteInputId = 'id_page_permissions-' + index + '-DELETE';
|
||||
var childId = 'inline_child_page_permissions-' + index;
|
||||
$('#' + deleteInputId + '-button').click(function() {
|
||||
/* set 'deleted' form field to true */
|
||||
$('#' + deleteInputId).val('1');
|
||||
$('#' + childId).fadeOut();
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
@ -33,9 +33,5 @@
|
|||
{% endblock %}
|
||||
|
||||
{% block extra_js %}
|
||||
{% include "wagtailadmin/pages/_editor_js.html" %}
|
||||
|
||||
<script>
|
||||
{% include "wagtailusers/groups/includes/page_permissions_formset.js" with formset=formset only %}
|
||||
</script>
|
||||
{% include "wagtailusers/groups/includes/group_form_js.html" %}
|
||||
{% endblock %}
|
||||
|
|
|
|||
|
|
@ -41,9 +41,5 @@
|
|||
{% endblock %}
|
||||
|
||||
{% block extra_js %}
|
||||
{% include "wagtailadmin/pages/_editor_js.html" %}
|
||||
|
||||
<script>
|
||||
{% include "wagtailusers/groups/includes/page_permissions_formset.js" with formset=formset only %}
|
||||
</script>
|
||||
{% include "wagtailusers/groups/includes/group_form_js.html" %}
|
||||
{% endblock %}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,13 @@
|
|||
{% load static compress %}
|
||||
<script>
|
||||
window.chooserUrls = {
|
||||
'pageChooser': '{% url "wagtailadmin_choose_page" %}'
|
||||
};
|
||||
</script>
|
||||
|
||||
{% compress js %}
|
||||
<script src="{% static 'wagtailadmin/js/page-chooser.js' %}"></script>
|
||||
<script src="{% static 'wagtailadmin/js/expanding_formset.js' %}"></script>
|
||||
<script src="{% static 'wagtailadmin/js/modal-workflow.js' %}"></script>
|
||||
<script src="{% static 'wagtailusers/js/group-form.js' %}"></script>
|
||||
{% endcompress %}
|
||||
|
|
@ -1,17 +1,15 @@
|
|||
{% load i18n %}
|
||||
|
||||
<td>
|
||||
{% include "wagtailadmin/edit_handlers/field_panel_field.html" with field=form.page only %}
|
||||
{% include "wagtailadmin/shared/field.html" with field=form.page only %}
|
||||
</td>
|
||||
<td>
|
||||
{% include "wagtailadmin/edit_handlers/field_panel_field.html" with field=form.permission_type only %}
|
||||
{% include "wagtailadmin/shared/field.html" with field=form.permission_type only %}
|
||||
|
||||
{{ form.id }}
|
||||
{{ form.ORDER }}
|
||||
{{ form.DELETE }}
|
||||
</td>
|
||||
|
||||
<td>
|
||||
<button class="button-secondary button-small no" id="{{ form.DELETE.id_for_label }}-button">{% trans "Delete" %}</button>
|
||||
<button class="button-secondary button-small no" type="button" id="{{ form.DELETE.id_for_label }}-button">{% trans "Delete" %}</button>
|
||||
</td>
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
{% load i18n wagtailadmin_tags %}
|
||||
<h2>{% trans "Page permissions" %}</h2>
|
||||
|
||||
{{ formset.management_form }}{# what is this? #}
|
||||
{{ formset.management_form }}
|
||||
|
||||
<table class="listing">
|
||||
<col width="40%"/>
|
||||
|
|
@ -32,7 +32,7 @@
|
|||
|
||||
<script type="text/django-form-template" id="id_{{ formset.prefix }}-EMPTY_FORM_TEMPLATE">
|
||||
{% escapescript %}
|
||||
<tr>
|
||||
<tr id="inline_child_{{ formset.empty_form.prefix }}">
|
||||
{% include "wagtailusers/groups/includes/page_permissions_form.html" with form=formset.empty_form only %}
|
||||
</tr>
|
||||
{% endescapescript %}
|
||||
|
|
|
|||
|
|
@ -1,12 +0,0 @@
|
|||
$(function() {
|
||||
var panel = InlinePanel({
|
||||
formsetPrefix: "id_{{ formset.prefix }}",
|
||||
emptyChildFormPrefix: "{{ formset.empty_form.prefix }}"
|
||||
});
|
||||
|
||||
{% for form in formset.forms %}
|
||||
panel.initChildControls('{{ formset.prefix }}-{{ forloop.counter0 }}');
|
||||
{% endfor %}
|
||||
|
||||
panel.updateMoveButtonDisabledStates();
|
||||
});
|
||||
Loading…
Reference in a new issue