Исходный код вики InvitationMembersCommon
Редактировал(а) superadmin 27.05.2025 04:11
Последние авторы
| author | version | line-number | content |
|---|---|---|---|
| 1 | {{velocity}} | ||
| 2 | #* | ||
| 3 | * Invitation Application | ||
| 4 | * This document contains common macros used by all documents in the Invitation Application which are | ||
| 5 | * only available to wiki members. | ||
| 6 | * | ||
| 7 | * Macros in this script don't rely on any variables except those which are passed to them and the following: | ||
| 8 | * | ||
| 9 | * $doc the com.xpn.xwiki.api.Document object representing the document containing this code. | ||
| 10 | * $msg the internationalization message provider containing a get(String) and a get(String, List) function | ||
| 11 | * $xcontext the com.xpn.xwiki.Context object for this request | ||
| 12 | * $xwiki an object of the com.xpn.xwiki.api.XWiki class. | ||
| 13 | * $escapetool an object of class org.apache.velocity.tools.generic.EscapeTool | ||
| 14 | * | ||
| 15 | * Macros also depend on other macros but only other macros which are contained in this script. | ||
| 16 | *### | ||
| 17 | #if($doc.documentReference.name == 'InvitationMembersCommon') | ||
| 18 | #set ($linkTarget = "${doc.getSpace()}.WebHome") | ||
| 19 | #set ($linkTarget = $services.rendering.escape($linkTarget, 'xwiki/2.1')) | ||
| 20 | {{info}}$services.localization.render('xe.invitation.internalDocument', [$linkTarget]){{/info}} | ||
| 21 | #end | ||
| 22 | ## | ||
| 23 | #* | ||
| 24 | * Display a table of messages. | ||
| 25 | * | ||
| 26 | * $messages (Collection<XObject>) the messages to view. | ||
| 27 | * | ||
| 28 | * $fieldsToDisplay (List<String>) fields which should be displayed. | ||
| 29 | * Options include: sendingUser, subjectLine, status, memo, recipient and _checkbox | ||
| 30 | * using the _checkbox option will create a checkbox which is named the message id number. | ||
| 31 | * the _history option will provide a link to view the memo log for the message. | ||
| 32 | * | ||
| 33 | * $asAdmin (Boolean) should the links point to displaying for admin or user (NOT FOR SECURITY) | ||
| 34 | * | ||
| 35 | * $numberOfRecipientsByMessage (Map<Integer, XObject>) the number of recipients for a given message (Optional) | ||
| 36 | * if specified and recipient field is set in $fieldsToDisplay | ||
| 37 | * then messages with multiple recipients will say "X recipients". | ||
| 38 | * | ||
| 39 | *### | ||
| 40 | #macro(displayMessageTable, $messages, $fieldsToDisplay, $asAdmin, $numberOfRecipientsByMessage) | ||
| 41 | #if(!$messages || $messages.size() < 1) | ||
| 42 | {{info}}$services.localization.render('xe.invitation.displayMessageTable.noMessages'){{/info}} | ||
| 43 | #else | ||
| 44 | |||
| 45 | (%class="message-table"%)((( | ||
| 46 | #set($checkboxCount = 0) | ||
| 47 | #foreach($field in $fieldsToDisplay) | ||
| 48 | #if($field == '_history') | ||
| 49 | |=(%class="history"%)$services.localization.render('xe.invitation.displayMessageTable.history')## | ||
| 50 | #elseif($field == '_checkbox') | ||
| 51 | |=(%class="checkboxcol"%)## | ||
| 52 | #elseif($field == 'recipient' || $field == 'sentDate') | ||
| 53 | ## We need to prevent tables from overflowing | ||
| 54 | ## unfortunately it makes displayMessageTable aware of the properties of a message. | ||
| 55 | |=(%class="$field"%)$services.localization.render("xe.invitation.displayMessageTable.${field}")## | ||
| 56 | #else | ||
| 57 | |=$services.localization.render("xe.invitation.displayMessageTable.${field}")## | ||
| 58 | #end | ||
| 59 | #end | ||
| 60 | |||
| 61 | #foreach($message in $messages) | ||
| 62 | #foreach($field in $fieldsToDisplay) | ||
| 63 | #if($field == 'sendingUser') | ||
| 64 | |[[$escapetool.xml($message.getProperty("$field").getValue())]]## | ||
| 65 | #elseif($field == 'subjectLine') | ||
| 66 | #set ($inspectValue = 'group') | ||
| 67 | #if ($asAdmin) | ||
| 68 | #set ($inspectValue = "${inspectValue}AsAdmin") | ||
| 69 | #end | ||
| 70 | #set ($queryString = $escapetool.url({ | ||
| 71 | 'inspect': $inspectValue, | ||
| 72 | 'messageID': $message.getProperty('messageID').getValue() | ||
| 73 | })) | ||
| 74 | |[[$escapetool.xml($message.getProperty('subjectLine').getValue())>>$doc.getFullName()||queryString="$queryString"]]## | ||
| 75 | #elseif($field == 'status' | ||
| 76 | && $numberOfRecipientsByMessage | ||
| 77 | && $numberOfRecipientsByMessage.get($message.get('recipient')) | ||
| 78 | && $numberOfRecipientsByMessage.get($message.get('recipient')) > 1) | ||
| 79 | |$services.localization.render('xe.invitation.displayMessageTable.various') | ||
| 80 | #elseif($field == 'status') | ||
| 81 | |#messageStatusForCode($message.getProperty('status').getValue())## | ||
| 82 | #elseif($field == 'recipient' | ||
| 83 | && $numberOfRecipientsByMessage | ||
| 84 | && $numberOfRecipientsByMessage.get($message.get('recipient')) | ||
| 85 | && $numberOfRecipientsByMessage.get($message.get('recipient')) > 1) | ||
| 86 | |$services.localization.render('xe.invitation.displayMessageTable.multipleRecipients', | ||
| 87 | [$numberOfRecipientsByMessage.get($message.get('recipient'))]) | ||
| 88 | #elseif($field == '_checkbox') | ||
| 89 | |<label for="messageCheckboxID$checkboxCount" class='sr-only'> | ||
| 90 | $escapetool.xml($services.localization.render('xe.invitation.displayMessageTable.checkbox.input.label')) | ||
| 91 | </label> | ||
| 92 | <input type="checkbox" id="messageCheckboxID$checkboxCount" name="messageID" | ||
| 93 | value="$message.getProperty('messageID').getValue()" ## | ||
| 94 | #set($checkboxCount = $checkboxCount + 1) | ||
| 95 | ## If there is only one message in the group, add the convenience of checking the box by default. | ||
| 96 | #if($messages.size() == 1) | ||
| 97 | checked="checked" ## | ||
| 98 | #end | ||
| 99 | />## | ||
| 100 | #elseif($field == '_history') | ||
| 101 | #set ($inspectValue = 'history') | ||
| 102 | #if ($asAdmin) | ||
| 103 | #set ($inspectValue = "${inspectValue}AsAdmin") | ||
| 104 | #end | ||
| 105 | #set ($queryString = $escapetool.url({ | ||
| 106 | 'inspect': $inspectValue, | ||
| 107 | 'messageID': $message.getProperty('messageID').getValue() | ||
| 108 | })) | ||
| 109 | |[[$services.localization.render('xe.invitation.displayMessageTable.history')>>## | ||
| 110 | $doc.getFullName()||queryString="$queryString"]]## | ||
| 111 | #else | ||
| 112 | |$services.rendering.escape($message.display($field, 'view') , $doc.syntax)## | ||
| 113 | #end | ||
| 114 | #end | ||
| 115 | |||
| 116 | #end##foreach message in mail | ||
| 117 | )))## end of class message-table | ||
| 118 | #end##if there is mail | ||
| 119 | #end##macro | ||
| 120 | ## | ||
| 121 | #* | ||
| 122 | * Display some tools for users and admins (if applicable). | ||
| 123 | * | ||
| 124 | * $mail (Map<String, XObject>) map of messages by their ID. | ||
| 125 | * | ||
| 126 | * $parameterMap (Map<String, String>) map obtained by calling getParameterMap on the servlet request object. | ||
| 127 | * | ||
| 128 | * $isAdmin (Boolean) should administrative tools be displayed? | ||
| 129 | * | ||
| 130 | * $config (Map<String, String>) configuration for invitation application. | ||
| 131 | *### | ||
| 132 | #macro(invitationFooter, $mail, $parameterMap, $isAdmin, $config) | ||
| 133 | ## Clear the float:left which puts elements side by side. | ||
| 134 | #if($parameterMap && $parameterMap.get('inspect') && $parameterMap.get('inspect').size() > 0) | ||
| 135 | #set($inspect = $parameterMap.get('inspect').get(0)) | ||
| 136 | #end | ||
| 137 | (%class="clearboth" id=invitation-footer%)((( | ||
| 138 | |||
| 139 | |||
| 140 | ## User Tools | ||
| 141 | = $services.localization.render('xe.invitation.tools.heading') = | ||
| 142 | ## Invite friends. | ||
| 143 | #if($doc.getFullName() != $config.get('mainPage') || $parameterMap.size() > 0) | ||
| 144 | * [[$services.localization.render('xe.invitation.tools.senderLink')>>$config.get('mainPage')]] | ||
| 145 | #else | ||
| 146 | * **$services.localization.render('xe.invitation.tools.senderLink')** | ||
| 147 | #end | ||
| 148 | ## My invitations | ||
| 149 | #if($inspect != 'all') | ||
| 150 | * [[$services.localization.render('xe.invitation.tools.myInvitationsLink')>>$config.get('membersActionsPage')||queryString='inspect=all']] ## | ||
| 151 | #if($inspect == 'group') | ||
| 152 | |||
| 153 | ** **$services.localization.render('xe.invitation.tools.invitationsInGroup')** | ||
| 154 | #else | ||
| 155 | #set($messagesByMe = []) | ||
| 156 | #getMessagesBySender($mail.values(), $xcontext.getUser(), $messagesByMe) | ||
| 157 | #set($myPendingInvitations = []) | ||
| 158 | #getMessagesByStatus($messagesByMe, 'pending', $myPendingInvitations) | ||
| 159 | #if($myPendingInvitations.size() > 0) | ||
| 160 | (%id="my-pending-invitations"%){{info}}$myPendingInvitations.size() pending{{/info}}(%%)## | ||
| 161 | #end | ||
| 162 | ## If viewing message history then show history brelow group. | ||
| 163 | #if($inspect == 'history') | ||
| 164 | |||
| 165 | #set ($queryString = $escapetool.url({ | ||
| 166 | 'inspect': 'group', | ||
| 167 | 'messageID': $parameterMap.get('messageID').get(0) | ||
| 168 | })) | ||
| 169 | ** [[$services.localization.render('xe.invitation.tools.invitationsInGroup')>>$config.get('membersActionsPage')||queryString="$queryString"]] | ||
| 170 | *** **$services.localization.render('xe.invitation.tools.invitationHistory')**## | ||
| 171 | #end | ||
| 172 | |||
| 173 | #end | ||
| 174 | #else | ||
| 175 | * **$services.localization.render('xe.invitation.tools.myInvitationsLink')** | ||
| 176 | #end | ||
| 177 | #if($isAdmin) | ||
| 178 | ## Administrative Tools | ||
| 179 | |||
| 180 | |||
| 181 | = $services.localization.render('xe.invitation.adminTools.heading') = | ||
| 182 | ## | ||
| 183 | ## Warn the user if guests are unable to be invited. | ||
| 184 | #if("#canGuestAcceptInvitation($xwiki.getDocument($config.get('guestsActionsPage')))" != 'true') | ||
| 185 | {{error}}$services.localization.render('xe.invitation.guestsCanNotJoin', [$config.get('guestsActionsPage')]){{/error}} | ||
| 186 | |||
| 187 | #end | ||
| 188 | ## Click here to configure the friend inviter | ||
| 189 | * {{html}}<a href="$xwiki.getURL('XWiki.XWikiPreferences', 'admin', 'admin=globaladmin§ion=Invitation')">## | ||
| 190 | $services.localization.render('xe.invitation.adminTools.configureLink')## | ||
| 191 | </a>{{/html}} | ||
| 192 | ## View all invitations | ||
| 193 | #if($inspect != 'allAsAdmin') | ||
| 194 | * [[$services.localization.render('xe.invitation.adminTools.allInvitationsLink')>>$config.get('membersActionsPage')||queryString='inspect=allAsAdmin']] ## | ||
| 195 | #set($spamReports = []) | ||
| 196 | #getMessagesByStatus($mail.values(), 'reported', $spamReports) | ||
| 197 | #if($spamReports.size() > 0) | ||
| 198 | (%id="spam-reports"%){{warning}}$spamReports.size() reported as spam{{/warning}}(%%)## | ||
| 199 | #end | ||
| 200 | |||
| 201 | #if($inspect == 'groupAsAdmin') | ||
| 202 | ** **$services.localization.render('xe.invitation.tools.invitationsInGroup')** | ||
| 203 | #elseif($inspect == 'historyAsAdmin') | ||
| 204 | #set ($queryString = $escapetool.url({ | ||
| 205 | 'inspect': 'groupAsAdmin', | ||
| 206 | 'messageID': $parameterMap.get('messageID').get(0) | ||
| 207 | })) | ||
| 208 | ** [[$services.localization.render('xe.invitation.tools.invitationsInGroup')>>$config.get('membersActionsPage')||queryString="$queryString"]] | ||
| 209 | *** **$services.localization.render('xe.invitation.tools.invitationHistory')** | ||
| 210 | #end | ||
| 211 | #else | ||
| 212 | ## Inspect all as admin is selected. | ||
| 213 | * **$services.localization.render('xe.invitation.adminTools.allInvitationsLink')** | ||
| 214 | #end | ||
| 215 | #end | ||
| 216 | ))) | ||
| 217 | #end | ||
| 218 | ## | ||
| 219 | #* | ||
| 220 | * Get only messages by a given sender | ||
| 221 | * | ||
| 222 | * $messages (Collection<XObject>) the messages to search though. | ||
| 223 | * | ||
| 224 | * $sender (String) the name of the user (document name) who sent the message. | ||
| 225 | * | ||
| 226 | * $messagesOut (List<XObject>) will be populated with messages which are sent by $user | ||
| 227 | *### | ||
| 228 | #macro(getMessagesBySender, $messages, $sender, $messagesOut) | ||
| 229 | #foreach($message in $messages) | ||
| 230 | #if($sender == $message.getProperty('sendingUser').getValue()) | ||
| 231 | #set($discard = $messagesOut.add($message)) | ||
| 232 | #end | ||
| 233 | #end | ||
| 234 | #end | ||
| 235 | ## | ||
| 236 | #* | ||
| 237 | * Get only messages with a given status code. | ||
| 238 | * | ||
| 239 | * $messages (Collection<XObject>) the messages to search though. | ||
| 240 | * | ||
| 241 | * $status (String) the status code for the messages to get. | ||
| 242 | * | ||
| 243 | * $messagesOut (List<XObject>) will be populated with messages which are sent by $user | ||
| 244 | *### | ||
| 245 | #macro(getMessagesByStatus, $messages, $status, $messagesOut) | ||
| 246 | #foreach($message in $messages) | ||
| 247 | #if($status == $message.getProperty('status').getValue()) | ||
| 248 | #set($discard = $messagesOut.add($message)) | ||
| 249 | #end | ||
| 250 | #end | ||
| 251 | #end | ||
| 252 | ## | ||
| 253 | #* | ||
| 254 | * Get a "breadcrumb trail" based on the way users are expected to navigate through the members' actions. | ||
| 255 | * Each entry in the list is a link except for the last (which is the page the user is currently on) | ||
| 256 | * output might look like ['[[Invitation]]', '[[My invitations]]', 'Invitations in this message group'] | ||
| 257 | * * [[output]] denotes that the output is a link. | ||
| 258 | * | ||
| 259 | * $parameterMap (Map<String, String>) map obtained by calling getParameterMap on the servlet request object. | ||
| 260 | * | ||
| 261 | * $config (Map<String, String>) configuration for invitation application. | ||
| 262 | * | ||
| 263 | * $trail (List<String>) this list will be populated with entries into the breadcrumb trail. | ||
| 264 | *### | ||
| 265 | #macro(getInvitationBreadcrumbTrail, $parameterMap, $config, $trail) | ||
| 266 | #if($parameterMap && $parameterMap.get('inspect') && $parameterMap.get('inspect').size() > 0) | ||
| 267 | #set($inspect = $parameterMap.get('inspect').get(0)) | ||
| 268 | #end | ||
| 269 | ## | ||
| 270 | #if($doc.getFullName() == $config.get('mainPage')) | ||
| 271 | ## Invitation | ||
| 272 | #set($discard = $trail.add($services.localization.render('xe.invitation.heading'))) | ||
| 273 | #else | ||
| 274 | #set($discard = $trail.add("[[$services.localization.render('xe.invitation.heading')>>$config.get('mainPage')]]")) | ||
| 275 | #if($doc.getFullName() == $config.get('membersActionsPage')) | ||
| 276 | ## | ||
| 277 | ## Administration | ||
| 278 | #if($inspect.contains('AsAdmin')) | ||
| 279 | #if($inspect == 'allAsAdmin') | ||
| 280 | ## [[Invitation]] --> All invitations | ||
| 281 | #set($discard = $trail.add($services.localization.render('xe.invitation.adminTools.allInvitationsLink'))) | ||
| 282 | #else | ||
| 283 | #set ($queryString = $escapetool.url({ 'inspect': 'allAsAdmin' })) | ||
| 284 | #set($allAsAdminLink = "[[$services.localization.render('xe.invitation.adminTools.allInvitationsLink')" | ||
| 285 | + ">>$config.get('membersActionsPage')||queryString='$queryString']]") | ||
| 286 | #set($discard = $trail.add($allAsAdminLink)) | ||
| 287 | #if($inspect == 'groupAsAdmin') | ||
| 288 | ## [[Invitation]] --> [[All invitations]] --> Invitations in group | ||
| 289 | #set($discard = $trail.add($services.localization.render('xe.invitation.tools.invitationsInGroup'))) | ||
| 290 | #elseif($inspect == 'historyAsAdmin') | ||
| 291 | ## [[Invitation]] --> [[All invitations]] --> [[Invitations in group]] --> History of this invitation | ||
| 292 | #set ($queryString = $escapetool.url({ | ||
| 293 | 'inspect': 'groupAsAdmin', | ||
| 294 | 'messageID': $parameterMap.get('messageID').get(0) | ||
| 295 | })) | ||
| 296 | #set($allInGroupAsAdminLink = "[[$services.localization.render('xe.invitation.tools.invitationsInGroup')>>" | ||
| 297 | + "$config.get('membersActionsPage')||queryString='$queryString']]") | ||
| 298 | #set($discard = $trail.add($allInGroupAsAdminLink)) | ||
| 299 | #set($discard = $trail.add($services.localization.render('xe.invitation.tools.invitationHistory'))) | ||
| 300 | #end | ||
| 301 | #end | ||
| 302 | ## | ||
| 303 | ## For user. | ||
| 304 | #else | ||
| 305 | #if($inspect == 'all') | ||
| 306 | ## [[Invitation]] --> My Invitations | ||
| 307 | #set($discard = $trail.add($services.localization.render('xe.invitation.tools.myInvitationsLink'))) | ||
| 308 | #else | ||
| 309 | #set($myInvitationsLink = "[[$services.localization.render('xe.invitation.tools.myInvitationsLink')>>" | ||
| 310 | + "$config.get('membersActionsPage')||queryString='inspect=all']]") | ||
| 311 | #set($discard = $trail.add($myInvitationsLink)) | ||
| 312 | #if($inspect == 'group') | ||
| 313 | #set($discard = $trail.add($services.localization.render('xe.invitation.tools.invitationsInGroup'))) | ||
| 314 | #else | ||
| 315 | #set ($queryString = $escapetool.url({ | ||
| 316 | 'inspect': 'group', | ||
| 317 | 'messageID': $parameterMap.get('messageID').get(0) | ||
| 318 | })) | ||
| 319 | #set($myInvitationsinGroupLink = "[[$services.localization.render('xe.invitation.tools.invitationsInGroup')>>" | ||
| 320 | + "$config.get('membersActionsPage')||queryString='$queryString']]") | ||
| 321 | #set($discard = $trail.add($myInvitationsinGroupLink)) | ||
| 322 | #if($inspect == 'history') | ||
| 323 | #set($discard = $trail.add($services.localization.render('xe.invitation.tools.invitationHistory'))) | ||
| 324 | #end | ||
| 325 | #end | ||
| 326 | #end## If not inspect 'all' | ||
| 327 | #end## If not inspecting as admin | ||
| 328 | #end## If we're on InvitationMemberActions | ||
| 329 | #end## If we're not on the main page | ||
| 330 | #end## Macro | ||
| 331 | ## | ||
| 332 | #* | ||
| 333 | * Display the header for at the top of the page. | ||
| 334 | * | ||
| 335 | * $parameterMap (Map<String, String>) map obtained by calling getParameterMap on the servlet request object. | ||
| 336 | * | ||
| 337 | * $config (Map<String, String>) configuration for invitation application. | ||
| 338 | *### | ||
| 339 | #macro(displayInvitationHeader, $parameterMap, $config) | ||
| 340 | #set($breadcrumbTrail = []) | ||
| 341 | #getInvitationBreadcrumbTrail($parameterMap, $config, $breadcrumbTrail) | ||
| 342 | #if($breadcrumbTrail.size() > 0) | ||
| 343 | = $breadcrumbTrail.get($mathtool.add($breadcrumbTrail.size(), -1)) = | ||
| 344 | #end | ||
| 345 | #end | ||
| 346 | {{/velocity}} |