66 * Set up the form in a modal after being successfully attached to the body.
77 */
88function attachUserForm ( ) {
9- $ ( "body" ) . on ( 'renderSuccess.ufModal' , function ( data ) {
9+ $ ( "body" ) . on ( 'renderSuccess.ufModal' , function ( data ) {
1010 var modal = $ ( this ) . ufModal ( 'getModal' ) ;
1111 var form = modal . find ( '.js-form' ) ;
1212
@@ -15,14 +15,16 @@ function attachUserForm() {
1515 width : '100%'
1616 } ) ;
1717
18+
19+
1820 // Set up the form for submission
1921 form . ufForm ( {
2022 validator : page . validators
2123 } ) . on ( "submitSuccess.ufForm" , function ( ) {
2224 // Reload page on success
2325 window . location . reload ( ) ;
2426 } ) ;
25-
27+
2628 toggleSetPasswordMode ( modal , 'link' ) ;
2729
2830 // On submission, submit either the PUT request, or POST for a password reset, depending on the toggle state
@@ -47,14 +49,14 @@ function toggleSetPasswordMode(el, changePasswordMode) {
4749 if ( validator ) {
4850 //Iterate through named elements inside of the form, and mark them as error free
4951 el . find ( "input[type='password']" ) . each ( function ( ) {
50- validator . successList . push ( this ) ; //mark as error free
52+ validator . successList . push ( this ) ; //mark as error free
5153 } ) ;
52- validator . resetForm ( ) ; //remove error class on name elements and clear history
53- validator . reset ( ) ; //remove all error and success data
54+ validator . resetForm ( ) ; //remove error class on name elements and clear history
55+ validator . reset ( ) ; //remove all error and success data
5456 }
5557 el . find ( "input[type='password']" ) . closest ( '.form-group' )
56- . removeClass ( 'has-error has-success' ) ;
57- el . find ( '.form-control-feedback' ) . each ( function ( ) {
58+ . removeClass ( 'has-error has-success' ) ;
59+ el . find ( '.form-control-feedback' ) . each ( function ( ) {
5860 $ ( this ) . remove ( ) ;
5961 } ) ;
6062 } else {
@@ -80,14 +82,14 @@ function toggleChangePasswordMode(el, userName, changePasswordMode) {
8082 if ( validator ) {
8183 //Iterate through named elements inside of the form, and mark them as error free
8284 el . find ( "input[type='password']" ) . each ( function ( ) {
83- validator . successList . push ( this ) ; //mark as error free
85+ validator . successList . push ( this ) ; //mark as error free
8486 } ) ;
85- validator . resetForm ( ) ; //remove error class on name elements and clear history
86- validator . reset ( ) ; //remove all error and success data
87+ validator . resetForm ( ) ; //remove error class on name elements and clear history
88+ validator . reset ( ) ; //remove all error and success data
8789 }
8890 el . find ( "input[type='password']" ) . closest ( '.form-group' )
89- . removeClass ( 'has-error has-success' ) ;
90- el . find ( '.form-control-feedback' ) . each ( function ( ) {
91+ . removeClass ( 'has-error has-success' ) ;
92+ el . find ( '.form-control-feedback' ) . each ( function ( ) {
9193 $ ( this ) . remove ( ) ;
9294 } ) ;
9395 } else {
@@ -130,19 +132,19 @@ function updateUser(userName, fieldName, fieldValue) {
130132 return $ . parseJSON ( result ) ;
131133 }
132134 } catch ( e ) {
133- // statements to handle any exceptions
134- console . log ( "Warning: Could not parse expected JSON response." ) ;
135- return { } ;
135+ // statements to handle any exceptions
136+ console . log ( "Warning: Could not parse expected JSON response." ) ;
137+ return { } ;
136138 }
137139 }
138140 }
139- } ) . fail ( function ( jqXHR ) {
141+ } ) . fail ( function ( jqXHR ) {
140142 // Error messages
141143 if ( debugAjax && jqXHR . responseText ) {
142144 document . write ( jqXHR . responseText ) ;
143145 document . close ( ) ;
144146 } else {
145- console . log ( "Error (" + jqXHR . status + "): " + jqXHR . responseText ) ;
147+ console . log ( "Error (" + jqXHR . status + "): " + jqXHR . responseText ) ;
146148
147149 // Display errors on failure
148150 // TODO: ufAlerts widget should have a 'destroy' method
@@ -151,12 +153,12 @@ function updateUser(userName, fieldName, fieldValue) {
151153 } else {
152154 $ ( "#alerts-page" ) . ufAlerts ( 'clear' ) ;
153155 }
154-
156+
155157 $ ( "#alerts-page" ) . ufAlerts ( 'fetch' ) . ufAlerts ( 'render' ) ;
156158 }
157159
158160 return jqXHR ;
159- } ) . done ( function ( response ) {
161+ } ) . done ( function ( response ) {
160162 window . location . reload ( ) ;
161163 } ) ;
162164}
@@ -166,8 +168,8 @@ function updateUser(userName, fieldName, fieldValue) {
166168 * @param {module:jQuery } el jQuery wrapped element to target.
167169 * @param {{delete_redirect: string} } options Options used to modify behaviour of button actions.
168170 */
169- function bindUserButtons ( el , options ) {
170- if ( ! options ) options = { } ;
171+ function bindUserButtons ( el , options ) {
172+ if ( ! options ) options = { } ;
171173
172174 /**
173175 * Buttons that launch a modal dialog
@@ -200,38 +202,38 @@ function updateUser(userName, fieldName, fieldValue) {
200202 msgTarget : $ ( "#alerts-page" )
201203 } ) ;
202204
203- $ ( "body" ) . on ( 'renderSuccess.ufModal' , function ( data ) {
205+ $ ( "body" ) . on ( 'renderSuccess.ufModal' , function ( data ) {
204206 var modal = $ ( this ) . ufModal ( 'getModal' ) ;
205207 var form = modal . find ( '.js-form' ) ;
206208
207209 // Set up collection widget
208210 var roleWidget = modal . find ( '.js-form-roles' ) ;
209211 roleWidget . ufCollection ( {
210- dropdown : {
212+ dropdown : {
211213 ajax : {
212- url : site . uri . public + '/api/roles'
214+ url : site . uri . public + '/api/roles'
213215 } ,
214- placeholder : "Select a role"
216+ placeholder : "Select a role"
215217 } ,
216218 dropdownTemplate : modal . find ( '#user-roles-select-option' ) . html ( ) ,
217- rowTemplate : modal . find ( '#user-roles-row' ) . html ( )
219+ rowTemplate : modal . find ( '#user-roles-row' ) . html ( )
218220 } ) ;
219221
220222 // Get current roles and add to widget
221223 $ . getJSON ( site . uri . public + '/api/users/u/' + userName + '/roles' )
222- . done ( function ( data ) {
223- $ . each ( data . rows , function ( idx , role ) {
224- role . text = role . name ;
225- roleWidget . ufCollection ( 'addRow' , role ) ;
224+ . done ( function ( data ) {
225+ $ . each ( data . rows , function ( idx , role ) {
226+ role . text = role . name ;
227+ roleWidget . ufCollection ( 'addRow' , role ) ;
228+ } ) ;
226229 } ) ;
227- } ) ;
228230
229231 // Set up form for submission
230232 form . ufForm ( )
231- . on ( "submitSuccess.ufForm" , function ( ) {
232- // Reload page on success
233- window . location . reload ( ) ;
234- } ) ;
233+ . on ( "submitSuccess.ufForm" , function ( ) {
234+ // Reload page on success
235+ window . location . reload ( ) ;
236+ } ) ;
235237 } ) ;
236238 } ) ;
237239
@@ -248,7 +250,7 @@ function updateUser(userName, fieldName, fieldValue) {
248250 msgTarget : $ ( "#alerts-page" )
249251 } ) ;
250252
251- $ ( "body" ) . on ( 'renderSuccess.ufModal' , function ( ) {
253+ $ ( "body" ) . on ( 'renderSuccess.ufModal' , function ( ) {
252254 var modal = $ ( this ) . ufModal ( 'getModal' ) ;
253255 var form = modal . find ( '.js-form' ) ;
254256
@@ -284,16 +286,16 @@ function updateUser(userName, fieldName, fieldValue) {
284286 msgTarget : $ ( "#alerts-page" )
285287 } ) ;
286288
287- $ ( "body" ) . on ( 'renderSuccess.ufModal' , function ( ) {
289+ $ ( "body" ) . on ( 'renderSuccess.ufModal' , function ( ) {
288290 var modal = $ ( this ) . ufModal ( 'getModal' ) ;
289291 var form = modal . find ( '.js-form' ) ;
290292
291293 form . ufForm ( )
292- . on ( "submitSuccess.ufForm" , function ( ) {
293- // Navigate or reload page on success
294- if ( options . delete_redirect ) window . location . href = options . delete_redirect ;
295- else window . location . reload ( ) ;
296- } ) ;
294+ . on ( "submitSuccess.ufForm" , function ( ) {
295+ // Navigate or reload page on success
296+ if ( options . delete_redirect ) window . location . href = options . delete_redirect ;
297+ else window . location . reload ( ) ;
298+ } ) ;
297299 } ) ;
298300 } ) ;
299301
@@ -307,12 +309,12 @@ function updateUser(userName, fieldName, fieldValue) {
307309 updateUser ( btn . data ( 'user_name' ) , 'flag_verified' , '1' ) ;
308310 } ) ;
309311
310- el . find ( '.js-user-enable' ) . click ( function ( ) {
312+ el . find ( '.js-user-enable' ) . click ( function ( ) {
311313 var btn = $ ( this ) ;
312314 updateUser ( btn . data ( 'user_name' ) , 'flag_enabled' , '1' ) ;
313315 } ) ;
314316
315- el . find ( '.js-user-disable' ) . click ( function ( ) {
317+ el . find ( '.js-user-disable' ) . click ( function ( ) {
316318 var btn = $ ( this ) ;
317319 updateUser ( btn . data ( 'user_name' ) , 'flag_enabled' , '0' ) ;
318320 } ) ;
@@ -330,4 +332,4 @@ function bindUserCreationButton(el) {
330332
331333 attachUserForm ( ) ;
332334 } ) ;
333- } ;
335+ } ;
0 commit comments