Skip to content

Commit 6ba90a6

Browse files
Merge pull request #939 from userfrosting/feature-deletionRedirectsBehaviour
Better deletion redirects for user, group, and role pages plus related improvements
2 parents dcaffcc + 589c1e3 commit 6ba90a6

16 files changed

Lines changed: 132 additions & 86 deletions

File tree

app/sprinkles/account/assets/userfrosting/js/pages/register.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
*/
99
$(document).ready(function() {
1010
// TOS modal
11-
$(this).find('.js-show-tos').click(function() {
11+
$(this).find('.js-show-tos').click(function(e) {
12+
e.preventDefault();
13+
1214
$("body").ufModal({
1315
sourceUrl: site.uri.public + "/modals/account/tos",
1416
msgTarget: $("#alerts-page")

app/sprinkles/account/src/Controller/AccountController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
use Illuminate\Database\Capsule\Manager as Capsule;
1414
use Psr\Http\Message\ResponseInterface as Response;
1515
use Psr\Http\Message\ServerRequestInterface as Request;
16-
use Slim\Exception\NotFoundException as NotFoundException;
1716
use UserFrosting\Fortress\RequestDataTransformer;
1817
use UserFrosting\Fortress\RequestSchema;
1918
use UserFrosting\Fortress\ServerSideValidator;
@@ -28,6 +27,7 @@
2827
use UserFrosting\Sprinkle\Core\Util\Captcha;
2928
use UserFrosting\Support\Exception\BadRequestException;
3029
use UserFrosting\Support\Exception\ForbiddenException;
30+
use UserFrosting\Support\Exception\NotFoundException;
3131

3232
/**
3333
* Controller class for /account/* URLs. Handles account-related activities, including login, registration, password recovery, and account settings.
@@ -489,7 +489,7 @@ public function pageRegister(Request $request, Response $response, $args)
489489
$localePathBuilder = $this->ci->localePathBuilder;
490490

491491
if (!$config['site.registration.enabled']) {
492-
throw new NotFoundException($request, $response);
492+
throw new NotFoundException();
493493
}
494494

495495
/** @var \UserFrosting\Sprinkle\Account\Authenticate\Authenticator $authenticator */

app/sprinkles/admin/assets/userfrosting/js/pages/dashboard.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
*/
77

88
$(document).ready(function() {
9-
$('.js-clear-cache').click(function() {
9+
$('.js-clear-cache').click(function(e) {
10+
e.preventDefault();
11+
1012
$("body").ufModal({
1113
sourceUrl: site.uri.public + "/modals/dashboard/clear-cache",
1214
ajaxParams: {

app/sprinkles/admin/assets/userfrosting/js/pages/group.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
$(document).ready(function() {
1111
// Control buttons
12-
bindGroupButtons($("#view-group"));
12+
bindGroupButtons($("#view-group"), { delete_redirect: page.delete_redirect });
1313

1414
// Table of users in this group
1515
$("#widget-group-users").ufTable({

app/sprinkles/admin/assets/userfrosting/js/pages/role.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
$(document).ready(function() {
1111
// Control buttons
12-
bindRoleButtons($("#view-role"));
12+
bindRoleButtons($("#view-role"), { delete_redirect: page.delete_redirect });
1313

1414
$("#widget-role-permissions").ufTable({
1515
dataUrl: site.uri.public + '/api/roles/r/' + page.role_slug + '/permissions',

app/sprinkles/admin/assets/userfrosting/js/pages/user.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
$(document).ready(function() {
1111
// Control buttons
12-
bindUserButtons($("#view-user"));
12+
bindUserButtons($("#view-user"), { delete_redirect: page.delete_redirect });
1313

1414
// Table of activities
1515
$("#widget-user-activities").ufTable({

app/sprinkles/admin/assets/userfrosting/js/widgets/groups.js

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,12 @@ function attachGroupForm() {
5353

5454
/**
5555
* Link group action buttons, for example in a table or on a specific group's page.
56+
* @param {module:jQuery} el jQuery wrapped element to target.
57+
* @param {{delete_redirect: string}} options Options used to modify behaviour of button actions.
5658
*/
57-
function bindGroupButtons(el) {
59+
function bindGroupButtons(el, options) {
60+
if (!options) options = {};
61+
5862
/**
5963
* Link row buttons after table is loaded.
6064
*/
@@ -63,7 +67,9 @@ function bindGroupButtons(el) {
6367
* Buttons that launch a modal dialog
6468
*/
6569
// Edit group details button
66-
el.find('.js-group-edit').click(function() {
70+
el.find('.js-group-edit').click(function(e) {
71+
e.preventDefault();
72+
6773
$("body").ufModal({
6874
sourceUrl: site.uri.public + "/modals/groups/edit",
6975
ajaxParams: {
@@ -76,7 +82,9 @@ function bindGroupButtons(el) {
7682
});
7783

7884
// Delete group button
79-
el.find('.js-group-delete').click(function() {
85+
el.find('.js-group-delete').click(function(e) {
86+
e.preventDefault();
87+
8088
$("body").ufModal({
8189
sourceUrl: site.uri.public + "/modals/groups/confirm-delete",
8290
ajaxParams: {
@@ -85,22 +93,25 @@ function bindGroupButtons(el) {
8593
msgTarget: $("#alerts-page")
8694
});
8795

88-
$("body").on('renderSuccess.ufModal', function (data) {
96+
$("body").on('renderSuccess.ufModal', function () {
8997
var modal = $(this).ufModal('getModal');
9098
var form = modal.find('.js-form');
9199

92100
form.ufForm()
93101
.on("submitSuccess.ufForm", function() {
94-
// Reload page on success
95-
window.location.reload();
102+
// Navigate or reload page on success
103+
if (options.delete_redirect) window.location.href = options.delete_redirect;
104+
else window.location.reload();
96105
});
97106
});
98107
});
99108
}
100109

101110
function bindGroupCreationButton(el) {
102111
// Link create button
103-
el.find('.js-group-create').click(function() {
112+
el.find('.js-group-create').click(function(e) {
113+
e.preventDefault();
114+
104115
$("body").ufModal({
105116
sourceUrl: site.uri.public + "/modals/groups/create",
106117
msgTarget: $("#alerts-page")

app/sprinkles/admin/assets/userfrosting/js/widgets/roles.js

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,20 @@ function attachRoleForm() {
4444

4545
/**
4646
* Link role action buttons, for example in a table or on a specific role's page.
47+
* @param {module:jQuery} el jQuery wrapped element to target.
48+
* @param {{delete_redirect: string}} options Options used to modify behaviour of button actions.
4749
*/
48-
function bindRoleButtons(el) {
50+
function bindRoleButtons(el, options) {
51+
if (!options) options = {};
52+
4953
/**
5054
* Link row buttons after table is loaded.
5155
*/
5256

5357
// Manage permissions button
54-
el.find('.js-role-permissions').click(function() {
58+
el.find('.js-role-permissions').click(function(e) {
59+
e.preventDefault();
60+
5561
var slug = $(this).data('slug');
5662
$("body").ufModal({
5763
sourceUrl: site.uri.public + "/modals/roles/permissions",
@@ -100,7 +106,9 @@ function bindRoleButtons(el) {
100106
* Buttons that launch a modal dialog
101107
*/
102108
// Edit role details button
103-
el.find('.js-role-edit').click(function() {
109+
el.find('.js-role-edit').click(function(e) {
110+
e.preventDefault();
111+
104112
$("body").ufModal({
105113
sourceUrl: site.uri.public + "/modals/roles/edit",
106114
ajaxParams: {
@@ -113,7 +121,9 @@ function bindRoleButtons(el) {
113121
});
114122

115123
// Delete role button
116-
el.find('.js-role-delete').click(function() {
124+
el.find('.js-role-delete').click(function(e) {
125+
e.preventDefault();
126+
117127
$("body").ufModal({
118128
sourceUrl: site.uri.public + "/modals/roles/confirm-delete",
119129
ajaxParams: {
@@ -128,16 +138,19 @@ function bindRoleButtons(el) {
128138

129139
form.ufForm()
130140
.on("submitSuccess.ufForm", function() {
131-
// Reload page on success
132-
window.location.reload();
141+
// Navigate or reload page on success
142+
if (options.delete_redirect) window.location.href = options.delete_redirect;
143+
else window.location.reload();
133144
});
134145
});
135146
});
136147
}
137148

138149
function bindRoleCreationButton(el) {
139150
// Link create button
140-
el.find('.js-role-create').click(function() {
151+
el.find('.js-role-create').click(function(e) {
152+
e.preventDefault();
153+
141154
$("body").ufModal({
142155
sourceUrl: site.uri.public + "/modals/roles/create",
143156
msgTarget: $("#alerts-page")

app/sprinkles/admin/assets/userfrosting/js/widgets/users.js

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -125,14 +125,19 @@ function updateUser(userName, fieldName, fieldValue) {
125125

126126
/**
127127
* Link user action buttons, for example in a table or on a specific user's page.
128+
* @param {module:jQuery} el jQuery wrapped element to target.
129+
* @param {{delete_redirect: string}} options Options used to modify behaviour of button actions.
128130
*/
129-
function bindUserButtons(el) {
131+
function bindUserButtons(el, options) {
132+
if (!options) options = {};
130133

131134
/**
132135
* Buttons that launch a modal dialog
133136
*/
134137
// Edit general user details button
135-
el.find('.js-user-edit').click(function() {
138+
el.find('.js-user-edit').click(function(e) {
139+
e.preventDefault();
140+
136141
$("body").ufModal({
137142
sourceUrl: site.uri.public + "/modals/users/edit",
138143
ajaxParams: {
@@ -145,7 +150,9 @@ function updateUser(userName, fieldName, fieldValue) {
145150
});
146151

147152
// Manage user roles button
148-
el.find('.js-user-roles').click(function() {
153+
el.find('.js-user-roles').click(function(e) {
154+
e.preventDefault();
155+
149156
var userName = $(this).data('user_name');
150157
$("body").ufModal({
151158
sourceUrl: site.uri.public + "/modals/users/roles",
@@ -191,7 +198,9 @@ function updateUser(userName, fieldName, fieldValue) {
191198
});
192199

193200
// Change user password button
194-
el.find('.js-user-password').click(function() {
201+
el.find('.js-user-password').click(function(e) {
202+
e.preventDefault();
203+
195204
var userName = $(this).data('user_name');
196205
$("body").ufModal({
197206
sourceUrl: site.uri.public + "/modals/users/password",
@@ -201,7 +210,7 @@ function updateUser(userName, fieldName, fieldValue) {
201210
msgTarget: $("#alerts-page")
202211
});
203212

204-
$("body").on('renderSuccess.ufModal', function (data) {
213+
$("body").on('renderSuccess.ufModal', function () {
205214
var modal = $(this).ufModal('getModal');
206215
var form = modal.find('.js-form');
207216

@@ -216,15 +225,19 @@ function updateUser(userName, fieldName, fieldValue) {
216225
toggleChangePasswordMode(modal, userName, 'link');
217226

218227
// On submission, submit either the PUT request, or POST for a password reset, depending on the toggle state
219-
modal.find("input[name='change_password_mode']").click(function() {
228+
modal.find("input[name='change_password_mode']").click(function(e) {
229+
e.preventDefault();
230+
220231
var changePasswordMode = $(this).val();
221232
toggleChangePasswordMode(modal, userName, changePasswordMode);
222233
});
223234
});
224235
});
225236

226237
// Delete user button
227-
el.find('.js-user-delete').click(function() {
238+
el.find('.js-user-delete').click(function(e) {
239+
e.preventDefault();
240+
228241
$("body").ufModal({
229242
sourceUrl: site.uri.public + "/modals/users/confirm-delete",
230243
ajaxParams: {
@@ -233,22 +246,25 @@ function updateUser(userName, fieldName, fieldValue) {
233246
msgTarget: $("#alerts-page")
234247
});
235248

236-
$("body").on('renderSuccess.ufModal', function (data) {
249+
$("body").on('renderSuccess.ufModal', function () {
237250
var modal = $(this).ufModal('getModal');
238251
var form = modal.find('.js-form');
239252

240253
form.ufForm()
241254
.on("submitSuccess.ufForm", function() {
242-
// Reload page on success
243-
window.location.reload();
255+
// Navigate or reload page on success
256+
if (options.delete_redirect) window.location.href = options.delete_redirect;
257+
else window.location.reload();
244258
});
245259
});
246260
});
247261

248262
/**
249263
* Direct action buttons
250264
*/
251-
el.find('.js-user-activate').click(function() {
265+
el.find('.js-user-activate').click(function(e) {
266+
e.preventDefault();
267+
252268
var btn = $(this);
253269
updateUser(btn.data('user_name'), 'flag_verified', '1');
254270
});
@@ -266,7 +282,9 @@ function updateUser(userName, fieldName, fieldValue) {
266282

267283
function bindUserCreationButton(el) {
268284
// Link create button
269-
el.find('.js-user-create').click(function() {
285+
el.find('.js-user-create').click(function(e) {
286+
e.preventDefault();
287+
270288
$("body").ufModal({
271289
sourceUrl: site.uri.public + "/modals/users/create",
272290
msgTarget: $("#alerts-page")

0 commit comments

Comments
 (0)