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