Improve macros.vm backwards compatibility

XMLWordPrintable

      The renderChildren macro in macros.vm could be made more backwards compatible by rearranging the code VERY slightly

      current code:

      #macro (renderChildren)
          #if ($helper.action.getPermittedChildren().size() > 0 && $page.latestVersion)
              <div id="pageChildren" class="pageSection">
              #set ($page = $helper.page)
              #if (!$helper.childrenShowing)
                  #set ($extraHeaderClass="summary")
              #end
                  
              <div class="pageSectionHeader $!extraHeaderClass">
                  #if ($helper.childrenShowing)
                      <a name="children" id="childrenSectionTitle" class="pageSectionTitle">$action.getText('children.title')</a>
                      &nbsp;
                      <a class="grey" href="$req.contextPath$generalUtil.customGetPageUrl($page)showChildren=false&#0035;children">$action.getText('hide.children')</a>
                  #else
                      #if ($helper.action.getPermittedChildren().size() > 1)
                          <a id="pageChildrenCount" name="children" id="childrenSectionTitle" class="pageSectionTitle">$action.getText('number.of.children',["$helper.action.getPermittedChildren().size()"])</a>
                      #else
                          <a id="pageChildrenCount" name="children" id="childrenSectionTitle" class="pageSectionTitle">$action.getText('number.of.children.one')</a>
                      #end
                      &nbsp;
                      <a class="grey" href="$req.contextPath$generalUtil.customGetPageUrl($page)showChildren=true&#0035;children">$action.getText('show.children')</a>
                  #end
      
                  &nbsp;|&nbsp; <a class="grey" href="$req.contextPath/pages/listpages-dirview.action?key=$page.space.key&openId=$page.id#selectedPageInHierarchy">$action.getText('view.in.hierarchy')</a>
                  #if ($permissionHelper.canCreatePage($remoteUser, $space))
                      #if ($page.type == "page")
                          &nbsp;|&nbsp;
                          <a class="grey" href="$req.contextPath/pages/createpage.action?spaceKey=$generalUtil.urlEncode($space.key)&fromPageId=$page.id">$helper.getText("action.add.page.child")</a>
                      #end
                  #end
              </div>
              #if ($helper.childrenShowing)
                  <div id="pageChildrenList" class="pageSectionBody">
                      #foreach ($child in $helper.action.getPermittedChildren())
                          #contentLink2 ($child true false) ## space key after the link is redundant
                          <br>
                      #end
                  </div>
              #end
              </div>
          #end
      #end
      

      Re-arranged code:

      #macro (renderChildren)
          #set ($page = $helper.page)
          #if ($helper.action.getPermittedChildren().size() > 0 && $page.latestVersion)
              <div id="pageChildren" class="pageSection">
              #if (!$helper.childrenShowing)
                  #set ($extraHeaderClass="summary")
              #end
                  
              <div class="pageSectionHeader $!extraHeaderClass">
                  #if ($helper.childrenShowing)
                      <a name="children" id="childrenSectionTitle" class="pageSectionTitle">$action.getText('children.title')</a>
                      &nbsp;
                      <a class="grey" href="$req.contextPath$generalUtil.customGetPageUrl($page)showChildren=false&#0035;children">$action.getText('hide.children')</a>
                  #else
                      #if ($helper.action.getPermittedChildren().size() > 1)
                          <a id="pageChildrenCount" name="children" id="childrenSectionTitle" class="pageSectionTitle">$action.getText('number.of.children',["$helper.action.getPermittedChildren().size()"])</a>
                      #else
                          <a id="pageChildrenCount" name="children" id="childrenSectionTitle" class="pageSectionTitle">$action.getText('number.of.children.one')</a>
                      #end
                      &nbsp;
                      <a class="grey" href="$req.contextPath$generalUtil.customGetPageUrl($page)showChildren=true&#0035;children">$action.getText('show.children')</a>
                  #end
      
                  &nbsp;|&nbsp; <a class="grey" href="$req.contextPath/pages/listpages-dirview.action?key=$page.space.key&openId=$page.id#selectedPageInHierarchy">$action.getText('view.in.hierarchy')</a>
                  #if ($permissionHelper.canCreatePage($remoteUser, $space))
                      #if ($page.type == "page")
                          &nbsp;|&nbsp;
                          <a class="grey" href="$req.contextPath/pages/createpage.action?spaceKey=$generalUtil.urlEncode($space.key)&fromPageId=$page.id">$helper.getText("action.add.page.child")</a>
                      #end
                  #end
              </div>
              #if ($helper.childrenShowing)
                  <div id="pageChildrenList" class="pageSectionBody">
                      #foreach ($child in $helper.action.getPermittedChildren())
                          #contentLink2 ($child true false) ## space key after the link is redundant
                          <br>
                      #end
                  </div>
              #end
              </div>
          #end
      #end
      

      All I've done is move the #set page outside the if statement ... if $page doesnt exist then the whole children display fails.

              Assignee:
              m@ (Inactive)
              Reporter:
              Ivan Benko [Atlassian]
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved: