| ... |
... |
@@ -1,7 +3,218 @@ |
| 1 |
|
-{{include reference='XWiki.UserDirectoryMacros'/}} |
| 2 |
|
- |
| 3 |
3 |
{{velocity}} |
| 4 |
|
-#set ($customize = $request.customize == 'true') |
| 5 |
|
-#displayUserDirectory($customize) |
| 6 |
|
-#set ($displayDocExtra = false) |
|
2 |
+#set ($xwikiUsersClassReference = $services.model.createDocumentReference($xcontext.database, 'XWiki', 'XWikiUsers')) |
|
3 |
+#set ($xwikiUsersClassName = $services.model.serialize($xwikiUsersClassReference)) |
|
4 |
+#set ($xwikiUsersClass = $xwiki.getClass($xwikiUsersClassName)) |
|
5 |
+#set ($directoryPreferencesClassReference = $services.model.createDocumentReference($xcontext.database, 'XWiki', 'UserDirectoryPreferencesClass')) |
|
6 |
+#set ($directoryPreferencesClassName = $services.model.serialize($directoryPreferencesClassReference)) |
|
7 |
+## |
|
8 |
+## Fake user used in some cases to properly display class properties |
|
9 |
+#set ($fakeUser = false) |
|
10 |
+## |
|
11 |
+## Set the fixed columns that we want the user directory to always show. |
|
12 |
+#set ($columns = ['_avatar', 'doc.fullName']) |
|
13 |
+## |
|
14 |
+## The columns that the user directory will default to when no user preferences exist or when the user resets to default. |
|
15 |
+#set ($defaultColumns = ['first_name', 'last_name']) |
|
16 |
+#set ($defaultColumnsString = $stringtool.join($defaultColumns, ' ')) |
|
17 |
+#set ($isCustomized = false) |
|
18 |
+## |
|
19 |
+## Guests and superadmin don't have an user profile and, therefore, no preferences. Offer default. |
|
20 |
+#if ($isGuest || $isSuperAdmin) |
|
21 |
+ #if ($isGuest) |
|
22 |
+ {{info}}$services.localization.render('xe.userdirectory.canCustomizeInfoGuest', ["path:$doc.getURL('login')"]){{/info}} |
|
23 |
+ #end |
|
24 |
+ ## Use the default columns for guests or superadmin. |
|
25 |
+ #set ($discard = $columns.addAll($defaultColumns)) |
|
26 |
+ ## Fake a user (in-memory) object inside a fake user profile page in order to be able to nicely display translated property pretty names of the XWikiUsers class. |
|
27 |
+ #set ($userPreferences = $doc) |
|
28 |
+ #set ($fakeUser = $doc.newObject($xwikiUsersClassName)) |
|
29 |
+#else |
|
30 |
+ ## User is logged in. |
|
31 |
+ #set ($userPreferences = $xwiki.getDocument($xcontext.userReference)) |
|
32 |
+ #set ($userPreference = $userPreferences.getObject($directoryPreferencesClassName)) |
|
33 |
+ #if (!$userPreference) |
|
34 |
+ ## Fake a user directory preference (in-memory) object just to be able to display the default values nicely. |
|
35 |
+ #set ($userPreference = $userPreferences.newObject($directoryPreferencesClassName)) |
|
36 |
+ #set ($discard = $userPreference.set('columns', $defaultColumnsString)) |
|
37 |
+ #end |
|
38 |
+ ## |
|
39 |
+ ## Read the user's preferences and build the list of columns to display. |
|
40 |
+ #set ($userColumnsString = $!{userPreference.getProperty('columns').value.trim()}) |
|
41 |
+ #foreach ($column in $userColumnsString.split('\s+')) |
|
42 |
+ ## Skip invalid or duplicate columns. Duplicate columns break the livetable filtering query. |
|
43 |
+ #if ($column.trim() != '' && $xwikiUsersClass.get($column) && !$columns.contains($column)) |
|
44 |
+ #set ($discard = $columns.add($column)) |
|
45 |
+ #end |
|
46 |
+ #end |
|
47 |
+ ## |
|
48 |
+ ## Check if they are the default preferences. |
|
49 |
+ #if ($userColumnsString != $defaultColumnsString) |
|
50 |
+ ## Mark it as a customized user directory. |
|
51 |
+ #set ($isCustomized = true) |
|
52 |
+ #end |
|
53 |
+ ## |
|
54 |
+ #set ($xredirect = $doc.getURL($xcontext.action, ${request.queryString})) |
|
55 |
+ ## |
|
56 |
+ ## Ability to customize the view. |
|
57 |
+ ## |
|
58 |
+ #if ($request.customize == 'true') |
|
59 |
+ #if ("$!request.action" != '') |
|
60 |
+ #if ($request.action == 'add') |
|
61 |
+ #set ($columnToAdd = $request.value.trim()) |
|
62 |
+ #if (!$columns.contains($columnToAdd)) |
|
63 |
+ #set ($userColumnsString = "$!userColumnsString $columnToAdd") |
|
64 |
+ #set ($userColumnsString = $userColumnsString.trim()) |
|
65 |
+ #set ($discard = $userPreference.set('columns', $userColumnsString)) |
|
66 |
+ #set ($discard = $userPreferences.save('Updated user directory preferences.')) |
|
67 |
+ #end |
|
68 |
+ #elseif ($request.action == 'reset') |
|
69 |
+ #set ($discard = $userPreferences.removeObject($userPreference)) |
|
70 |
+ #set ($discard = $userPreferences.save('Reset user directory preferences.')) |
|
71 |
+ #elseif ($request.action == 'save') |
|
72 |
+ #set ($discard = $userPreferences.updateObjectFromRequest($directoryPreferencesClassName)) |
|
73 |
+ #set ($discard = $userPreferences.save('Updated user directory preferences.')) |
|
74 |
+ #end |
|
75 |
+ ## Redirect using xredirect so that the page can be safely refreshed after an action. |
|
76 |
+ $response.sendRedirect($request.xredirect) |
|
77 |
+ #stop() |
|
78 |
+ #end |
|
79 |
+ ## |
|
80 |
+ ## Customize form. Note: Using 2 forms to be able to do everything without JavaScript. |
|
81 |
+ ## |
|
82 |
+ == {{translation key="xe.userdirectory.customizeColumnsTitle"/}} == |
|
83 |
+ {{html clean='false' wiki='true'}} |
|
84 |
+ <form class='xform half' action="$doc.getURL($xcontext.action, $request.queryString)" method='post'> |
|
85 |
+ <dl> |
|
86 |
+ <dt class='label'> |
|
87 |
+ <label>{{translation key="xe.userdirectory.customizeAvailableColumnsLabel"/}}</label> |
|
88 |
+ <span class='xHint'>{{translation key="xe.userdirectory.customizeAvailableColumnsHint"/}}</span> |
|
89 |
+ </dt> |
|
90 |
+ <dd> |
|
91 |
+ <select name='value'> |
|
92 |
+ #foreach ($property in $xwikiUsersClass.properties) |
|
93 |
+ ## Display translated class property pretty names. |
|
94 |
+ <option value="$property.name">$userPreferences.displayPrettyName($property.name)</option> |
|
95 |
+ #end |
|
96 |
+ </select> |
|
97 |
+ </dd> |
|
98 |
+ <dt> |
|
99 |
+ <input type='hidden' name='xredirect' value="$xredirect" /> |
|
100 |
+ <input type='hidden' name='action' value='add' /> |
|
101 |
+ <span class='buttonwrapper'> |
|
102 |
+ <input type="submit" class="button" name="submit" value="$services.localization.render('xe.userdirectory.customizeAddColumnButtonLabel')" /> |
|
103 |
+ </span> |
|
104 |
+ </dt> |
|
105 |
+ </dl> |
|
106 |
+ </form> |
|
107 |
+ <form class='xform half' action="$doc.getURL($xcontext.action, $request.queryString)" method='post'> |
|
108 |
+ <dl> |
|
109 |
+ <dt> |
|
110 |
+ <label>{{translation key="xe.userdirectory.customizeSelectedColumnsLabel"/}}</label> |
|
111 |
+ <span class='xHint'>{{translation key="xe.userdirectory.customizeSelectedColumnsHint"/}}</span> |
|
112 |
+ </dt> |
|
113 |
+ <dd>$userPreferences.display('columns', 'edit', $userPreference)</dd> |
|
114 |
+ <dt> |
|
115 |
+ <input type='hidden' name='xredirect' value="$xredirect" /> |
|
116 |
+ <input type='hidden' name='action' value='save' /> |
|
117 |
+ <span class='buttonwrapper'> |
|
118 |
+ <input class='button' type='submit' name='submit' value="$services.localization.render('xe.userdirectory.customizeSaveButtonLabel')"/> |
|
119 |
+ </span> |
|
120 |
+ <span class="buttonwrapper"> |
|
121 |
+ <a href="$doc.getURL($xcontext.action, "$request.queryString&action=reset&xredirect=$escapetool.url($xredirect)")" class='button secondary'>{{translation key="xe.userdirectory.customizeResetButtonLabel"/}}</a> |
|
122 |
+ </span> |
|
123 |
+ </dt> |
|
124 |
+ </dl> |
|
125 |
+ </form> |
|
126 |
+ ## |
|
127 |
+ == {{translation key="xe.userdirectory.customizePreviewTitle"/}} == |
|
128 |
+ {{/html}} |
|
129 |
+ #elseif ($isCustomized) |
|
130 |
+ {{warning}}$services.localization.render('xe.userdirectory.isCustomizedWarning', ["$doc.fullName", "customize=true&action=reset&xredirect=$escapetool.url($xredirect)", "$doc.fullName", 'customize=true']){{/warning}} |
|
131 |
+ #else |
|
132 |
+ {{info}}$services.localization.render('xe.userdirectory.canCustomizeInfo', ["$doc.fullName", 'customize=true']){{/info}} |
|
133 |
+ #end |
|
134 |
+#end |
|
135 |
+## |
|
136 |
+## Build and display the resulting livetable. |
|
137 |
+## |
|
138 |
+#set($columnsProperties = {}) |
|
139 |
+## |
|
140 |
+#foreach ($column in $columns) |
|
141 |
+ #set ($filterable = true) |
|
142 |
+ #set ($sortable = true) |
|
143 |
+ #set ($type = 'text') |
|
144 |
+ #set ($link = '') |
|
145 |
+ #set ($html = false) |
|
146 |
+ #set ($displayName = $userPreferences.displayPrettyName($column)) |
|
147 |
+ #set ($classPropertyType = $xwikiUsersClass.get($column).type) |
|
148 |
+ #if ($column == '_avatar') |
|
149 |
+ #set ($type = 'none') |
|
150 |
+ #set ($html = true) |
|
151 |
+ #set ($sortable = false) |
|
152 |
+ #set ($link = 'view') |
|
153 |
+ #elseif ($column == 'doc.fullName') |
|
154 |
+ #set ($link = 'view') |
|
155 |
+ #elseif ($classPropertyType.endsWith('ListClass')) |
|
156 |
+ #set($type = 'list') |
|
157 |
+ #elseif ($classPropertyType.endsWith('NumberClass')) |
|
158 |
+ #set($type = 'number') |
|
159 |
+ #elseif ($classPropertyType.endsWith('PasswordClass')) |
|
160 |
+ #set($sortable = false) |
|
161 |
+ #end |
|
162 |
+ #set ($columnValue = { 'type' : $type, 'link' : $link, 'html' : $html, 'sortable' : $sortable, 'displayName' : $displayName }) |
|
163 |
+ #set ($discard = $columnsProperties.put($column, $columnValue)) |
|
164 |
+#end |
|
165 |
+## |
|
166 |
+## Allow other applications to provide a different data source for the user directory livetable. For example, some application might define a different membership relation. |
|
167 |
+#set ($userDirectoryLivetableResultsReference = $services.model.createDocumentReference($xcontext.database, 'XWiki', 'UserDirectoryLivetableResultsOverride')) |
|
168 |
+#if (!$xwiki.exists($userDirectoryLivetableResultsReference)) |
|
169 |
+ ## If no override is present, use the default data source. |
|
170 |
+ #set ($userDirectoryLivetableResultsReference = $services.model.createDocumentReference($xcontext.database, 'XWiki', 'UserDirectoryLivetableResults')) |
|
171 |
+#end |
|
172 |
+## Note that we specify the class name even though we use a custom results page (which hard-codes it) because the class |
|
173 |
+## name is needed by the live table filters, to have a proper drop down list for Static List fields for instance |
|
174 |
+## (see XWIKI-9660). |
|
175 |
+#set ($options = { |
|
176 |
+ 'className': $services.model.serialize($xwikiUsersClassReference, 'local'), |
|
177 |
+ 'resultPage' : "$services.model.serialize($userDirectoryLivetableResultsReference)", |
|
178 |
+ 'translationPrefix' : 'xe.userdirectory.', |
|
179 |
+ 'tagCloud' : true, |
|
180 |
+ 'rowCount': 10 |
|
181 |
+}) |
|
182 |
+## Add a filter for subwikis |
|
183 |
+#if ($xcontext.database != $xcontext.mainWikiName && "$!services.wiki" != '' && "$!services.wiki.user" != '') |
|
184 |
+ #set($userScope = $services.wiki.user.getUserScope($services.wiki.currentWikiId)) |
|
185 |
+ #if ($userScope == 'GLOBAL_ONLY') |
|
186 |
+ #set($discard = $options.put('extraParams', 'userScope=global')) |
|
187 |
+ #else |
|
188 |
+ #set($discard = $options.put('extraParams', 'userScope=local')) |
|
189 |
+ #end |
|
190 |
+ #if ($userScope == 'LOCAL_AND_GLOBAL') |
|
191 |
+ #set($discard = $xwiki.jsx.use('Main.UserDirectory')) |
|
192 |
+ |
|
193 |
+ {{html}} |
|
194 |
+ <form class="xform third" action=""> |
|
195 |
+ <dl> |
|
196 |
+ <dt> |
|
197 |
+ <label for="userScopeFilter">$services.localization.render('userdirectory.userScopeFilter')</label> |
|
198 |
+ <span class="xHint">$services.localization.render('userdirectory.userScopeFilter.hint')</span> |
|
199 |
+ </dt> |
|
200 |
+ <dd> |
|
201 |
+ <select name="userScope" id="userScopeFilter"> |
|
202 |
+ <option value="local">$services.localization.render('userdirectory.userScopeFilter.local')</option> |
|
203 |
+ <option value="global">$services.localization.render('userdirectory.userScopeFilter.global')</option> |
|
204 |
+ </select> |
|
205 |
+ </dd> |
|
206 |
+ </dl> |
|
207 |
+ </form> |
|
208 |
+ {{/html}} |
|
209 |
+ |
|
210 |
+ #end |
|
211 |
+#end |
|
212 |
+#livetable('userdirectory' $columns $columnsProperties $options) |
|
213 |
+## |
|
214 |
+## Clean up any existing fake user from the current in-memory document to avoid side-effects |
|
215 |
+#if ($fakeUser) |
|
216 |
+ #set ($discard = $doc.removeObject($fakeUser)) |
|
217 |
+#end |
| 7 |
7 |
{{/velocity}} |