Modifications pour le document AdminUsersSheet

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

Depuis 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]
À 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]

Résumé

Détails

Propriétés de la Page
Auteur du document
... ... @@ -1,1 +1,1 @@
1 -xwiki:XWiki.fcharton
1 +XWiki.superadmin
XWiki.JavaScriptExtension[0]
Code
... ... @@ -20,7 +20,7 @@
20 20   var createUserModal = $('#createUserModal');
21 21  
22 22   var validateCreateUserForm = function(form) {
23 - return form.length && (!window.LiveValidation ||
23 + return form.size() > 0 && (!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.length);
38 + createUserButton.prop('disabled', createUserForm.size() === 0);
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()).then(html => {
50 + $.post(createUserForm.attr('action'), createUserForm.serialize()).done(function(html) {
51 51   var errorMessage = $('<div/>').html(html).find('.errormessage, .LV_validation_message.LV_invalid');
52 - if (errorMessage.length) {
52 + if (errorMessage.size() > 0) {
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 - }).catch(() => {
64 + }).fail(function (response) {
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.length);
95 + saveButton.prop('disabled', editUserForm.size() === 0);
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()).then(() => {
113 + $.post(editForm.attr('action'), editForm.serialize()).done(function() {
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 - }).catch(response => {
120 + }).fail(function (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(event) {
149 + var onToggleUser = function(action, event) {
150 150   event.preventDefault();
151 151   var actionTrigger = $(this);
152 152   if (actionTrigger.hasClass('pending')) {
... ... @@ -154,22 +154,21 @@
154 154   return;
155 155   }
156 156   actionTrigger.addClass('pending');
157 - var action = event.data.action;
158 158   var notification = new XWiki.widgets.Notification(notificationMessage[action].inProgress, 'inprogress');
159 159   // The enable and disable actions redirect to the user profile by default which may take a lot of time to render so
160 160   // we redirect to a URL that doesn't render anything.
161 161   var emptyResponseURL = new XWiki.Document('AdminUsersSheet', 'XWiki').getURL('get', 'outputSyntax=plain');
162 - Promise.resolve($.post(actionTrigger.attr('href'), {'xredirect': emptyResponseURL})).then(function() {
161 + $.post(actionTrigger.attr('href'), {'xredirect': emptyResponseURL}).done(function() {
163 163   window['livetable_userstable'].refresh();
164 164   notification.replace(new XWiki.widgets.Notification(notificationMessage[action].done, 'done'));
165 - }).catch(function() {
164 + }).fail(function() {
166 166   notification.replace(new XWiki.widgets.Notification(notificationMessage[action].failed, 'error'));
167 - }).finally(function() {
166 + }).always(function() {
168 168   actionTrigger.removeClass('pending');
169 169   });
170 170   };
171 - $('#userstable').on('click', 'a.actionenable', {action: 'enable'}, onToggleUser);
172 - $('#userstable').on('click', 'a.actiondisable', {action: 'disable'}, onToggleUser);
170 + $('#userstable').on('click', 'a.actionenable', $.proxy(onToggleUser, null, 'enable'));
171 + $('#userstable').on('click', 'a.actiondisable', $.proxy(onToggleUser, null, 'disable'));
173 173   })();
174 174  
175 175   //
... ... @@ -226,9 +226,9 @@
226 226   newAuthor: newAuthor,
227 227   requiredRight: requiredRight
228 228   });
229 - return Promise.resolve(newAuthorValidationRequest);
228 + return newAuthorValidationRequest;
230 230   } else {
231 - return Promise.resolve({valid: true});
230 + return $.Deferred().resolve({valid: true}).promise();
232 232   }
233 233   };
234 234   deleteUserModal.on('change', '#newAuthor', function(event) {
... ... @@ -237,17 +237,17 @@
237 237   var newAuthorField = $(event.target);
238 238   // Hide the previous error message.
239 239   newAuthorField.nextAll('.xErrorMsg').addClass('hidden');
240 - validateNewAuthor(newAuthorField.val(), newAuthorField.data('requiredRight')).then(function(result) {
239 + validateNewAuthor(newAuthorField.val(), newAuthorField.data('requiredRight')).done(function(result) {
241 241   if (result.valid === false) {
242 242   newAuthorField.nextAll('.xErrorMsg').removeClass('hidden');
243 243   }
244 - }).finally(function() {
243 + }).always(function() {
245 245   // Re-enable the modal submit button.
246 246   deleteUserButton.prop('disabled', false);
247 247   });
248 248   });
249 249  
250 - deleteUserButton.on('click', function() {
249 + deleteUserButton.click(function() {
251 251   var notification = new XWiki.widgets.Notification(
252 252   $jsontool.serialize($services.localization.render('xe.admin.users.delete.inProgress')),
253 253   'inprogress'
... ... @@ -258,7 +258,7 @@
258 258   docname: userReference,
259 259   newAuthor: deleteUserModal.find('#newAuthor').val(),
260 260   form_token: xm.form_token
261 - }).then(() => {
260 + }).done(function() {
262 262   deleteUserModal.data('liveTable').deleteRow(deleteUserModal.data('rowIndex'));
263 263   deleteUserModal.data('liveTableElement').trigger('xwiki:user:deleted', {reference: userReference});
264 264   notification.replace(new XWiki.widgets.Notification(
... ... @@ -265,7 +265,7 @@
265 265   $jsontool.serialize($services.localization.render('xe.admin.users.delete.done')),
266 266   'done'
267 267   ));
268 - }).catch(() => {
267 + }).fail(function() {
269 269   notification.replace(new XWiki.widgets.Notification(
270 270   $jsontool.serialize($services.localization.render('xe.admin.users.delete.failed')),
271 271   'error'