@@ -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
267283function 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