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 4.1
modifié par Florent Charton
sur 2025/08/19 15:15
Commentaire de modification : Install extension [org.xwiki.platform:xwiki-platform-administration-ui/17.4.3]

Résumé

Détails

Propriétés de la Page
Syntaxe
... ... @@ -1,1 +1,1 @@
1 -XWiki 2.0
1 +XWiki 2.1
Contenu
... ... @@ -1,49 +1,88 @@
1 1  {{velocity output="false"}}
2 -#macro (userScopeFilter)
3 - <select name="wiki">
4 - <option selected="selected" value="local">
5 - $escapetool.xml($services.localization.render('rightsmanager.local'))
6 - </option>
7 - <option value="global">
8 - $escapetool.xml($services.localization.render('rightsmanager.global'))
9 - </option>
10 - <option value="both">
11 - $escapetool.xml($services.localization.render('rightsmanager.both'))
12 - </option>
13 - </select>
14 -#end
15 -
16 -#macro (displayUsersLiveTable)
17 - #set ($columnOptions = {
18 - 'name': {'type': 'text', 'sortable': false, 'html': true},
19 - 'first_name': {'type': 'text', 'sortable': false},
20 - 'last_name': {'type': 'text', 'sortable': false},
21 - 'scope': {'type': 'list', 'sortable': false},
22 - '_actions': {
23 - 'actions': [
24 - 'edit',
25 - {'id': 'disable', 'icon': 'lock'},
26 - {'id': 'enable', 'icon': 'unlock'},
27 - 'delete'
28 - ],
29 - 'labels': false
30 - }
2 +#macro (displayUsersLiveData)
3 + #set ($properties = ['name', 'first_name', 'last_name', '_actions'])
4 + #set ($sourceParameters = {
5 + 'template': 'getusers.vm',
6 + 'translationPrefix': 'xe.admin.users.'
31 31   })
32 - #set ($columns = ['name', 'first_name', 'last_name', '_actions'])
33 - #set ($liveTableOptions = {
34 - 'url': $doc.getURL('view', 'xpage=getusers'),
35 - 'translationPrefix': 'xe.admin.users.',
36 - 'outputOnlyHtml': true
37 - })
38 38   #if (!$xcontext.isMainWiki())
39 - #set ($discard = $columns.add(3, 'scope'))
40 - ## We use the top filters option to show only the local users by default because the JavaScript code from the sheet
41 - ## is executed after the livetable is loaded. The JavaScript code removes the top filters and updates the scope filter
42 - ## afterwards.
43 - #set ($liveTableOptions.topFilters = "#userScopeFilter")
9 + #set ($discard = $properties.add(3, 'scope'))
44 44   #end
45 45   <div class="medium-avatars">
46 - #livetable('userstable' $columns $columnOptions $liveTableOptions)
12 + $services.liveData.render({
13 + 'id': 'userstable',
14 + 'source': 'liveTable',
15 + 'properties': $stringtool.join($properties, ','),
16 + 'sourceParameters': $escapetool.url($sourceParameters)
17 + }, {
18 + 'query': {
19 + 'filters': [
20 + {
21 + 'property': 'scope',
22 + 'constraints': [{
23 + 'operator': 'contains',
24 + 'value': 'local'
25 + }]
26 + }
27 + ]
28 + },
29 + 'meta': {
30 + 'propertyDescriptors': [
31 + {
32 + 'id': 'name',
33 + 'displayer': 'html',
34 + 'sortable': false,
35 + 'editable': false
36 + },
37 + {
38 + 'id': 'first_name',
39 + 'sortable': false,
40 + 'editable': false
41 + },
42 + {
43 + 'id': 'last_name',
44 + 'sortable': false,
45 + 'editable': false
46 + },
47 + {
48 + 'id': 'scope',
49 + 'sortable': false,
50 + 'editable': false,
51 + 'filter': {
52 + 'id': 'list',
53 + 'options': [
54 + {'value': 'local', 'label': $services.localization.render('rightsmanager.local')},
55 + {'value': 'global', 'label': $services.localization.render('rightsmanager.global')},
56 + {'value': 'both', 'label': $services.localization.render('rightsmanager.both')}
57 + ]
58 + }
59 + },
60 + {
61 + 'id': '_actions',
62 + 'displayer': {
63 + 'id': 'actions',
64 + 'actions': ['edit', 'disable', 'enable', 'delete']
65 + }
66 + }
67 + ],
68 + 'actions': [
69 + {
70 + 'id': 'disable',
71 + 'icon': 'lock',
72 + 'allowProperty': 'doc.hasdisable',
73 + 'urlProperty': 'doc.disable_url',
74 + 'extraIconClasses': 'text-warning'
75 + },
76 + {
77 + 'id': 'enable',
78 + 'icon': 'unlock',
79 + 'allowProperty': 'doc.hasenable',
80 + 'urlProperty': 'doc.enable_url',
81 + 'extraIconClasses': 'text-success'
82 + }
83 + ]
84 + }
85 + })
47 47   </div>
48 48   <p>
49 49   <button type="button" class="btn btn-primary" data-toggle="modal" data-target="${escapetool.h}createUserModal"
... ... @@ -83,7 +83,7 @@
83 83  
84 84  #macro (editUserModal)
85 85   <div class="modal" id="editUserModal" tabindex="-1" role="dialog" aria-labelledby="editUserModal-label"
86 - data-backdrop="static" data-keyboard="false" data-liveTable="#userstable" data-liveTableAction="edit">
125 + data-backdrop="static" data-keyboard="false" data-live-data="#userstable" data-live-data-action="edit">
87 87   <div class="modal-dialog modal-lg" role="document">
88 88   <div class="modal-content">
89 89   <div class="modal-header">
... ... @@ -113,7 +113,7 @@
113 113   ## have script or programming rights.
114 114   #userPicker_import
115 115   <div class="modal" id="deleteUserModal" tabindex="-1" role="dialog" aria-labelledby="deleteUserModal-label"
116 - data-liveTable="#userstable" data-liveTableAction="delete">
155 + data-live-data="#userstable" data-live-data-action="delete">
117 117   <div class="modal-dialog" role="document">
118 118   <div class="modal-content">
119 119   <div class="modal-header">
... ... @@ -167,11 +167,13 @@
167 167  #macro (maybeShowDeleteUserWarning $userReference $right)
168 168   #countPagesLastModifiedBy($userReference)
169 169   #if ($pageCount > 0)
170 - <div class="box errormessage xform">
209 + {{/html}}
210 +
211 + {{error cssClass="xform"}}
212 + {{html}}
171 171   #set ($pageIndexReference = $services.model.createDocumentReference(
172 172   $userReference.wikiReference.name, 'Main', 'AllDocs'))
173 - #set ($pageIndexURL = $xwiki.getURL($pageIndexReference) + '#|t=alldocs&doc.author=' +
174 - $escapetool.url($services.model.serialize($userReference, 'local')))
215 + #set ($pageIndexURL = $xwiki.getURL($pageIndexReference, 'view', "doc.author=${escapetool.url($services.model.serialize($userReference, 'local'))}"))
175 175   #set ($translationKey = "administration.section.users.deleteUser.${right}RightsWarning")
176 176   $services.localization.render($translationKey, ["<a href='$pageIndexURL'>", $pageCount, '</a>'])
177 177   <dl>
... ... @@ -196,7 +196,10 @@
196 196   [$rightTranslation]))</span>
197 197   </dd>
198 198   </dl>
199 - </div>
240 + {{/html}}
241 + {{/error}}
242 +
243 + {{html clean="false"}}
200 200   #end
201 201  #end
202 202  
... ... @@ -249,10 +249,10 @@
249 249   #set ($discard = $xwiki.jsx.use("XWiki.AdminUsersSheet"))
250 250  
251 251   {{html clean="false"}}
252 - #displayUsersLiveTable
253 - #createUserModal
254 - #editUserModal
255 - #deleteUserModal
296 + #displayUsersLiveData()
297 + #createUserModal()
298 + #editUserModal()
299 + #deleteUserModal()
256 256   {{/html}}
257 257   #end
258 258  #end
XWiki.JavaScriptExtension[0]
Code
... ... @@ -1,19 +1,10 @@
1 1  require.config({
2 2   paths: {
3 - 'xwiki-livetable-modal': new XWiki.Document('AdminGroupsSheet', 'XWiki').getURL('jsx', 'r=1')
3 + 'xwiki-livedata-modal': new XWiki.Document('AdminGroupsSheet', 'XWiki').getURL('jsx', 'r=1')
4 4   }
5 5  });
6 6  
7 -//
8 -// Scope Filtering
9 -//
10 -require(['jquery'], function($) {
11 - var options = $('#userstable').prev('.tipfilters').remove().find('select[name="wiki"]').html();
12 - var scopeFilter = $('#userstable .xwiki-livetable-display-filters select[name="scope"]')
13 - scopeFilter.attr('name', 'wiki').html(options);
14 -});
15 -
16 -require(['jquery', 'xwiki-meta', 'xwiki-livetable-modal', 'xwiki-events-bridge'], function($, xm) {
7 +require(['jquery', 'xwiki-meta', 'xwiki-livedata-modal', 'xwiki-events-bridge'], function($, xm) {
17 17   //
18 18   // User Creation
19 19   //
... ... @@ -54,7 +54,7 @@
54 54   notification.replace(new XWiki.widgets.Notification(errorMessage.text(), 'error'));
55 55   } else {
56 56   createUserModal.modal('hide');
57 - window.livetable_userstable.refresh();
48 + $('#userstable').data('liveData').updateEntries();
58 58   $('#userstable').trigger('xwiki:user:created');
59 59   notification.replace(new XWiki.widgets.Notification(
60 60   $jsontool.serialize($services.localization.render('xe.admin.users.create.done')),
... ... @@ -78,7 +78,7 @@
78 78   var loadEditForm = function(forceLock) {
79 79   var saveButton = editUserModal.find('.btn-primary').prop('disabled', true);
80 80   var rowData = editUserModal.data('rowData');
81 - var userReference = XWiki.Model.resolve(rowData.doc_fullName, XWiki.EntityType.DOCUMENT, [rowData.doc_wiki]);
72 + var userReference = XWiki.Model.resolve(rowData['doc.fullName'], XWiki.EntityType.DOCUMENT, [rowData['doc.wiki']]);
82 82   var userDocument = new XWiki.Document(userReference);
83 83   var editUserURL = userDocument.getURL('edit');
84 84   var parameters = {xpage: 'edituser'};
... ... @@ -112,7 +112,7 @@
112 112   $(document).trigger('xwiki:actions:beforeSave');
113 113   $.post(editForm.attr('action'), editForm.serialize()).then(() => {
114 114   $(document).trigger('xwiki:document:saved');
115 - editUserModal.modal('hide').data('liveTable').refresh();
106 + editUserModal.modal('hide').data('liveDataElement').data('liveData').updateEntries();
116 116   notification.replace(new XWiki.widgets.Notification(
117 117   $jsontool.serialize($services.localization.render('core.editors.saveandcontinue.notification.done')),
118 118   'done'
... ... @@ -146,30 +146,32 @@
146 146   failed: $jsontool.serialize($services.localization.render('administration.section.users.disableUser.failed'))
147 147   }
148 148   }
149 - var onToggleUser = function(event) {
150 - event.preventDefault();
151 - var actionTrigger = $(this);
152 - if (actionTrigger.hasClass('pending')) {
153 - // Another request is already in progress.
154 - return;
155 - }
156 - actionTrigger.addClass('pending');
157 - var action = event.data.action;
158 - var notification = new XWiki.widgets.Notification(notificationMessage[action].inProgress, 'inprogress');
159 - // The enable and disable actions redirect to the user profile by default which may take a lot of time to render so
160 - // we redirect to a URL that doesn't render anything.
161 - var emptyResponseURL = new XWiki.Document('AdminUsersSheet', 'XWiki').getURL('get', 'outputSyntax=plain');
162 - Promise.resolve($.post(actionTrigger.attr('href'), {'xredirect': emptyResponseURL})).then(function() {
163 - window['livetable_userstable'].refresh();
164 - notification.replace(new XWiki.widgets.Notification(notificationMessage[action].done, 'done'));
165 - }).catch(function() {
166 - notification.replace(new XWiki.widgets.Notification(notificationMessage[action].failed, 'error'));
167 - }).finally(function() {
168 - actionTrigger.removeClass('pending');
169 - });
170 - };
171 - $('#userstable').on('click', 'a.actionenable', {action: 'enable'}, onToggleUser);
172 - $('#userstable').on('click', 'a.actiondisable', {action: 'disable'}, onToggleUser);
140 +
141 + function onToggleUser(action) {
142 + return function (event) {
143 + event.preventDefault();
144 + var actionTrigger = $(this);
145 + if (actionTrigger.hasClass('pending')) {
146 + // Another request is already in progress.
147 + return;
148 + }
149 + actionTrigger.addClass('pending');
150 + var notification = new XWiki.widgets.Notification(notificationMessage[action].inProgress, 'inprogress');
151 + // The enable and disable actions redirect to the user profile by default which may take a lot of time to
152 + // render so we redirect to a URL that doesn't render anything.
153 + var emptyResponseURL = new XWiki.Document('AdminUsersSheet', 'XWiki').getURL('get', 'outputSyntax=plain');
154 + Promise.resolve($.post(actionTrigger.attr('href'), {'xredirect': emptyResponseURL})).then(function () {
155 + $('#userstable').data('liveData').updateEntries();
156 + notification.replace(new XWiki.widgets.Notification(notificationMessage[action].done, 'done'));
157 + }).catch(function () {
158 + notification.replace(new XWiki.widgets.Notification(notificationMessage[action].failed, 'error'));
159 + }).finally(function () {
160 + actionTrigger.removeClass('pending');
161 + });
162 + };
163 + }
164 + $(document).on('click', '#userstable a.action_enable', onToggleUser('enable'));
165 + $(document).on('click', '#userstable a.action_disable', onToggleUser('disable'));
173 173   })();
174 174  
175 175   //
... ... @@ -203,9 +203,9 @@
203 203  
204 204   deleteUserModal.on('show.bs.modal', function() {
205 205   var rowData = deleteUserModal.data('rowData');
206 - var userReference = rowData.doc_fullName;
207 - if (XWiki.currentWiki !== rowData.doc_wiki) {
208 - userReference = XWiki.Model.resolve(userReference, XWiki.EntityType.DOCUMENT, [rowData.doc_wiki]);
199 + var userReference = rowData['doc.fullName'];
200 + if (XWiki.currentWiki !== rowData['doc.wiki']) {
201 + userReference = XWiki.Model.resolve(userReference, XWiki.EntityType.DOCUMENT, [rowData['doc.wiki']]);
209 209   userReference = XWiki.Model.serialize(userReference);
210 210   }
211 211   deleteUserModal.data('userReference', userReference);
... ... @@ -259,8 +259,8 @@
259 259   newAuthor: deleteUserModal.find('#newAuthor').val(),
260 260   form_token: xm.form_token
261 261   }).then(() => {
262 - deleteUserModal.data('liveTable').deleteRow(deleteUserModal.data('rowIndex'));
263 - deleteUserModal.data('liveTableElement').trigger('xwiki:user:deleted', {reference: userReference});
255 + deleteUserModal.data('liveDataElement').data('liveData').updateEntries();
256 + deleteUserModal.data('liveDataElement').trigger('xwiki:user:deleted', {reference: userReference});
264 264   notification.replace(new XWiki.widgets.Notification(
265 265   $jsontool.serialize($services.localization.render('xe.admin.users.delete.done')),
266 266   'done'
XWiki.StyleSheetExtension[0]
Code
... ... @@ -1,19 +3,4 @@
1 -#template('colorThemeInit.vm')
2 -
3 3  /**
4 - * Users Live Table
5 - */
6 -#userstable td[data-title] {
7 - vertical-align: middle;
8 -}
9 -#userstable .actiondisable .action-icon {
10 - color: $theme.notificationWarningColor;
11 -}
12 -#userstable .actionenable .action-icon {
13 - color: $theme.notificationSuccessColor;
14 -}
15 -
16 -/**
17 17   * Delete User Modal
18 18   */
19 19  #deleteUserModal .userName {
Parser le contenu
... ... @@ -1,1 +1,1 @@
1 -Oui
1 +Non
Content Type
... ... @@ -1,1 +1,1 @@
1 -CSS
1 +LESS