FlamingoThemesCode
De SupraWiki
- Globals
- set ($discard = $xwiki.ssx.use('FlamingoThemesCode.WebHomeSheet'))
- CONTROLLER
- if($request.action == 'setTheme')
#setTheme()
- elseif($request.action == 'setThemeSuccess')
#prepareView() #setThemeSuccess() #view()
- elseif($request.action == 'create')
#create()
- else
#prepareView() #view()
- end
- PREPARE VIEW
- macro(prepareView)
#set ($currentTheme = $xwiki.getXWikiPreference('colorTheme'))
#if ("$!currentTheme" == )
#set ($currentTheme = 'FlamingoThemes.Charcoal')
#end
#set ($currentThemeDoc = $xwiki.getDocument($currentTheme))
#set ($isSubWiki = $services.wiki.currentWikiId != $services.wiki.mainWikiId)
#set ($flamingoThemesFromThisWiki = [])
#getFlamingoThemes($services.wiki.currentWikiId, $flamingoThemesFromThisWiki)
#if ($isSubWiki)
#set ($flamingoThemesFromMainWiki = [])
#getFlamingoThemes($services.wiki.mainWikiId, $flamingoThemesFromMainWiki)
#end
#set ($currentScope = 'local')
#if ("$!currentTheme" != && $services.model.resolveDocument($currentTheme).wikiReference.name == $services.wiki.mainWikiId)
#set ($currentScope = 'global')
#end
- end
- Get Flamingo themes
- macro(getFlamingoThemes $wiki $return)
#set ($results = [])
#set ($xwql = "from doc.object(FlamingoThemesCode.ThemeClass) obj WHERE doc.fullName <> 'FlamingoThemesCode.ThemeTemplate' ORDER BY doc.name")
#getThemesFromQuery ($xwql, $wiki, $results)
#set ($return = $NULL)
#setVariable ("$return", $results)
- end
- Get themes from a query
- macro(getThemesFromQuery $xwql $wiki $return)
#set ($wikiReference = $services.model.createWikiReference($wiki))
#set ($themes = $services.query.xwql($xwql).setWiki($wiki).execute())
#set ($themesRef = [])
#foreach ($theme in $themes)
#set ($themeRef = $services.model.resolveDocument($theme, 'default', $wikiReference))
#if ($services.security.authorization.hasAccess('view', $xcontext.userReference, $themeRef))
#set ($discard = $themesRef.add($themeRef))
#end
#end
#set ($return = $NULL)
#setVariable("$return" $themesRef)
- end
- VIEW
- macro(view)
(% class="theme-viewer" %)
(((
## Display a warning about old color themes (if any)
#if($xwiki.exists($services.model.createDocumentReference(, 'ColorThemes', 'ColorThemeClass')) && $xwiki.exists($services.model.createDocumentReference(, 'ColorThemes', 'WebHome')))
Predefinição:Info
$services.localization.render('platform.flamingo.themes.home.warningOldColorThemeInstalled', ["[[", ">>ColorThemes.WebHome]]"])
Predefinição:/info
#end
## Display the current theme
== $services.localization.render('platform.flamingo.themes.home.currenttheme') ==
#if($currentThemeDoc.getObject('ColorThemes.ColorThemeClass'))
Predefinição:Warning
$services.localization.render('platform.flamingo.themes.home.warningCurrentOldColorTheme')
Predefinição:/warning
#end
#displayTheme($currentThemeDoc.documentReference, $currentScope)
## Display the other themes
## Creation form
#creationForm()
== $services.localization.render('platform.flamingo.themes.home.otherthemes') ==
#if ($isSubWiki && !$flamingoThemesFromMainWiki.isEmpty())
Predefinição:Html
Predefinição:/html (% class="tab-content" %) ((( (% class="tab-pane active" id="local" %) ((( #foreach($themeRef in $flamingoThemesFromThisWiki) #displayTheme($themeRef, 'local') #end ))) (% class="tab-pane" id="global" %) ((( #foreach($themeRef in $flamingoThemesFromMainWiki) #displayTheme($themeRef, 'global') #end ))) ))) #else #foreach($themeRef in $flamingoThemesFromThisWiki) #displayTheme($themeRef, 'local') #end #end )))
- end
- DISPLAY THEME
- macro(displayTheme $themeReference $scope)
#if ($scope == 'local')
#set ($fullName = $services.model.serialize($themeReference, 'local'))
#else
#set ($fullName = $services.model.serialize($themeReference, 'default'))
#end
#set ($isCurrentTheme = ($currentThemeDoc.documentReference == $themeReference))
#set ($themeDoc = $xwiki.getDocument($themeReference))
#set ($themeObj = $themeDoc.getObject('FlamingoThemesCode.ThemeClass'))
(% class="theme #if($isCurrentTheme) current-theme#end" %)
(((
## Display the mockup
#themeMockup($themeObj)
## Display the informations
(% class="theme-info" %)
(((
=== [[$themeDoc.displayTitle>>$fullName]] #if ($isSubWiki && $scope == 'local') ($services.wiki.currentWikiId)#end===
#if ($hasAdmin && !$isCurrentTheme)
$services.icon.render('bullet_go') [[$services.localization.render('platform.flamingo.themes.home.useThisTheme')>>path:$doc.getURL('view', "action=setTheme&theme=${fullName}&form_token=$services.csrf.token")]]
#end
)))
)))
- end
- THEME MOCKUP
- macro(themeMockup $themeObj)
#macro(displayValue $variableName $fallback)
#set($value = $themeObj.getValue($variableName))
#if("$!value" == )
#set($value = $fallback)
#end
$value##
#end
Predefinição:Html
## A fake navbar
## A fake page content
## A fake app bar
## A fake right panel
## A fake footer
Predefinição:/html
- end
- CREATION FORM
- macro(creationForm)
#if($xwiki.hasAccessLevel('edit', $xcontext.user, 'FlamingoThemes.AnyPage____________'))
(% class="clearfix" %)
(((
Predefinição:Html
<form action="$doc.getURL()" method="post" class="form-inline">
<input type="hidden" name="form_token" value="$services.csrf.token" />
<input type="hidden" name="action" value="create"/>
<label for="newThemeName" class="hidden">$services.localization.render('platform.flamingo.themes.home.newThemeName')</label>
<input type="text" name="newThemeName" id="newThemeName" value="$services.localization.render('platform.flamingo.themes.home.newThemeName')" class="withTip" size="30"/>
<input type="submit" value="$services.localization.render('platform.flamingo.themes.home.create')" class="button"/>
</form>
Predefinição:/html ))) #end
- end
- CREATE A NEW THEME
- macro(create)
#if("$!request.newThemeName" == )
Predefinição:Error
Predefinição:Translation key="platform.flamingo.themes.home.create.invalid" /
Predefinição:/error
#creationForm()
#elseif(!$services.csrf.isTokenValid($request.form_token))
Predefinição:Error
Predefinição:Translation key="platform.flamingo.themes.home.create.csrf" parameters="$request.newThemeName" /
Predefinição:/error
Predefinição:Html
<form action="$doc.getURL()" method="post">
<input type="hidden" name="form_token" value="$services.csrf.token" />
<input type="hidden" name="action" value="create"/>
<input type="hidden" name="newThemeName" id="newThemeName" value="$request.newThemeName" />
<input type="submit" value="$services.localization.render('platform.flamingo.themes.home.create.confirm')" class="button"/>
</form>
Predefinição:/html
#else
## Let's do it
$response.sendRedirect($xwiki.getDocument($services.model.createDocumentReference(, 'FlamingoThemes', $request.newThemeName)).getURL('edit', "template=FlamingoThemesCode.ThemeTemplate&title=$escapetool.url($request.newThemeName)&parent=$doc.fullName&xhidden=1"))
#end
- end
- SET THEME
- macro(setTheme)
#if("$!request.theme" != && $hasAdmin && ${services.csrf.isTokenValid("$!{request.getParameter('form_token')}")})
#set($preferencesDoc = $xwiki.getDocument('XWiki.XWikiPreferences'))
#set($preferencesObj = $preferencesDoc.getObject('XWiki.XWikiPreferences'))
$preferencesObj.set('colorTheme', $request.theme)
$preferencesDoc.save()
$response.sendRedirect($doc.getURL('view', "theme=$escapetool.url($request.theme)&action=setThemeSuccess"))
#end
- end
- SET THEME SUCCESS
- macro(setThemeSuccess)
#if("$!request.theme" != )
Predefinição:Success
$services.localization.render('platform.flamingo.themes.home.set.success', [$xwiki.getDocument($request.theme).displayTitle])
Predefinição:/success
#end
- end
