/
menus_content.vm
334 lines (323 loc) · 14.2 KB
/
menus_content.vm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
##
## Globals
##
#set ($canView = !$doc.isNew() && $xwiki.hasAccessLevel('view'))
#set ($canCopy = $canView && $hasCreatePage)
#set ($canDelete = !$doc.isNew() && $xwiki.hasAccessLevel('delete'))
#set ($canShare = $canView && $xwiki.exists('XWiki.SharePage') && !$isGuest)
##
## Display the 4 menus
##
#if ($displayContentMenu)
#template("menus_macros.vm")
<div id="contentmenu" class="pull-right actionmenu">
#if ($displayEditMenu && $hasEdit && !$isReadOnly)
#displayEditMenu()
#end
#if ($displayCreateMenu && $hasCreatePage)
#displayCreateButton()
#end
#if ($displayAdminMenu)
#displayAdminMenu()
#end
#if ($displayMoreActionsMenu)
#diplayOptionsMenu()
#if ($canView)
#exportModal()
#end
#end
#if($keyboardShortcutsEnabled)
#keyboardShortcuts()
#end
</div>
#end
#**
* Display a menu if it has some content.
*
* @param $id the id of the menu
* @param $icon the icon of the menu
* @param $content the content of the menu
*
* @since 7.3M2
*#
#macro(displayMenu $id $icon $content)
#set ($content = $content.toString())
#if ($stringtool.isNotBlank($content))
<div class="dropdown" id="$id">
<a href="" data-toggle="dropdown" role="button"><span class="glyphicon glyphicon-$icon"></span></a>
<ul class="dropdown-menu">
$content
</ul>
</div>
#end
#end
#**
* Display UI extensions if the author of the UIX has the ADMIN right on the current wiki
*
* @param $name the name of the UI extension to display
* @param $staticExtensions (optional) an array of static extensions to display along with the regular uix.
* e.g. [ { 'content': 'someHTMLcontent', 'order': 20000, 'separator': true } ]
* @since 7.3M1
*
* TODO: replace this macro to stop having "static extensions" but a mechanism to have real UI Extensions in templates.
*#
#macro(displaySecureUIX $name $staticExtensions)
## Get the given static extension
#set($extensions = $staticExtensions)
#if (!$extensions)
#set ($extensions = [])
#end
## Get the UIX from the system
#foreach($uix in $services.uix.getExtensions($name))
#if ($services.security.authorization.hasAccess('admin', $uix.authorReference, $services.wiki.currentWikiDescriptor.reference))
#set ($separator = ("$!uix.getParameters().separator" == 'true'))
#set ($uixMap = { 'content' : $services.rendering.render($uix.execute(), 'html/5.0'),
'order' : $mathtool.toInteger($uix.getParameters().order),
'separator': $separator})
#set ($discard = $extensions.add($uixMap))
#end
#end
## Display them, sorted by order
#set ($canHaveMenuSeparator = false)
#foreach($uix in $sorttool.sort($extensions, 'order'))
## Maybe display a menu separator
#if ("$!uix.separator" == 'true' && $canHaveMenuSeparator)
#submenuseparator()
#set ($canHaveMenuSeparator = false)
#end
#set ($content = $uix.content.toString())
$content
#if ($stringtool.isNotBlank($content))
#set ($canHaveMenuSeparator = true)
#end
#end
#end
#**
* Display the create button
*#
#macro(displayCreateButton)
<div class="dropdown" id="tmCreate">
<a href="$doc.getURL('create')" role="button"><span class="glyphicon glyphicon-plus"></span></a>
</div>
#end
#**
* Display the edit menu
*#
#macro(displayEditMenu)
#set ($defaultEditURL = $doc.getURL($doc.getDefaultEditMode(), $!languageparams))
#set ($staticExtensions = [])
#if ($isAdvancedUser)
##
## Default edit mode
##
#set ($discard = $staticExtensions.add( { 'content': "#submenuitem($defaultEditURL, $services.localization.render('core.menu.edit'), 'tmEditDefault', '', 'pencil')", 'order': 10000}))
##
## WYSIWYG
##
## Check if the WYSIWYG supports the current document's syntax and if so add a menu entry to edit the current
## document with the WYSIWYG editor.
#define ($editWYSIWYG)
#if ($services.wysiwyg.isSyntaxSupported($tdoc.syntax.toIdString()) || $tdoc.syntax.toIdString() == 'xwiki/1.0')
#submenuitem($doc.getURL('edit', "$!{languageparams}#if ($languageparams != '')&#{end}editor=wysiwyg") $services.localization.render('core.menu.edit.wysiwyg') 'tmEditWysiwyg', '', 'pencil')
#end
#end
#set ($discard = $staticExtensions.add( { 'content': $editWYSIWYG, 'order': 20000, 'separator': true}))
##
## WIKI EDITOR
##
#define ($wikiEditor)
#submenuitem($doc.getURL('edit', "$!{languageparams}#if ($languageparams != '')&#{end}editor=wiki") $services.localization.render('core.menu.edit.wiki') 'tmEditWiki', '', 'wrench')
#end
#set ($discard = $staticExtensions.add( { 'content': $wikiEditor, 'order': 30000}))
##
## INLINE EDITOR
##
#define ($inlineEditor)
#submenuitem($doc.getURL('edit', "$!{languageparams}#if ($languageparams != '')&#{end}editor=inline") $services.localization.render('core.menu.edit.inline') 'tmEditInline', '', 'list-alt')
#end
#set ($discard = $staticExtensions.add( { 'content': $inlineEditor, 'order': 40000}))
##
## RIGHTS
##
## The 'rights' editor is already present in the page administration. So we display it here only if we are not in
## a terminal document or if the user has not the admin right on the space (because right now the page
## administration is still combined with the space administration).
## TODO: create a proprer 'page administration' and stop adding a right editor in this menu
#define ($rightsEditor)
#if ($doc.name != 'WebHome' || !$hasSpaceAdmin || !$isAdminAppInstalled)
#submenuitem($doc.getURL('edit', 'editor=rights') $services.localization.render('core.menu.edit.rights') 'tmEditRights', '', 'lock')
#end
#end
#set ($discard = $staticExtensions.add( { 'content': $rightsEditor, 'order': 50000, 'separator': true}))
##
## OBJECTS EDITOR
##
#set ($discard = $staticExtensions.add( { 'content': "#submenuitem($doc.getURL('edit', 'editor=object') $services.localization.render('core.menu.edit.object') 'tmEditObject', '', 'hdd')", 'order': 60000}))
##
## CLASS EDITOR
##
#set ($discard = $staticExtensions.add( { 'content': "#submenuitem($doc.getURL('edit', 'editor=class') $services.localization.render('core.menu.edit.class') 'tmEditClass', '', 'hdd')", 'order': 70000}))
#end
##
## Display all the extensions points, including the static ones
##
#define ($menuContent)
#displaySecureUIX('org.xwiki.plaftorm.editactions', $staticExtensions)
#end
#set ($menuContent = $menuContent.toString())
#set ($menuHasContent = $stringtool.isNotBlank($menuContent))
##
## Display the menu
##
<div class="dropdown" id="tmEdit">
<a href="$defaultEditURL" #if ($menuHasContent)data-toggle="dropdown"#end role="button"><span class="glyphicon glyphicon-pencil"></span></a>
#if ($menuHasContent)
<ul class="dropdown-menu">
$menuContent
</ul>
#end
</div>
#end
#**
* Display admin menu
*#
#macro(displayAdminMenu)
#set ($staticExtensions = [])
##
## COPY
##
#if ($canCopy)
#set ($discard = $staticExtensions.add( { 'content': "#submenuitem($xwiki.getURL($doc.documentReference, 'view', 'xpage=copy') $services.localization.render('core.menu.copy') 'tmActionCopy', '' 'share')", 'order': 20000, 'separator': true}))
#end
##
## DELETE / RENAME
##
#if ($canDelete)
#set ($discard = $staticExtensions.add( { 'content': "#submenuitem($xwiki.getURL($doc.documentReference, 'view', 'xpage=rename&step=1') $services.localization.render('core.menu.rename') 'tmActionRename', '' 'edit')", 'order': 30000}))
#set ($discard = $staticExtensions.add( { 'content': "#submenuitem($xwiki.getURL($doc.documentReference, 'delete', $!languageparams) $services.localization.render('core.menu.delete') 'tmActionDelete', '', 'remove')", 'order': 40000}))
#end
##
## Display all the extensions points, including the static ones
##
#define ($menuContent)
#displaySecureUIX('org.xwiki.plaftorm.adminactions', $staticExtensions)
#end
##
## Display the menu only if there is some content
##
#displayMenu('tmAdminActions', 'cog', $menuContent)
#end
#**
* Display options menu
*#
#macro(diplayOptionsMenu)
#set ($staticExtensions = [])
##
## EXPORT / PRINT / SOURCE / SHARE
##
#if ($canView)
##
## EXPORT
##
#define ($export)
#submenuitem('' $services.localization.render('core.menu.export') 'tmExport', '', 'download-alt', 'data-toggle="modal" data-target="#exportModal"')
#end
#set ($discard = $staticExtensions.add( { 'content': $export, 'order': 80000, 'separator': true}))
##
## PRINT
##
#define ($print)
#submenuitem($doc.getURL('view', "xpage=print&$!escapetool.html($request.getQueryString())") $services.localization.render('core.menu.preview') 'tmPrintPreview', '', 'print')
#end
#set ($discard = $staticExtensions.add( { 'content': $print, 'order': 90000}))
##
## VIEW SOURCE
##
#define ($viewSource)
#submenuitem($doc.getURL('view', "viewer=code") $services.localization.render('core.menu.view.source') 'tmViewSource', '', 'search')
#end
#set ($discard = $staticExtensions.add( { 'content': $viewSource, 'order': 100000}))
##
## SHARE BY EMAIL
##
#if ($canShare)
#define ($share)
#submenuitem($xwiki.getURL($doc.documentReference, 'view', 'viewer=share') $services.localization.render('core.menu.share') 'tmActionShare', '', 'envelope')
#userPicker_import()
#end
#set ($discard = $staticExtensions.add( { 'content': $share, 'order': 110000}))
$xwiki.jsx.use('XWiki.SharePage')
$xwiki.ssx.use('XWiki.SharePage')
#end
#end
##
## Display all the extensions points, including the static ones
##
#define ($menuContent)
#displaySecureUIX('org.xwiki.plaftorm.moreoptions', $staticExtensions)
## ----------------------------
## Display the shortcuts
## ----------------------------
#if($canView && $displayShortcuts)
#submenuseparator()
#template("shortcuts.vm")
#end
#end
##
## Display the menu if it has some content
##
#displayMenu('tmMoreActions', 'option-vertical', $menuContent)
#end
#**
* Add keyboard shortcuts
*#
#macro(keyboardShortcuts)
<script type="text/javascript">
//<![CDATA[
#if ($hasEdit && !$isReadOnly)
shortcut.add("$services.localization.render('core.shortcuts.view.edit')",function() { location.href=$('tmEdit').down('a').href; }, { 'type':'keypress', 'propagate':false, 'disable_in_input':true });
#if($isAdvancedUser)
shortcut.add("$services.localization.render('core.shortcuts.view.wiki')",function() { location.href=$('tmEditWiki').href; }, { 'type':'keypress', 'propagate':false, 'disable_in_input':true });
shortcut.add("$services.localization.render('core.shortcuts.view.wysiwyg')",function() { location.href=$('tmEditWysiwyg').href; }, { 'type':'keypress', 'propagate':false, 'disable_in_input':true });
shortcut.add("$services.localization.render('core.shortcuts.view.inline')",function() { location.href=$('tmEditInline').href; }, { 'type':'keypress', 'propagate':false, 'disable_in_input':true });
shortcut.add("$services.localization.render('core.shortcuts.view.rights')",function() { var editRights = $('tmEditRights'); location.href= editRights ? editRights.href : "$xwiki.getURL($spacePreferencesDocumentReference, 'admin', 'category=1')";}, { 'type':'keypress', 'propagate':false, 'disable_in_input':true });
shortcut.add("$services.localization.render('core.shortcuts.view.objects')",function() { location.href=$('tmEditObject').href; }, { 'type':'keypress', 'propagate':false, 'disable_in_input':true });
#if($hasAdmin)
shortcut.add("$services.localization.render('core.shortcuts.view.class')",function() { location.href=$('tmEditClass').href; }, { 'type':'keypress', 'propagate':false, 'disable_in_input':true });
#end
#end
#end
#if ($canDelete)
shortcut.add("$services.localization.render('core.shortcuts.view.delete')",function() { location.href=$('tmActionDelete').href; }, { 'type':'keypress', 'propagate':false, 'disable_in_input':true });
shortcut.add("$services.localization.render('core.shortcuts.view.rename')",function() { location.href=$('tmActionRename').href; }, { 'type':'keypress', 'propagate':false, 'disable_in_input':true });
#end
//]]>
</script>
#end
#**
* Add export modal
*#
#macro(exportModal)
<div class="modal fade text-left" id="exportModal" tabindex="-1" role="dialog" aria-labelledby="exportModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title" id="exportModalLabel">$services.localization.render('core.menu.export')</h4>
</div>
<div class="modal-body">
<a href="$doc.getURL('view', "xpage=pdfoptions&qs=$!escapetool.url($request.getQueryString())")" class="btn btn-primary">$services.localization.render('core.menu.export.pdf')</a>
#if("$!{services.officemanager.serverState}" == "Connected")
<a href="$doc.getURL('export', "format=odt&$!escapetool.html($request.getQueryString())")" class="btn btn-primary">$services.localization.render('core.menu.export.odt')</a>
<a href="$doc.getURL('export', "format=rtf&$!escapetool.html($request.getQueryString())")" class="btn btn-primary">$services.localization.render('core.menu.export.rtf')</a>
#end
<a href="$doc.getURL('export', "format=html&$!escapetool.html($request.getQueryString())")" class="btn btn-primary">$services.localization.render('core.menu.export.html')</a>
#if($hasAdmin && "$!xwiki.getPlugin('package')" != '')
<a href="$doc.getURL('export', "format=xar&name=$escapetool.url($doc.fullName)&pages=$escapetool.url($services.model.serialize($doc.getDocumentReference(),'default'))&$!docvariant")" class="btn btn-primary">$services.localization.render('core.menu.export.xar')</a>
#end
<button type="button" class="btn btn-default" data-dismiss="modal">$services.localization.render('cancel')</button>
</div>
</div>
</div>
</div>
#end