Modifications pour le document AdminUsersSheet

Modifié par Florent Charton le 2025/08/19 15:15

Depuis la version 1.1
modifié par superadmin
sur 2022/06/20 08:48
Commentaire de modification : Install extension [org.xwiki.platform:xwiki-platform-administration-ui/13.10.6]
À la version 2.1
modifié par Florent Charton
sur 2024/08/08 18:43
Commentaire de modification : Install extension [org.xwiki.platform:xwiki-platform-administration-ui/15.10.11]

Résumé

Détails

Propriétés de la Page
Auteur du document
... ... @@ -1,1 +1,1 @@
1 -XWiki.superadmin
1 +xwiki:XWiki.fcharton
XWiki.JavaScriptExtension[0]
Code
... ... @@ -20,7 +20,7 @@
20 20   var createUserModal = $('#createUserModal');
21 21  
22 22   var validateCreateUserForm = function(form) {
23 - return form.size() > 0 && (!window.LiveValidation ||
23 + return form.length && (!window.LiveValidation ||
24 24   LiveValidation.massValidate(LiveValidationForm.getInstance(form[0]).fields));
25 25   };
26 26  
... ... @@ -35,7 +35,7 @@
35 35   createUserModalBody.removeClass('loading').append(createUserForm);
36 36   $(document).trigger('xwiki:dom:updated', {'elements': createUserModalBody.toArray()});
37 37   createUserForm.find(':input').filter(':visible').first().focus();
38 - createUserButton.prop('disabled', createUserForm.size() === 0);
38 + createUserButton.prop('disabled', !createUserForm.length);
39 39   });
40 40   }).on('click', '.btn-primary', function(event) {
41 41   var createUserForm = createUserModal.find('form#register');
... ... @@ -47,9 +47,9 @@
47 47   $jsontool.serialize($services.localization.render('xe.admin.users.create.inProgress')),
48 48   'inprogress'
49 49   );
50 - $.post(createUserForm.attr('action'), createUserForm.serialize()).done(function(html) {
50 + $.post(createUserForm.attr('action'), createUserForm.serialize()).then(html => {
51 51   var errorMessage = $('<div/>').html(html).find('.errormessage, .LV_validation_message.LV_invalid');
52 - if (errorMessage.size() > 0) {
52 + if (errorMessage.length) {
53 53   createUserButton.prop('disabled', false);
54 54   notification.replace(new XWiki.widgets.Notification(errorMessage.text(), 'error'));
55 55   } else {
... ... @@ -61,7 +61,7 @@
61 61   'done'
62 62   ));
63 63   }
64 - }).fail(function (response) {
64 + }).catch(() => {
65 65   createUserButton.prop('disabled', false);
66 66   notification.replace(new XWiki.widgets.Notification(
67 67   $jsontool.serialize($services.localization.render('xe.admin.users.create.failed')),
... ... @@ -92,7 +92,7 @@
92 92   $(document).trigger('xwiki:dom:updated', {'elements': self.toArray()});
93 93   var editUserForm = editUserModal.find('form#edituser');
94 94   editUserForm.find(':input').filter(':visible').first().focus();
95 - saveButton.prop('disabled', editUserForm.size() === 0);
95 + saveButton.prop('disabled', !editUserForm.length);
96 96   });
97 97   };
98 98  
... ... @@ -110,7 +110,7 @@
110 110   'inprogress'
111 111   );
112 112   $(document).trigger('xwiki:actions:beforeSave');
113 - $.post(editForm.attr('action'), editForm.serialize()).done(function() {
113 + $.post(editForm.attr('action'), editForm.serialize()).then(() => {
114 114   $(document).trigger('xwiki:document:saved');
115 115   editUserModal.modal('hide').data('liveTable').refresh();
116 116   notification.replace(new XWiki.widgets.Notification(
... ... @@ -117,7 +117,7 @@
117 117   $jsontool.serialize($services.localization.render('core.editors.saveandcontinue.notification.done')),
118 118   'done'
119 119   ));
120 - }).fail(function (response) {
120 + }).catch(response => {
121 121   saveButton.prop('disabled', false);
122 122   var message = $jsontool.serialize($services.localization.render('core.editors.saveandcontinue.notification.error',
123 123   ['__reason__']));
... ... @@ -146,7 +146,7 @@
146 146   failed: $jsontool.serialize($services.localization.render('administration.section.users.disableUser.failed'))
147 147   }
148 148   }
149 - var onToggleUser = function(action, event) {
149 + var onToggleUser = function(event) {
150 150   event.preventDefault();
151 151   var actionTrigger = $(this);
152 152   if (actionTrigger.hasClass('pending')) {
... ... @@ -154,21 +154,22 @@
154 154   return;
155 155   }
156 156   actionTrigger.addClass('pending');
157 + var action = event.data.action;
157 157   var notification = new XWiki.widgets.Notification(notificationMessage[action].inProgress, 'inprogress');
158 158   // The enable and disable actions redirect to the user profile by default which may take a lot of time to render so
159 159   // we redirect to a URL that doesn't render anything.
160 160   var emptyResponseURL = new XWiki.Document('AdminUsersSheet', 'XWiki').getURL('get', 'outputSyntax=plain');
161 - $.post(actionTrigger.attr('href'), {'xredirect': emptyResponseURL}).done(function() {
162 + Promise.resolve($.post(actionTrigger.attr('href'), {'xredirect': emptyResponseURL})).then(function() {
162 162   window['livetable_userstable'].refresh();
163 163   notification.replace(new XWiki.widgets.Notification(notificationMessage[action].done, 'done'));
164 - }).fail(function() {
165 + }).catch(function() {
165 165   notification.replace(new XWiki.widgets.Notification(notificationMessage[action].failed, 'error'));
166 - }).always(function() {
167 + }).finally(function() {
167 167   actionTrigger.removeClass('pending');
168 168   });
169 169   };
170 - $('#userstable').on('click', 'a.actionenable', $.proxy(onToggleUser, null, 'enable'));
171 - $('#userstable').on('click', 'a.actiondisable', $.proxy(onToggleUser, null, 'disable'));
171 + $('#userstable').on('click', 'a.actionenable', {action: 'enable'}, onToggleUser);
172 + $('#userstable').on('click', 'a.actiondisable', {action: 'disable'}, onToggleUser);
172 172   })();
173 173  
174 174   //
... ... @@ -225,9 +225,9 @@
225 225   newAuthor: newAuthor,
226 226   requiredRight: requiredRight
227 227   });
228 - return newAuthorValidationRequest;
229 + return Promise.resolve(newAuthorValidationRequest);
229 229   } else {
230 - return $.Deferred().resolve({valid: true}).promise();
231 + return Promise.resolve({valid: true});
231 231   }
232 232   };
233 233   deleteUserModal.on('change', '#newAuthor', function(event) {
... ... @@ -236,17 +236,17 @@
236 236   var newAuthorField = $(event.target);
237 237   // Hide the previous error message.
238 238   newAuthorField.nextAll('.xErrorMsg').addClass('hidden');
239 - validateNewAuthor(newAuthorField.val(), newAuthorField.data('requiredRight')).done(function(result) {
240 + validateNewAuthor(newAuthorField.val(), newAuthorField.data('requiredRight')).then(function(result) {
240 240   if (result.valid === false) {
241 241   newAuthorField.nextAll('.xErrorMsg').removeClass('hidden');
242 242   }
243 - }).always(function() {
244 + }).finally(function() {
244 244   // Re-enable the modal submit button.
245 245   deleteUserButton.prop('disabled', false);
246 246   });
247 247   });
248 248  
249 - deleteUserButton.click(function() {
250 + deleteUserButton.on('click', function() {
250 250   var notification = new XWiki.widgets.Notification(
251 251   $jsontool.serialize($services.localization.render('xe.admin.users.delete.inProgress')),
252 252   'inprogress'
... ... @@ -257,7 +257,7 @@
257 257   docname: userReference,
258 258   newAuthor: deleteUserModal.find('#newAuthor').val(),
259 259   form_token: xm.form_token
260 - }).done(function() {
261 + }).then(() => {
261 261   deleteUserModal.data('liveTable').deleteRow(deleteUserModal.data('rowIndex'));
262 262   deleteUserModal.data('liveTableElement').trigger('xwiki:user:deleted', {reference: userReference});
263 263   notification.replace(new XWiki.widgets.Notification(
... ... @@ -264,7 +264,7 @@
264 264   $jsontool.serialize($services.localization.render('xe.admin.users.delete.done')),
265 265   'done'
266 266   ));
267 - }).fail(function() {
268 + }).catch(() => {
268 268   notification.replace(new XWiki.widgets.Notification(
269 269   $jsontool.serialize($services.localization.render('xe.admin.users.delete.failed')),
270 270   'error'