Wiki-Quellcode von NotificationsDisplayerUIX

Zuletzt geändert von Daniel Herrmann am 2026/03/08 12:48

Verstecke letzte Bearbeiter
Daniel Herrmann 1.1 1 {{velocity wiki="true"}}
2 #********************************************************
3 Get the actual notifications.
4 ********************************************************###
5 ## We use POST since we are sending the reference of the document and we want to avoid special characters in the URL.
6 #if ('get' == $xcontext.action && 'POST' == $request.method && 'getNotifications' == $request.action)
7 #set ($requestedDocumentReference = $services.model.resolveDocument($request.document))
8 {{html clean="false"}} ## we need clean="false" because we want to display the raw content
9 #if ("$!xcontext.userReference" != '' && $services.notification.isEnabled())
10 <div class="notifications-header">
11 <div class="clearfix">
12 <div class="col-xs-4">
13 <p><strong>$escapetool.xml($services.localization.render('notifications.menu.header'))</strong></p>
14 </div>
15 <div class="col-xs-8 text-right">
16 <p>
17 <span class="notifications-header-link">
18 <a href="$xwiki.getURL('XWiki.Notifications.Code.NotificationRSSService', 'get', 'outputSyntax=plain')"
19 class="notifications-header-link notifications-rss-link" rel="nofollow external">
Daniel Herrmann 3.1 20 $services.icon.renderHTML('rss')&nbsp;$escapetool.xml($services.localization.render('notifications.rss.feedLink'))##
Daniel Herrmann 1.1 21 </a>
22 </span>
23 <span class="notifications-header-link">
24 <a href="$xwiki.getURL($xcontext.userReference, 'view', 'category=notifications')" class="notifications-settings" rel="nofollow">
25 $services.icon.renderHTML('cog')&nbsp;$escapetool.xml($services.localization.render('notifications.menu.header.settings'))
26 </a>
27 </span>
28 </p>
29 </div>
30 </div>
31 <div class="notifications-header-uix col-xs-12">
32 </div>
33 </div>
34 <div class="notifications-area clearfix">
35 {{/html}}
36
37 {{notifications displayReadStatus="true" useUserPreferences="true" count="10" displayRSSLink="false" /}}
38
39 {{html clean="false"}}
40 </div>
41 {{/html}}
42 #end
43 #end
44 {{/velocity}}
45
46 {{velocity wiki="false"}}
47 #********************************************************
48 Get the number of unread notifications as JSON
49 ********************************************************###
50 #if ('get' == $xcontext.action && 'GET' == $request.method && 'getUnreadCount' == $request.action)
51 #set ($discard = $response.setHeader('Cache-Control', 'no-cache'))
52 #set ($discard = $response.setHeader('Content-Type', 'application/json'))
53 $jsontool.serialize({'unread': $services.notification.sources.getEventsCount(21)})
54 #********************************************************
55 Mark a notification as read
56 ********************************************************###
57 #elseif('get' == $xcontext.action && 'POST' == $request.method && 'read' == $request.action)
58 #set ($eventIds = $request.eventIds.split(','))
59 #set ($read = "$!request.read")
60 #if ($eventIds.length == 0 || $read.isEmpty())
61 #set ($discard = $response.setStatus(400))
62 #else
63 #foreach ($eventId in $eventIds)
64 #set ($discard = $services.notification.saveEventStatus($eventId, $read.equals('true')))
65 #end
66 #end
67 #********************************************************
68 Change the start date of the user
69 ********************************************************###
70 #elseif('get' == $xcontext.action && 'POST' == $request.method && 'setStartDate' == $request.action)
71 #set ($startDate = $datetool.date)
72 #if ("$!request.date" != '')
73 #set ($startDate = $xwiki.jodatime.getDateTime($numbertool.toNumber($request.date).longValue()).toDate())
74 #end
75 #set ($discard = $services.notification.preferences.setStartDate($startDate))
76 #set ($discard = $services.notification.filters.setStartDate($startDate))
77 #********************************************************
78 Clear all event status until a specific date for the user
79 ********************************************************###
80 #elseif('get' == $xcontext.action && 'POST' == $request.method && 'clear' == $request.action)
81 #set ($startDate = $datetool.date)
82 #if ("$!request.date" != '')
83 #set ($startDate = $xwiki.jodatime.getDateTime($numbertool.toNumber($request.date).longValue()).toDate())
84 #end
85 #set ($discard = $services.notification.preferences.setStartDate($startDate))
86 #set ($discard = $services.notification.filters.setStartDate($startDate))
87 #set ($discard = $services.notification.clearAllStatus($startDate))
88 #********************************************************
89 Watch/Unwatch a location
90 ********************************************************###
91 #elseif('get' == $xcontext.action && 'POST' == $request.method && ('watchLocation' == $request.action || 'unwatchLocation' == $request.action))
92 #if ("$!request.type" == 'space')
93 #set ($location = $services.model.resolveSpace($request.location))
94 #elseif ("$!request.type" == 'wiki')
95 #set ($location = $services.model.createWikiReference($request.location))
96 #else
97 #set ($location = $services.model.resolveDocument($request.location))
98 #end
99 #if ('watchLocation' == $request.action)
100 #set ($discard = $services.notification.watch.watchLocation($location))
101 #else
102 #set ($discard = $services.notification.watch.unwatchLocation($location))
103 #end
104 ## Display the new states
105 #if ("$!request.currentDoc" != '')
106 #set ($currentDoc = $services.model.resolveDocument($request.currentDoc))
107 #set ($states = {
108 'document': $services.notification.watch.getLocationWatchedStatus($currentDoc),
109 'space': $services.notification.watch.getLocationWatchedStatus($currentDoc.lastSpaceReference),
110 'wiki': $services.notification.watch.getLocationWatchedStatus($currentDoc.wikiReference)
111 })
112 #set ($discard = $response.setContentType('application/json'))
113 $jsontool.serialize($states)
114 #end
115 #end
116 {{/velocity}}
117