FlamingoThemesCode: mudanças entre as edições

De SupraWiki
(Importacão de dados via API)
 
(Importacão de dados via API)
 
Linha 1: Linha 1:
{{velocity}}
{{velocity}}
{{documentTree showTranslations="false" showAttachments="false" root="document:$doc.documentReference" /}}
################################
## 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')))
      {{info}}
        $services.localization.render('platform.flamingo.themes.home.warningOldColorThemeInstalled', ["[[", ">>ColorThemes.WebHome]]"])
      {{/info}}
    #end
   
    ## Display the current theme
    == $services.localization.render('platform.flamingo.themes.home.currenttheme') ==
    #if($currentThemeDoc.getObject('ColorThemes.ColorThemeClass'))
      {{warning}}
        $services.localization.render('platform.flamingo.themes.home.warningCurrentOldColorTheme')
      {{/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())
      {{html}}
      <ul class="nav nav-tabs" role="tablist">
        <li role="presentation" class="active"><a href="#local" role="tab" data-toggle="tab">$escapetool.xml($services.localization.render('platform.flamingo.themes.local'))</a></li>
        <li role="presentation"><a href="#global" role="tab" data-toggle="tab">$escapetool.xml($services.localization.render('platform.flamingo.themes.global'))</a></li>
      </ul>
      {{/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
 
  {{html}}
    <div class="mockup-page" style="background-color: #displayValue('body-bg', '#fff')">
      ## A fake navbar
      <div class="mockup-navbar" style="background-color: #displayValue('navbar-default-bg', '#eee')">
        ## A fake logo
        <div class="mockup-logo"></div>
        ## A fake menu
        <div class="mockup-navbar-menu" style="border-color: #displayValue('navbar-default-color', '#000')"></div>
        ## A fake add button
        <div class="mockup-add-button" style="background-color: #displayValue('btn-success-bg', '#4D9244')"></div>
      </div>
     
      ## A fake page content
      <div class="mockup-page-content" style="background-color: #displayValue('xwiki-page-content-bg', '#fff')">
        <div class="mockup-title" style="border-color: #displayValue('text-color', '#000')"></div>
        <div class="mockup-text1" style="border-color: #displayValue('text-color', '#000')"></div>
        <div class="mockup-text2" style="border-color: #displayValue('text-color', '#000')"></div>
        <div class="mockup-text3" style="border-color: #displayValue('text-color', '#000')"></div>
        <div class="mockup-text4" style="border-color: #displayValue('link-color', '#000')"></div>
        <div class="mockup-text5" style="border-color: #displayValue('text-color', '#0000ff')"></div>
      </div>
     
      ## A fake app bar
      <div class="mockup-left-panel" style="color: #displayValue('link-color', '#0000ff')"></div>
     
      ## A fake right panel
      <div class="mockup-right-panel">
        <div class="mockup-right-panel-header" style="color: #displayValue('panel-default-text', '#000'); background-color: #displayValue('panel-bg', '#fff')">
          <div class="mockup-right-panel-header-text" style="border-color: #displayValue('panel-default-text', '#000')"></div>
        </div>
        <div class="mockup-right-panel-contents" style="background-color: #displayValue('panel-bg', '#fff')">
          <div class="mockup-right-panel-text1" style="background-color: #displayValue('panel-default-text', '#000')"> </div>
          <div class="mockup-right-panel-text2" style="background-color: #displayValue('panel-default-text', '#000')"> </div>
          <div class="mockup-right-panel-text3" style="background-color: #displayValue('link-color', '#0000ff')"> </div>
        </div>
      </div>
     
      ## A fake footer
      <div class="mockup-footer" style="background-color: #displayValue('navbar-default-bg', '#fff')">
        <div class="mockup-footer-content" style="border-color: #displayValue('navbar-default-link-color', '#000')">
      </div>
     
    </div>
  {{/html}}
 
#end
####################################
## CREATION FORM
####################################
#macro(creationForm)
  #if($xwiki.hasAccessLevel('edit', $xcontext.user, 'FlamingoThemes.AnyPage____________'))
    (% class="clearfix" %)
    (((
 
    {{html}}
      <div class="theme-creation-form" >
        <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>
      </div>
    {{/html}}
   
    )))
  #end
#end
####################################
## CREATE A NEW THEME
####################################
#macro(create)
  #if("$!request.newThemeName" == '')
    {{error}}
      {{translation key="platform.flamingo.themes.home.create.invalid" /}}
    {{/error}}
   
    #creationForm()
  #elseif(!$services.csrf.isTokenValid($request.form_token))
    {{error}}
      {{translation key="platform.flamingo.themes.home.create.csrf" parameters="$request.newThemeName" /}}
    {{/error}}
   
    {{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>
    {{/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" != '')
 
    {{success}}
      $services.localization.render('platform.flamingo.themes.home.set.success', [$xwiki.getDocument($request.theme).displayTitle])
    {{/success}}
   
  #end
#end
{{/velocity}}
{{/velocity}}

Edição atual tal como às 15h51min de 1 de junho de 2023

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