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,11 +15,7 @@ function attachUserForm() {
1515 width : '100%'
1616 } ) ;
1717
18- // Needed to allow select2 to render a 'empty' list item.
19- form . find ( ".js-select2-group" ) . select2 ( {
20- width : '100%' ,
21- templateResult : item => item . text || '\u200B'
22- } ) ;
18+
2319
2420 // Set up the form for submission
2521 form . ufForm ( {
@@ -48,14 +44,14 @@ function toggleChangePasswordMode(el, userName, changePasswordMode) {
4844 if ( validator ) {
4945 //Iterate through named elements inside of the form, and mark them as error free
5046 el . find ( "input[type='password']" ) . each ( function ( ) {
51- validator . successList . push ( this ) ; //mark as error free
47+ validator . successList . push ( this ) ; //mark as error free
5248 } ) ;
53- validator . resetForm ( ) ; //remove error class on name elements and clear history
54- validator . reset ( ) ; //remove all error and success data
49+ validator . resetForm ( ) ; //remove error class on name elements and clear history
50+ validator . reset ( ) ; //remove all error and success data
5551 }
5652 el . find ( "input[type='password']" ) . closest ( '.form-group' )
57- . removeClass ( 'has-error has-success' ) ;
58- el . find ( '.form-control-feedback' ) . each ( function ( ) {
53+ . removeClass ( 'has-error has-success' ) ;
54+ el . find ( '.form-control-feedback' ) . each ( function ( ) {
5955 $ ( this ) . remove ( ) ;
6056 } ) ;
6157 } else {
@@ -72,7 +68,7 @@ function toggleChangePasswordMode(el, userName, changePasswordMode) {
7268 * Update user field(s)
7369 */
7470function updateUser ( userName , fieldName , fieldValue ) {
75- var data = {
71+ var data = {
7672 'value' : fieldValue
7773 } ;
7874
@@ -98,19 +94,19 @@ function updateUser(userName, fieldName, fieldValue) {
9894 return $ . parseJSON ( result ) ;
9995 }
10096 } catch ( e ) {
101- // statements to handle any exceptions
102- console . log ( "Warning: Could not parse expected JSON response." ) ;
103- return { } ;
97+ // statements to handle any exceptions
98+ console . log ( "Warning: Could not parse expected JSON response." ) ;
99+ return { } ;
104100 }
105101 }
106102 }
107- } ) . fail ( function ( jqXHR ) {
103+ } ) . fail ( function ( jqXHR ) {
108104 // Error messages
109105 if ( debugAjax && jqXHR . responseText ) {
110106 document . write ( jqXHR . responseText ) ;
111107 document . close ( ) ;
112108 } else {
113- console . log ( "Error (" + jqXHR . status + "): " + jqXHR . responseText ) ;
109+ console . log ( "Error (" + jqXHR . status + "): " + jqXHR . responseText ) ;
114110
115111 // Display errors on failure
116112 // TODO: ufAlerts widget should have a 'destroy' method
@@ -124,7 +120,7 @@ function updateUser(userName, fieldName, fieldValue) {
124120 }
125121
126122 return jqXHR ;
127- } ) . done ( function ( response ) {
123+ } ) . done ( function ( response ) {
128124 window . location . reload ( ) ;
129125 } ) ;
130126}
@@ -134,8 +130,8 @@ function updateUser(userName, fieldName, fieldValue) {
134130 * @param {module:jQuery } el jQuery wrapped element to target.
135131 * @param {{delete_redirect: string} } options Options used to modify behaviour of button actions.
136132 */
137- function bindUserButtons ( el , options ) {
138- if ( ! options ) options = { } ;
133+ function bindUserButtons ( el , options ) {
134+ if ( ! options ) options = { } ;
139135
140136 /**
141137 * Buttons that launch a modal dialog
@@ -168,38 +164,38 @@ function updateUser(userName, fieldName, fieldValue) {
168164 msgTarget : $ ( "#alerts-page" )
169165 } ) ;
170166
171- $ ( "body" ) . on ( 'renderSuccess.ufModal' , function ( data ) {
167+ $ ( "body" ) . on ( 'renderSuccess.ufModal' , function ( data ) {
172168 var modal = $ ( this ) . ufModal ( 'getModal' ) ;
173169 var form = modal . find ( '.js-form' ) ;
174170
175171 // Set up collection widget
176172 var roleWidget = modal . find ( '.js-form-roles' ) ;
177173 roleWidget . ufCollection ( {
178- dropdown : {
174+ dropdown : {
179175 ajax : {
180- url : site . uri . public + '/api/roles'
176+ url : site . uri . public + '/api/roles'
181177 } ,
182- placeholder : "Select a role"
178+ placeholder : "Select a role"
183179 } ,
184180 dropdownTemplate : modal . find ( '#user-roles-select-option' ) . html ( ) ,
185- rowTemplate : modal . find ( '#user-roles-row' ) . html ( )
181+ rowTemplate : modal . find ( '#user-roles-row' ) . html ( )
186182 } ) ;
187183
188184 // Get current roles and add to widget
189185 $ . getJSON ( site . uri . public + '/api/users/u/' + userName + '/roles' )
190- . done ( function ( data ) {
191- $ . each ( data . rows , function ( idx , role ) {
192- role . text = role . name ;
193- roleWidget . ufCollection ( 'addRow' , role ) ;
186+ . done ( function ( data ) {
187+ $ . each ( data . rows , function ( idx , role ) {
188+ role . text = role . name ;
189+ roleWidget . ufCollection ( 'addRow' , role ) ;
190+ } ) ;
194191 } ) ;
195- } ) ;
196192
197193 // Set up form for submission
198194 form . ufForm ( )
199- . on ( "submitSuccess.ufForm" , function ( ) {
200- // Reload page on success
201- window . location . reload ( ) ;
202- } ) ;
195+ . on ( "submitSuccess.ufForm" , function ( ) {
196+ // Reload page on success
197+ window . location . reload ( ) ;
198+ } ) ;
203199 } ) ;
204200 } ) ;
205201
@@ -216,7 +212,7 @@ function updateUser(userName, fieldName, fieldValue) {
216212 msgTarget : $ ( "#alerts-page" )
217213 } ) ;
218214
219- $ ( "body" ) . on ( 'renderSuccess.ufModal' , function ( ) {
215+ $ ( "body" ) . on ( 'renderSuccess.ufModal' , function ( ) {
220216 var modal = $ ( this ) . ufModal ( 'getModal' ) ;
221217 var form = modal . find ( '.js-form' ) ;
222218
@@ -252,16 +248,16 @@ function updateUser(userName, fieldName, fieldValue) {
252248 msgTarget : $ ( "#alerts-page" )
253249 } ) ;
254250
255- $ ( "body" ) . on ( 'renderSuccess.ufModal' , function ( ) {
251+ $ ( "body" ) . on ( 'renderSuccess.ufModal' , function ( ) {
256252 var modal = $ ( this ) . ufModal ( 'getModal' ) ;
257253 var form = modal . find ( '.js-form' ) ;
258254
259255 form . ufForm ( )
260- . on ( "submitSuccess.ufForm" , function ( ) {
261- // Navigate or reload page on success
262- if ( options . delete_redirect ) window . location . href = options . delete_redirect ;
263- else window . location . reload ( ) ;
264- } ) ;
256+ . on ( "submitSuccess.ufForm" , function ( ) {
257+ // Navigate or reload page on success
258+ if ( options . delete_redirect ) window . location . href = options . delete_redirect ;
259+ else window . location . reload ( ) ;
260+ } ) ;
265261 } ) ;
266262 } ) ;
267263
@@ -275,12 +271,12 @@ function updateUser(userName, fieldName, fieldValue) {
275271 updateUser ( btn . data ( 'user_name' ) , 'flag_verified' , '1' ) ;
276272 } ) ;
277273
278- el . find ( '.js-user-enable' ) . click ( function ( ) {
274+ el . find ( '.js-user-enable' ) . click ( function ( ) {
279275 var btn = $ ( this ) ;
280276 updateUser ( btn . data ( 'user_name' ) , 'flag_enabled' , '1' ) ;
281277 } ) ;
282278
283- el . find ( '.js-user-disable' ) . click ( function ( ) {
279+ el . find ( '.js-user-disable' ) . click ( function ( ) {
284280 var btn = $ ( this ) ;
285281 updateUser ( btn . data ( 'user_name' ) , 'flag_enabled' , '0' ) ;
286282 } ) ;
@@ -298,4 +294,4 @@ function bindUserCreationButton(el) {
298294
299295 attachUserForm ( ) ;
300296 } ) ;
301- } ;
297+ } ;
0 commit comments