diff --git a/wagtail/wagtailadmin/static_src/wagtailadmin/js/expanding_formset.js b/wagtail/wagtailadmin/static_src/wagtailadmin/js/expanding_formset.js index 906984e90..8bf57af0f 100644 --- a/wagtail/wagtailadmin/static_src/wagtailadmin/js/expanding_formset.js +++ b/wagtail/wagtailadmin/static_src/wagtailadmin/js/expanding_formset.js @@ -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); diff --git a/wagtail/wagtailusers/static_src/wagtailusers/js/group-form.js b/wagtail/wagtailusers/static_src/wagtailusers/js/group-form.js new file mode 100644 index 000000000..ee1ccd411 --- /dev/null +++ b/wagtail/wagtailusers/static_src/wagtailusers/js/group-form.js @@ -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(); + }); + } + }); +}); diff --git a/wagtail/wagtailusers/templates/wagtailusers/groups/create.html b/wagtail/wagtailusers/templates/wagtailusers/groups/create.html index ec125511c..b5712e589 100644 --- a/wagtail/wagtailusers/templates/wagtailusers/groups/create.html +++ b/wagtail/wagtailusers/templates/wagtailusers/groups/create.html @@ -33,9 +33,5 @@ {% endblock %} {% block extra_js %} - {% include "wagtailadmin/pages/_editor_js.html" %} - - + {% include "wagtailusers/groups/includes/group_form_js.html" %} {% endblock %} diff --git a/wagtail/wagtailusers/templates/wagtailusers/groups/edit.html b/wagtail/wagtailusers/templates/wagtailusers/groups/edit.html index 55886f6ad..ddf76625a 100644 --- a/wagtail/wagtailusers/templates/wagtailusers/groups/edit.html +++ b/wagtail/wagtailusers/templates/wagtailusers/groups/edit.html @@ -41,9 +41,5 @@ {% endblock %} {% block extra_js %} - {% include "wagtailadmin/pages/_editor_js.html" %} - - + {% include "wagtailusers/groups/includes/group_form_js.html" %} {% endblock %} diff --git a/wagtail/wagtailusers/templates/wagtailusers/groups/includes/group_form_js.html b/wagtail/wagtailusers/templates/wagtailusers/groups/includes/group_form_js.html new file mode 100644 index 000000000..d494ce946 --- /dev/null +++ b/wagtail/wagtailusers/templates/wagtailusers/groups/includes/group_form_js.html @@ -0,0 +1,13 @@ +{% load static compress %} + + +{% compress js %} + + + + +{% endcompress %} diff --git a/wagtail/wagtailusers/templates/wagtailusers/groups/includes/page_permissions_form.html b/wagtail/wagtailusers/templates/wagtailusers/groups/includes/page_permissions_form.html index f6f56414d..f113231c8 100644 --- a/wagtail/wagtailusers/templates/wagtailusers/groups/includes/page_permissions_form.html +++ b/wagtail/wagtailusers/templates/wagtailusers/groups/includes/page_permissions_form.html @@ -1,17 +1,15 @@ {% load i18n %}