From 7768d57d2fad015982c15bf184beca7af52c4901 Mon Sep 17 00:00:00 2001 From: Matt Westcott Date: Mon, 17 Aug 2015 13:31:49 +0200 Subject: [PATCH] Move JS code shared between add group/delete group views into an include --- .../static_src/wagtailusers/js/group-form.js | 13 +++++++++++++ .../templates/wagtailusers/groups/create.html | 18 +----------------- .../templates/wagtailusers/groups/edit.html | 18 +----------------- .../groups/includes/group_form_js.html | 13 +++++++++++++ 4 files changed, 28 insertions(+), 34 deletions(-) create mode 100644 wagtail/wagtailusers/static_src/wagtailusers/js/group-form.js create mode 100644 wagtail/wagtailusers/templates/wagtailusers/groups/includes/group_form_js.html 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..e2773d66b --- /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 9dc553834..b5712e589 100644 --- a/wagtail/wagtailusers/templates/wagtailusers/groups/create.html +++ b/wagtail/wagtailusers/templates/wagtailusers/groups/create.html @@ -33,21 +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 5c9eb2414..ddf76625a 100644 --- a/wagtail/wagtailusers/templates/wagtailusers/groups/edit.html +++ b/wagtail/wagtailusers/templates/wagtailusers/groups/edit.html @@ -41,21 +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 %}