FlamingoThemesCode

De SupraWiki
Revisão de 15h51min de 1 de junho de 2023 por Administrator (discussão | contribs) (Importacão de dados via API)
(dif) ← Edição anterior | Revisão atual (dif) | Versão posterior → (dif)

Predefinição:Velocity

    1. Globals
  1. set ($discard = $xwiki.ssx.use('FlamingoThemesCode.WebHomeSheet'))
    1. CONTROLLER
  2. if($request.action == 'setTheme')
 #setTheme()
  1. elseif($request.action == 'setThemeSuccess')
 #prepareView()
 #setThemeSuccess()
 #view()
  1. elseif($request.action == 'create')
 #create()
  1. else
 #prepareView()
 #view()
  1. end
    1. PREPARE VIEW
  2. 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
  1. end
    1. Get Flamingo themes
  2. 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)
  1. end
    1. Get themes from a query
  2. 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)
  1. end
    1. VIEW
  2. 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
 )))
  1. end
    1. DISPLAY THEME
  2. 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
   )))
 )))
  1. end
    1. THEME MOCKUP
  2. 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 logo
       ## A fake menu
       ## A fake add button
     ## A fake page content
     ## A fake app bar 
     ## A fake right panel
     ## A fake footer
 Predefinição:/html
 
  1. end
    1. CREATION FORM
  2. 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
  1. end
    1. CREATE A NEW THEME
  2. 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
  1. end
    1. SET THEME
  2. 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
  1. end
    1. SET THEME SUCCESS
  2. 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
  1. end

Predefinição:/velocity