Changes for page User Directory
Last modified by Ecaterina Valica on 2016/11/17 15:21
From version 18.1
edited by Ecaterina Valica
on 2016/11/17 15:21
on 2016/11/17 15:21
Change comment:
Install extension [org.xwiki.platform:xwiki-platform-user-directory-ui-8.2.1]
Summary
-
Page properties (3 modified, 0 added, 0 removed)
-
Objects (0 modified, 0 added, 1 removed)
Details
- Page properties
-
- Title
-
... ... @@ -1,1 +1,1 @@ 1 -$s ervices.localization.render('xe.userdirectory.title')1 +$msg.get("xe.userdirectory.title") - Author
-
... ... @@ -1,1 +1,1 @@ 1 -XWiki. evalica1 +xwiki:XWiki.Admin - Content
-
... ... @@ -1,6 +3,176 @@ 1 -{{include reference='XWiki.UserDirectoryMacros'/}} 2 - 3 3 {{velocity}} 4 -#displayUserDirectory(true) 5 -#set($docextras=[]) 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 +## Set the fixed columns that we want the user directory to always show. 9 +#set ($columns = ['_avatar', 'doc.fullName']) 10 +## 11 +## The columns that the user directory will default to when no user preferences exist or when the user resets to default. 12 +#set ($defaultColumns = ['first_name', 'last_name']) 13 +#set ($defaultColumnsString = $stringtool.join($defaultColumns, ' ')) 14 +#set ($isCustomized = false) 15 +## 16 +## Guests and superadmin don't have an user profile and, therefore, no preferences. Offer default. 17 +#if ($isGuest || $isSuperAdmin) 18 + #if ($isGuest) 19 + {{info}}$msg.get('xe.userdirectory.canCustomizeInfoGuest', "path:$doc.getURL('login')"){{/info}} 20 + #end 21 + ## Use the default columns for guests or superadmin. 22 + #set ($discard = $columns.addAll($defaultColumns)) 23 + ## 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. 24 + #set ($userPreferences = $doc) 25 + #set ($fakeUser = $doc.newObject($xwikiUsersClassName)) 26 +#else 27 + ## User is logged in. 28 + #set ($userPreferences = $xwiki.getDocument($xcontext.userReference)) 29 + #set ($userPreference = $userPreferences.getObject($directoryPreferencesClassName)) 30 + #if (!$userPreference) 31 + ## Fake a user directory preference (in-memory) object just to be able to display the default values nicely. 32 + #set ($userPreference = $userPreferences.newObject($directoryPreferencesClassName)) 33 + #set ($discard = $userPreference.set('columns', $defaultColumnsString)) 34 + #end 35 + ## 36 + ## Read the user's preferences and build the list of columns to display. 37 + #set ($userColumnsString = $!{userPreference.getProperty('columns').value.trim()}) 38 + #foreach ($column in $userColumnsString.split('\s+')) 39 + ## Skip invalid or duplicate columns. Duplicate columns break the livetable filtering query. 40 + #if ($column.trim() != '' && $xwikiUsersClass.get($column) && !$columns.contains($column)) 41 + #set ($discard = $columns.add($column)) 42 + #end 43 + #end 44 + ## 45 + ## Check if they are the default preferences. 46 + #if ($userColumnsString != $defaultColumnsString) 47 + ## Mark it as a customized user directory. 48 + #set ($isCustomized = true) 49 + #end 50 + ## 51 + #set ($xredirect = $doc.getURL($xcontext.action, ${request.queryString})) 52 + ## 53 + ## Ability to customize the view. 54 + ## 55 + #if ($request.customize == 'true') 56 + #if ("$!request.action" != '') 57 + #if ($request.action == 'add') 58 + #set ($columnToAdd = $request.value.trim()) 59 + #if (!$columns.contains($columnToAdd)) 60 + #set ($userColumnsString = "$!userColumnsString $columnToAdd") 61 + #set ($userColumnsString = $userColumnsString.trim()) 62 + #set ($discard = $userPreference.set('columns', $userColumnsString)) 63 + #set ($discard = $userPreferences.save('Updated user directory preferences.')) 64 + #end 65 + #elseif ($request.action == 'reset') 66 + #set ($discard = $userPreferences.removeObject($userPreference)) 67 + #set ($discard = $userPreferences.save('Reset user directory preferences.')) 68 + #elseif ($request.action == 'save') 69 + #set ($discard = $userPreferences.updateObjectFromRequest($directoryPreferencesClassName)) 70 + #set ($discard = $userPreferences.save('Updated user directory preferences.')) 71 + #end 72 + ## Redirect using xredirect so that the page can be safely refreshed after an action. 73 + $response.sendRedirect($request.xredirect) 74 + #stop() 75 + #end 76 + ## 77 + ## Customize form. Note: Using 2 forms to be able to do everything without JavaScript. 78 + ## 79 + == $msg.get('xe.userdirectory.customizeColumnsTitle') == 80 + {{html clean='false' wiki='true'}} 81 + <form class='xform half' action="$doc.getURL($xcontext.action, $request.queryString)" method='post'> 82 + <dl> 83 + <dt class='label'> 84 + <label>$msg.get('xe.userdirectory.customizeAvailableColumnsLabel')</label> 85 + <span class='xHint'>$msg.get('xe.userdirectory.customizeAvailableColumnsHint')</span> 86 + </dt> 87 + <dd> 88 + <select name='value'> 89 + #foreach ($property in $xwikiUsersClass.properties) 90 + ## Display translated class property pretty names. 91 + <option value="$property.name">$userPreferences.displayPrettyName($property.name)</option> 92 + #end 93 + </select> 94 + </dd> 95 + <dt> 96 + <input type='hidden' name='xredirect' value="$xredirect" /> 97 + <input type='hidden' name='action' value='add' /> 98 + <span class='buttonwrapper'> 99 + <input type='submit' class='button' name='submit' value='$msg.get('xe.userdirectory.customizeAddColumnButtonLabel')' /> 100 + </span> 101 + </dt> 102 + </dl> 103 + </form> 104 + <form class='xform half' action="$doc.getURL($xcontext.action, $request.queryString)" method='post'> 105 + <dl> 106 + <dt> 107 + <label>$msg.get('xe.userdirectory.customizeSelectedColumnsLabel')</label> 108 + <span class='xHint'>$msg.get('xe.userdirectory.customizeSelectedColumnsHint')</span> 109 + </dt> 110 + <dd>$userPreferences.display('columns', 'edit', $userPreference)</dd> 111 + <dt> 112 + <input type='hidden' name='xredirect' value="$xredirect" /> 113 + <input type='hidden' name='action' value='save' /> 114 + <span class='buttonwrapper'> 115 + <input class='button' type='submit' name='submit' value="$msg.get('xe.userdirectory.customizeSaveButtonLabel')"/> 116 + </span> 117 + <span class="buttonwrapper"> 118 + <a href="$doc.getURL($xcontext.action, "$request.queryString&action=reset&xredirect=$escapetool.url($xredirect)")" class='button secondary'>$msg.get('xe.userdirectory.customizeResetButtonLabel')</a> 119 + </span> 120 + </dt> 121 + </dl> 122 + </form> 123 + ## 124 + <h2>$msg.get('xe.userdirectory.customizePreviewTitle')</h2> 125 + {{/html}} 126 + #elseif ($isCustomized) 127 + {{warning}}$msg.get('xe.userdirectory.isCustomizedWarning', ["$doc.fullName", "customize=true&action=reset&xredirect=$escapetool.url($xredirect)", "$doc.fullName", 'customize=true']){{/warning}} 128 + #else 129 + {{info}}$msg.get('xe.userdirectory.canCustomizeInfo', ["$doc.fullName", 'customize=true']){{/info}} 130 + #end 131 +#end 132 +## 133 +## Build and display the resulting livetable. 134 +## 135 +#set($columnsProperties = {}) 136 +## 137 +#foreach ($column in $columns) 138 + #set ($filterable = true) 139 + #set ($sortable = true) 140 + #set ($type = 'text') 141 + #set ($link = '') 142 + #set ($html = false) 143 + #set ($displayName = $userPreferences.displayPrettyName($column)) 144 + #set ($classPropertyType = $xwikiUsersClass.get($column).type) 145 + #if ($column == '_avatar') 146 + #set ($type = 'none') 147 + #set ($html = true) 148 + #set ($sortable = false) 149 + #set ($link = 'view') 150 + #elseif ($column == 'doc.fullName') 151 + #set ($link = 'view') 152 + #elseif ($classPropertyType.endsWith('ListClass')) 153 + #set($type = 'list') 154 + #elseif ($classPropertyType.endsWith('NumberClass')) 155 + #set($type = 'number') 156 + #elseif ($classPropertyType.endsWith('PasswordClass')) 157 + #set($sortable = false) 158 + #end 159 + #set ($columnValue = { 'type' : $type, 'link' : $link, 'html' : $html, 'sortable' : $sortable, 'displayName' : $displayName }) 160 + #set ($discard = $columnsProperties.put($column, $columnValue)) 161 +#end 162 +## 163 +## Allow other applications to provide a different data source for the user directory livetable. For example, some application might define a different membership relation. 164 +#set ($userDirectoryLivetableResultsReference = $services.model.createDocumentReference($xcontext.database, 'XWiki', 'UserDirectoryLivetableResultsOverride')) 165 +#if (!$xwiki.exists($userDirectoryLivetableResultsReference)) 166 + ## If no override is present, use the default data source. 167 + #set ($userDirectoryLivetableResultsReference = $services.model.createDocumentReference($xcontext.database, 'XWiki', 'UserDirectoryLivetableResults')) 168 +#end 169 +#set ($options = { 170 + 'resultPage' : "$services.model.serialize($userDirectoryLivetableResultsReference)", 171 + 'translationPrefix' : 'xe.userdirectory.', 172 + 'tagCloud' : true, 173 + 'rowCount': 10 174 +}) 175 +#livetable('userdirectory' $columns $columnsProperties $options) 6 6 {{/velocity}}
- XWiki.JavaScriptExtension[0]
-
- Caching policy
-
... ... @@ -1,1 +1,0 @@ 1 -long - Code
-
... ... @@ -1,41 +1,0 @@ 1 -(function(){ 2 - 3 - /** 4 - * Init 5 - */ 6 - function init() { 7 - var userScope = $('userScopeFilter'); 8 - if (userScope === null) { 9 - // Nothing to do 10 - return; 11 - } 12 - userScope.observe('change', onUserScopeChange); 13 - } 14 - 15 - function onUserScopeChange(event) { 16 - var value = $('userScopeFilter').value; 17 - var livetable = window["livetable_userdirectory"]; 18 - var url = livetable.getUrl; 19 - if (url.search("userScope=") >= 0) { 20 - // Replace the old value 21 - if (value == 'local') { 22 - url = url.replace("userScope=global", "userScope=local"); 23 - } else { 24 - url = url.replace("userScope=local", "userScope=global"); 25 - } 26 - } else { 27 - url = url + "&userScope=" + value; 28 - } 29 - livetable.getUrl = url; 30 - // Reload the livetable 31 - livetable.clearCache(); 32 - livetable.showRows(1, livetable.limit); 33 - } 34 - 35 - /** 36 - * Call Init 37 - */ 38 - (XWiki && XWiki.domIsLoaded && init()) || document.observe("xwiki:dom:loaded", init); 39 - 40 -})(); 41 - - Use this extension
-
... ... @@ -1,1 +1,0 @@ 1 -onDemand - Name
-
... ... @@ -1,1 +1,0 @@ 1 -Dynamic filter for user scope - Parse content
-
... ... @@ -1,1 +1,0 @@ 1 -No