##
##
## Extra data: comments, attachments ...
##
<div id="xwikidata" class="layoutsubsection">
##
## Build the list of documents extras to display, if it does not exist (default).
## List format : ["ExtraAnchor", "ExtraName", "ExtraTabText", ExtraNumberOfItems, "extratemplate.vm", "keyboardShortcut"]
##

## -------------------------------
#if ($doc.space=="Inemar")
  #set($docextras = "no")
  #set($showcomments = "no")
  #set($showattachments = "no")
  #set($showinformation = "no")
#end
#if ($doc.space=="InemarDatiWeb")
  #set($docextras = "no")
  #set($showcomments = "no")
  #set($showattachments = "no")
  #set($showinformation = "no")
#end
#if ($context.user == "XWiki.XWikiGuest")
  #set($showattachments = "no")
  #set($showinformation = "no")
#end
#set($showhistory = "no")
## -------------------------------

#if (!$docextras)
  #if("$!{showcomments}" == "")
    #set($showcomments = $xwiki.getWebPreference("showcomments"))
  #end
  #if("$!{showattachments}" == "")
    #set($showattachments = $xwiki.getWebPreference("showattachments"))
  #end
  #if("$!{showhistory}" == "")
    #set($showhistory = $xwiki.getWebPreference("showhistory"))
  #end
  #if("$!{showinformation}" == "")
    #set($showinformation = $xwiki.getWebPreference("showinformation"))
  #end
  #set($docextras = $util.arrayList)
  #if($showcomments != false && $showcomments != "no" && $showcomments != "0" && $showcomments != "false")
    $xwiki.jsfx.use('uicomponents/viewers/comments.js', {'forceSkinAction': true, 'language': ${context.language}})
    $xwiki.ssfx.use('uicomponents/viewers/comments.css', true)
    #set ($discard = $docextras.add(["Comments", "comments", $msg.get("docextra.comments"), $doc.getObjects("XWiki.XWikiComments").size(), "commentsinline.vm", $msg.get("core.shortcuts.view.comments")]))
  #end
  #if($showattachments != false && $showattachments != "no" && $showattachments != "0" && $showattachments != "false")
    $xwiki.jsfx.use('js/xwiki/viewers/attachments.js', {'forceSkinAction': true, 'language': ${context.language}})
    $xwiki.ssfx.use('js/xwiki/viewers/attachments.css', true)
    #set ($discard = $docextras.add(["Attachments", "attachments", $msg.get("docextra.attachments"), $doc.getAttachmentList().size(), "attachmentsinline.vm",$msg.get("core.shortcuts.view.attachments")]))
  #end
  #if($showhistory != false && $showhistory != "no" && $showhistory != "0" && $showhistory != "false")
    #set ($discard = $docextras.add(["History", "history", $msg.get("docextra.history"), -1, "historyinline.vm", $msg.get("core.shortcuts.view.history")]))
  #end
  #if($showinformation != false && $showinformation != "no" && $showinformation != "0" && $showinformation != "false")
    #set ($discard = $docextras.add(["Information", "information", $msg.get("docextra.information"), -1, "informationinline.vm", $msg.get("core.shortcuts.view.information")]))
  #end
#end
##
## Put anchors before the footer, otherwise the top of each section would be hidden by the floating topmenu
##
#if($docextras.size() > 0)
<div id="docextraanchors" class="invisible">
#foreach($docextra in $docextras)<span id="${listtool.get($docextra, 0)}anchor">&nbsp;</span>#end
</div>
#end
#macro(docabout)
<div class="about">
##
## Last modification
##
##<span id="aboutauthor">$msg.get("lastmodifiedby")$xwiki.getLocalUserName($tdoc.author)</span>
##<span id="aboutdate">$msg.get("lastmodifiedon") $!xwiki.formatDate($tdoc.date)</span>
</div>
#end
#docabout()
##
## Display tabs
##
#if($docextras.size() > 0)
  <div id="xwikidatacontents">
    <div class="floatcontainer" id="docExtraTabs">
      <ul class="xwikitabbar" id="docExtrasTabsUl">
        #foreach($docextra in $docextras)
          #set ($extraAnchor = $listtool.get($docextra, 0))
          #set ($extraName = $listtool.get($docextra, 1))
          #set ($extraTabText = $listtool.get($docextra, 2))
          #set ($extraNbOfItems = $listtool.get($docextra, 3))
          <li id="${extraAnchor}tab">
            #set ($args = "viewer=${extraName}")
            <a id="${extraAnchor}link" href="$doc.getURL('view', $args)">
              $extraTabText #if($extraNbOfItems >= 0) <span class="itemcount">$msg.get("docextra.extranb", [$extraNbOfItems])</span> #end
            </a>
          </li>
        #end
      </ul>
    </div>
    ##
    ## Display panes (AJAX placeholders)
    ##
    <div id="docextrapanes">
      #foreach($docextra in $docextras)
        #set ($extraAnchor = $listtool.get($docextra, 0))
        <div id="${extraAnchor}pane" class="hidden empty"></div>
      #end
    </div>
    ##
    ## JavaScript code generation
    ##
    <script type="text/javascript">
      var hashviewer = self.document.location.hash.substring(1);
      #foreach($docextra in $docextras)
        #set ($extraAnchor = $listtool.get($docextra, 0))
        #set ($extraTemplate = $listtool.get($docextra, 4))
        #set ($extraShortcut = $listtool.get($docextra, 5))
        ##
        ## Set the extra to load
        ##
        #if ($velocityCount == 1)
          var extraInit = function(){ XWiki.displayDocExtra("${extraAnchor}", "${extraTemplate}", false) };
        #end
        if (hashviewer == "${extraAnchor}") {
          var extraInit = function(){ XWiki.displayDocExtra("${extraAnchor}", "${extraTemplate}", true) };
        }
        ##
        ## Replace tab link
        ##
        if ($("${extraAnchor}link") != null) {
          $("${extraAnchor}link").href="#${extraAnchor}";
          Event.observe($("${extraAnchor}link"), "click", function(){ XWiki.displayDocExtra("${extraAnchor}", "${extraTemplate}", false); }, false);
        }
        ##
        ## Replace top menu link (if any)
        ##
        if ($("tmShow${extraAnchor}") != null) {
          $("tmShow${extraAnchor}").href="#${extraAnchor}";
          Event.observe($("tmShow${extraAnchor}"), "click", function(){ XWiki.displayDocExtra("${extraAnchor}", "${extraTemplate}", true); }, false);
        }
        ##
        ## Override keyboard shortcut (if any)
        ##
        #if ($keyboardShortcutsEnabled && "$!extraShortcut" != "")
          shortcut.remove("$extraShortcut");
          shortcut.add("$extraShortcut", function() { XWiki.displayDocExtra("${extraAnchor}", "${extraTemplate}", true); }, { 'type':'keypress', 'propagate':false, 'disable_in_input':true });
        #end
      #end
      document.observe("dom:loaded", extraInit, false);
    </script>
  </div> ## xwikidatacontents
#end
</div>  ## xwikidata
