diff --git a/apps/users/templates/users/user_group_create_update.html b/apps/users/templates/users/user_group_create_update.html index 6baef2a94..dcf02adb9 100644 --- a/apps/users/templates/users/user_group_create_update.html +++ b/apps/users/templates/users/user_group_create_update.html @@ -47,5 +47,26 @@ $(document).ready(function () { closeOnSelect: false }); }) +.on("submit", "form", function (evt) { + evt.preventDefault(); + var the_url = '{% url 'api-users:user-group-list' %}'; + var redirect_to = '{% url "users:user-group-list" %}'; + var method = "POST"; + {% if type == "update" %} + the_url = '{% url 'api-users:user-group-detail' pk=object.id %}'; + method = "PUT"; + {% endif %} + var form = $("form"); + var data = form.serializeObject(); + objectAttrsIsList(data, ['users']); + var props = { + url: the_url, + data: data, + method: method, + form: form, + redirect_to: redirect_to + }; + formSubmit(props); +}) {% endblock %} diff --git a/apps/users/views/group.py b/apps/users/views/group.py index f0e267de3..2f19a8055 100644 --- a/apps/users/views/group.py +++ b/apps/users/views/group.py @@ -44,6 +44,7 @@ class UserGroupCreateView(PermissionsMixin, SuccessMessageMixin, CreateView): context = { 'app': _('Users'), 'action': _('Create user group'), + 'type': 'create' } kwargs.update(context) return super().get_context_data(**kwargs) @@ -61,6 +62,7 @@ class UserGroupUpdateView(PermissionsMixin, SuccessMessageMixin, UpdateView): context = { 'app': _('Users'), 'action': _('Update user group'), + 'type': 'update' } kwargs.update(context)