Wiki-Quellcode von $services.localization.render('platform.flamingo.themes.home.title')
Verstecke letzte Bearbeiter
| author | version | line-number | content |
|---|---|---|---|
| |
1.1 | 1 | {{velocity}} |
| 2 | ################################ | ||
| 3 | ## Globals | ||
| 4 | ################################ | ||
| 5 | #set ($discard = $xwiki.ssx.use('FlamingoThemesCode.WebHomeSheet')) | ||
| 6 | #################################### | ||
| 7 | ## CONTROLLER | ||
| 8 | #################################### | ||
| 9 | #if($request.action == 'setTheme') | ||
| 10 | #setTheme() | ||
| 11 | #elseif($request.action == 'setThemeSuccess') | ||
| 12 | #prepareView() | ||
| 13 | #setThemeSuccess() | ||
| 14 | #view() | ||
| 15 | #elseif($request.action == 'create') | ||
| 16 | #create() | ||
| 17 | #else | ||
| 18 | #prepareView() | ||
| 19 | #view() | ||
| 20 | #end | ||
| 21 | #################################### | ||
| 22 | ## PREPARE VIEW | ||
| 23 | #################################### | ||
| 24 | #macro(prepareView) | ||
| 25 | #set ($currentTheme = $xwiki.getXWikiPreference('colorTheme')) | ||
| 26 | #if ("$!currentTheme" == '') | ||
| 27 | #set ($currentTheme = 'FlamingoThemes.Charcoal') | ||
| 28 | #end | ||
| 29 | #set ($currentThemeDoc = $xwiki.getDocument($currentTheme)) | ||
| 30 | #set ($isSubWiki = $services.wiki.currentWikiId != $services.wiki.mainWikiId) | ||
| 31 | #set ($flamingoThemesFromThisWiki = []) | ||
| 32 | #getFlamingoThemes($services.wiki.currentWikiId, $flamingoThemesFromThisWiki) | ||
| 33 | #if ($isSubWiki) | ||
| 34 | #set ($flamingoThemesFromMainWiki = []) | ||
| 35 | #getFlamingoThemes($services.wiki.mainWikiId, $flamingoThemesFromMainWiki) | ||
| 36 | #end | ||
| 37 | #set ($currentScope = 'local') | ||
| 38 | #if ("$!currentTheme" != '' && $services.model.resolveDocument($currentTheme).wikiReference.name == $services.wiki.mainWikiId) | ||
| 39 | #set ($currentScope = 'global') | ||
| 40 | #end | ||
| 41 | #end | ||
| 42 | ################################ | ||
| 43 | ## Get Flamingo themes | ||
| 44 | ################################ | ||
| 45 | #macro(getFlamingoThemes $wiki $return) | ||
| 46 | #set ($results = []) | ||
| 47 | #set ($xwql = "from doc.object(FlamingoThemesCode.ThemeClass) obj WHERE doc.fullName <> 'FlamingoThemesCode.ThemeTemplate' ORDER BY doc.name") | ||
| 48 | #getThemesFromQuery ($xwql, $wiki, $results) | ||
| 49 | #set ($return = $NULL) | ||
| 50 | #setVariable ("$return", $results) | ||
| 51 | #end | ||
| 52 | ################################ | ||
| 53 | ## Get themes from a query | ||
| 54 | ################################ | ||
| 55 | #macro(getThemesFromQuery $xwql $wiki $return) | ||
| 56 | #set ($wikiReference = $services.model.createWikiReference($wiki)) | ||
| 57 | #set ($themes = $services.query.xwql($xwql).setWiki($wiki).execute()) | ||
| 58 | #set ($themesRef = []) | ||
| 59 | #foreach ($theme in $themes) | ||
| 60 | #set ($themeRef = $services.model.resolveDocument($theme, 'default', $wikiReference)) | ||
| 61 | #if ($services.security.authorization.hasAccess('view', $xcontext.userReference, $themeRef)) | ||
| 62 | #set ($discard = $themesRef.add($themeRef)) | ||
| 63 | #end | ||
| 64 | #end | ||
| 65 | #set ($return = $NULL) | ||
| 66 | #setVariable("$return" $themesRef) | ||
| 67 | #end | ||
| 68 | #################################### | ||
| 69 | ## VIEW | ||
| 70 | #################################### | ||
| 71 | #macro(view) | ||
| 72 | (% class="theme-viewer" %) | ||
| 73 | ((( | ||
| 74 | ## Display a warning about old color themes (if any) | ||
| 75 | #if($xwiki.exists($services.model.createDocumentReference('', 'ColorThemes', 'ColorThemeClass')) && $xwiki.exists($services.model.createDocumentReference('', 'ColorThemes', 'WebHome'))) | ||
| 76 | {{info}} | ||
| 77 | $services.localization.render('platform.flamingo.themes.home.warningOldColorThemeInstalled', ["[[", ">>ColorThemes.WebHome]]"]) | ||
| 78 | {{/info}} | ||
| 79 | #end | ||
| 80 | |||
| 81 | ## Display the current theme | ||
| 82 | == $services.localization.render('platform.flamingo.themes.home.currenttheme') == | ||
| 83 | #if($currentThemeDoc.getObject('ColorThemes.ColorThemeClass')) | ||
| 84 | {{warning}} | ||
| 85 | $services.localization.render('platform.flamingo.themes.home.warningCurrentOldColorTheme') | ||
| 86 | {{/warning}} | ||
| 87 | #end | ||
| 88 | #displayTheme($currentThemeDoc.documentReference, $currentScope) | ||
| 89 | |||
| 90 | ## Display the other themes | ||
| 91 | ## Creation form | ||
| 92 | #creationForm() | ||
| 93 | |||
| 94 | == $services.localization.render('platform.flamingo.themes.home.otherthemes') == | ||
| 95 | #if ($isSubWiki && !$flamingoThemesFromMainWiki.isEmpty()) | ||
| 96 | {{html}} | ||
| 97 | <ul class="nav nav-tabs" role="tablist"> | ||
| 98 | <li role="presentation" class="active"><a href="#local" role="tab" data-toggle="tab">$escapetool.xml($services.localization.render('platform.flamingo.themes.local'))</a></li> | ||
| 99 | <li role="presentation"><a href="#global" role="tab" data-toggle="tab">$escapetool.xml($services.localization.render('platform.flamingo.themes.global'))</a></li> | ||
| 100 | </ul> | ||
| 101 | {{/html}} | ||
| 102 | |||
| 103 | (% class="tab-content" %) | ||
| 104 | ((( | ||
| 105 | (% class="tab-pane active" id="local" %) | ||
| 106 | ((( | ||
| 107 | #foreach($themeRef in $flamingoThemesFromThisWiki) | ||
| 108 | #displayTheme($themeRef, 'local') | ||
| 109 | #end | ||
| 110 | ))) | ||
| 111 | |||
| 112 | (% class="tab-pane" id="global" %) | ||
| 113 | ((( | ||
| 114 | #foreach($themeRef in $flamingoThemesFromMainWiki) | ||
| 115 | #displayTheme($themeRef, 'global') | ||
| 116 | #end | ||
| 117 | ))) | ||
| 118 | ))) | ||
| 119 | #else | ||
| 120 | #foreach($themeRef in $flamingoThemesFromThisWiki) | ||
| 121 | #displayTheme($themeRef, 'local') | ||
| 122 | #end | ||
| 123 | #end | ||
| 124 | ))) | ||
| 125 | #end | ||
| 126 | #################################### | ||
| 127 | ## DISPLAY THEME | ||
| 128 | #################################### | ||
| 129 | #macro(displayTheme $themeReference $scope) | ||
| 130 | #if ($scope == 'local') | ||
| 131 | #set ($fullName = $services.model.serialize($themeReference, 'local')) | ||
| 132 | #else | ||
| 133 | #set ($fullName = $services.model.serialize($themeReference, 'default')) | ||
| 134 | #end | ||
| 135 | #set ($isCurrentTheme = ($currentThemeDoc.documentReference == $themeReference)) | ||
| 136 | #set ($themeDoc = $xwiki.getDocument($themeReference)) | ||
| 137 | #set ($themeObj = $themeDoc.getObject('FlamingoThemesCode.ThemeClass')) | ||
| 138 | * (% class="theme #if($isCurrentTheme) current-theme#end" %) | ||
| 139 | ((( | ||
| 140 | ## Display the mockup | ||
| 141 | #themeMockup($themeObj) | ||
| 142 | ## Display the informations | ||
| 143 | (% class="theme-info" %) | ||
| 144 | ((( | ||
| 145 | #set ($themeDocTitle = $services.rendering.escape($services.rendering.escape($themeDoc.displayTitle, 'xwiki/2.1'), | ||
| 146 | 'xwiki/2.1')) | ||
| 147 | #set ($themeDocLink = $services.rendering.escape($fullName, 'xwiki/2.1')) | ||
| 148 | === [[$themeDocTitle>>$themeDocLink]] #if ($isSubWiki && $scope == | ||
| 149 | 'local') ($services.rendering.escape($services.wiki.currentWikiId, 'xwiki/2.1'))#end=== | ||
| 150 | #if ($hasAdmin && !$isCurrentTheme) | ||
| 151 | #set ($useThisThemeTitle = $services.rendering.escape($services.rendering.escape($services.localization.render( | ||
| 152 | 'platform.flamingo.themes.home.useThisTheme'), 'xwiki/2.1'), 'xwiki/2.1')) | ||
| 153 | #set ($viewThemeUrl = $doc.getURL('view', $escapetool.url({ | ||
| 154 | 'action': 'setTheme', | ||
| 155 | 'theme': $fullName, | ||
| 156 | 'form_token': $services.csrf.token | ||
| 157 | }))) | ||
| 158 | #set ($useThisThemePath = "path:$viewThemeUrl") | ||
| 159 | $services.icon.render('bullet_go') [[$useThisThemeTitle>>$useThisThemePath]] | ||
| 160 | #end | ||
| 161 | ))) | ||
| 162 | ))) | ||
| 163 | #end | ||
| 164 | #################################### | ||
| 165 | ## THEME MOCKUP | ||
| 166 | #################################### | ||
| 167 | #macro(themeMockup $themeObj) | ||
| 168 | #macro(displayValue $variableName $fallback) | ||
| 169 | #set($value = $themeObj.getValue($variableName)) | ||
| 170 | #if("$!value" == '') | ||
| 171 | #set($value = $fallback) | ||
| 172 | #end | ||
| 173 | $escapetool.xml($value)## | ||
| 174 | #end | ||
| 175 | |||
| 176 | {{html}} | ||
| 177 | <div class="mockup-page" style="background-color: #displayValue('body-bg', '#fff')"> | ||
| 178 | ## A fake navbar | ||
| 179 | <div class="mockup-navbar" style="background-color: #displayValue('navbar-default-bg', '#eee')"> | ||
| 180 | ## A fake logo | ||
| 181 | <div class="mockup-logo"></div> | ||
| 182 | ## A fake menu | ||
| 183 | <div class="mockup-navbar-menu" style="border-color: #displayValue('navbar-default-color', '#000')"></div> | ||
| 184 | ## A fake add button | ||
| 185 | <div class="mockup-add-button" style="background-color: #displayValue('btn-success-bg', '#4D9244')"></div> | ||
| 186 | </div> | ||
| 187 | |||
| 188 | ## A fake page content | ||
| 189 | <div class="mockup-page-content" style="background-color: #displayValue('xwiki-page-content-bg', '#fff')"> | ||
| 190 | <div class="mockup-title" style="border-color: #displayValue('text-color', '#000')"></div> | ||
| 191 | <div class="mockup-text1" style="border-color: #displayValue('text-color', '#000')"></div> | ||
| 192 | <div class="mockup-text2" style="border-color: #displayValue('text-color', '#000')"></div> | ||
| 193 | <div class="mockup-text3" style="border-color: #displayValue('text-color', '#000')"></div> | ||
| 194 | <div class="mockup-text4" style="border-color: #displayValue('link-color', '#000')"></div> | ||
| 195 | <div class="mockup-text5" style="border-color: #displayValue('text-color', '#0000ff')"></div> | ||
| 196 | </div> | ||
| 197 | |||
| 198 | ## A fake app bar | ||
| 199 | <div class="mockup-left-panel" style="color: #displayValue('link-color', '#0000ff')"></div> | ||
| 200 | |||
| 201 | ## A fake right panel | ||
| 202 | <div class="mockup-right-panel"> | ||
| 203 | <div class="mockup-right-panel-header" style="color: #displayValue('panel-default-text', '#000'); background-color: #displayValue('panel-bg', '#fff')"> | ||
| 204 | <div class="mockup-right-panel-header-text" style="border-color: #displayValue('panel-default-text', '#000')"></div> | ||
| 205 | </div> | ||
| 206 | <div class="mockup-right-panel-contents" style="background-color: #displayValue('panel-bg', '#fff')"> | ||
| 207 | <div class="mockup-right-panel-text1" style="background-color: #displayValue('panel-default-text', '#000')"> </div> | ||
| 208 | <div class="mockup-right-panel-text2" style="background-color: #displayValue('panel-default-text', '#000')"> </div> | ||
| 209 | <div class="mockup-right-panel-text3" style="background-color: #displayValue('link-color', '#0000ff')"> </div> | ||
| 210 | </div> | ||
| 211 | </div> | ||
| 212 | |||
| 213 | ## A fake footer | ||
| 214 | <div class="mockup-footer" style="background-color: #displayValue('navbar-default-bg', '#fff')"> | ||
| 215 | <div class="mockup-footer-content" style="border-color: #displayValue('navbar-default-link-color', '#000')"> | ||
| 216 | </div> | ||
| 217 | |||
| 218 | </div> | ||
| 219 | {{/html}} | ||
| 220 | |||
| 221 | #end | ||
| 222 | #################################### | ||
| 223 | ## CREATION FORM | ||
| 224 | #################################### | ||
| 225 | #macro(creationForm) | ||
| 226 | #if($xwiki.hasAccessLevel('edit', $xcontext.user, 'FlamingoThemes.AnyPage____________')) | ||
| 227 | {{html}} | ||
| 228 | <form class="theme-creation-form form-inline" action="$doc.getURL()" method="post"> | ||
| 229 | $services.icon.renderHTML('add') | ||
| 230 | <input type="hidden" name="form_token" value="$services.csrf.token" /> | ||
| 231 | <input type="hidden" name="action" value="create"/> | ||
| 232 | <label for="newThemeName" class="hidden">$services.localization.render('platform.flamingo.themes.home.newThemeName')</label> | ||
| 233 | <input type="text" name="newThemeName" id="newThemeName" value="$services.localization.render('platform.flamingo.themes.home.newThemeName')" class="withTip" size="30"/> | ||
| 234 | <input type="submit" value="$services.localization.render('platform.flamingo.themes.home.create')" class="button"/> | ||
| 235 | </form> | ||
| 236 | {{/html}} | ||
| 237 | #end | ||
| 238 | #end | ||
| 239 | #################################### | ||
| 240 | ## CREATE A NEW THEME | ||
| 241 | #################################### | ||
| 242 | #macro(create) | ||
| 243 | #if("$!request.newThemeName" == '') | ||
| 244 | {{error}} | ||
| 245 | {{translation key="platform.flamingo.themes.home.create.invalid" /}} | ||
| 246 | {{/error}} | ||
| 247 | |||
| 248 | #creationForm() | ||
| 249 | #elseif(!$services.csrf.isTokenValid($request.form_token)) | ||
| 250 | {{error}} | ||
| 251 | #set ($newThemeName = $services.rendering.escape($escapetool.java($request.newThemeName), 'xwiki/2.1')) | ||
| 252 | {{translation key="platform.flamingo.themes.home.create.csrf" parameters="~"$newThemeName~""/}} | ||
| 253 | {{/error}} | ||
| 254 | |||
| 255 | {{html}} | ||
| 256 | <form action="$doc.getURL()" method="post"> | ||
| 257 | <input type="hidden" name="form_token" value="$services.csrf.token" /> | ||
| 258 | <input type="hidden" name="action" value="create"/> | ||
| 259 | <input type="hidden" name="newThemeName" id="newThemeName" value="$escapetool.xml($request.newThemeName)" /> | ||
| 260 | <input type="submit" value="$services.localization.render('platform.flamingo.themes.home.create.confirm')" class="button"/> | ||
| 261 | </form> | ||
| 262 | {{/html}} | ||
| 263 | #else | ||
| 264 | ## Let's do it | ||
| 265 | $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&form_token=${request.form_token}")) | ||
| 266 | #end | ||
| 267 | #end | ||
| 268 | #################################### | ||
| 269 | ## SET THEME | ||
| 270 | #################################### | ||
| 271 | #macro(setTheme) | ||
| 272 | #if("$!request.theme" != '' && $hasAdmin && ${services.csrf.isTokenValid("$!{request.getParameter('form_token')}")}) | ||
| 273 | #set($preferencesDoc = $xwiki.getDocument('XWiki.XWikiPreferences')) | ||
| 274 | #set($preferencesObj = $preferencesDoc.getObject('XWiki.XWikiPreferences')) | ||
| 275 | $preferencesObj.set('colorTheme', $request.theme) | ||
| 276 | $preferencesDoc.save() | ||
| 277 | $response.sendRedirect($doc.getURL('view', "theme=$escapetool.url($request.theme)&action=setThemeSuccess")) | ||
| 278 | #end | ||
| 279 | #end | ||
| 280 | #################################### | ||
| 281 | ## SET THEME SUCCESS | ||
| 282 | #################################### | ||
| 283 | #macro(setThemeSuccess) | ||
| 284 | #if("$!request.theme" != '') | ||
| 285 | |||
| 286 | {{success}} | ||
| 287 | $services.localization.render('platform.flamingo.themes.home.set.success', [$xwiki.getDocument($request.theme).displayTitle]) | ||
| 288 | {{/success}} | ||
| 289 | |||
| 290 | #end | ||
| 291 | #end | ||
| 292 | {{/velocity}} | ||
| 293 |