<!--
-->
<xsl:stylesheet xmlns:x="http://www.w3.org/2001/XMLSchema" xmlns:d="http://schemas.microsoft.com/sharepoint/dsp" version="1.0" exclude-result-prefixes="xsl msxsl ddwrt SharePoint x d asp __designer GroupBoard ddwrt2" xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime" xmlns:asp="http://schemas.microsoft.com/ASPNET/20" xmlns:__designer="http://schemas.microsoft.com/WebParts/v2/DataView/designer" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:GroupBoard="Microsoft.SharePoint.Applications.GroupBoard.WebControls" xmlns:ddwrt2="urn:frontpage:internal" xmlns:SharePoint="Microsoft.SharePoint.WebControls">
  <xsl:import href="/_layouts/15/xsl/main.xsl"/>
  <xsl:output method="html" indent="no"/>
  <!-- 
	This XSLT is for GroupBoard workspace feature
  -->
  <!-- Whereabout starts here -->
  <xsl:template match ="FieldRef[@Name='RefWhereabout']" mode="Computed_body">
    <xsl:param name="thisNode" select="."/>
    <xsl:choose>
      <xsl:when test="$MasterVersion>=4">
        <div class="ms-vb itx" onmouseover="OnItem(this)" CTXName="ctx{$ViewCounter}" Id="{$thisNode/@ID}" Perm="$thisNode/@PermMask">
          <xsl:call-template name="RefWhereabout">
            <xsl:with-param name="thisNode" select ="$thisNode"/>
          </xsl:call-template>
        </div>
	<!-- render the markup for list item chevron from server side -->
	<div class="s4-ctx" onmouseover="OnChildItem(this.parentNode); return false;">
	  <span>&#160;</span>
	  <a onfocus="OnChildItem(this.parentNode.parentNode); return false;" onclick="PopMenuFromChevron(event); return false;" href="javascript:;" title="{$open_menu}">
          </a>
          <span>&#160;</span>
	</div>
      </xsl:when>
      <xsl:otherwise>
        <table height="100%" cellspacing="0" class="ms-unselectedtitle itx" onmouseover="OnItem(this)" CTXName="ctx{$ViewCounter}" Id="{$thisNode/@ID}">
          <tr>
            <td width="100%" class="ms-vb">
              <xsl:call-template name="RefWhereabout">
                <xsl:with-param name="thisNode" select ="$thisNode"/>
              </xsl:call-template>
            </td>
            <td>
              <img src="/_layouts/15/images/blank.gif?rev=23" width="13" style="visibility:hidden" alt="" />
            </td>
          </tr>
        </table>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
  <xsl:template name="RefWhereabout">
    <xsl:param name="thisNode" select="."/>
    <a onfocus="OnLink(this)" href="{$FORM_DISPLAY}&amp;ID={$thisNode/@ID}" onclick="GoToLink(this);return false;" target="_self">
      <xsl:variable name="whereaboutvalue" select="$thisNode/@Whereabout"/>
      <xsl:if test="not($whereaboutvalue='')" ddwrt:cf_ignore="1">
        <xsl:value-of select="$whereaboutvalue" />
      </xsl:if>
    </a>
    <xsl:if test="$thisNode/@Created_x0020_Date.ifnew='1'">
      <xsl:call-template name="NewGif"/>
    </xsl:if>
  </xsl:template>
  <!-- Whereabout ends here -->
  <xsl:template name="GroupBoardViewOverride" mode="RootTemplate" match="View[List/@TemplateType=404 or List/@TemplateType=405]" ddwrt:dvt_mode="root">
    <xsl:if test="$MasterVersion &lt; 4">
    <xsl:choose>
      <xsl:when test="ddwrt:IfDebug() = 'True'">
        <script type="text/javascript" src="/_layouts/15/groupboard.debug.js"/>
      </xsl:when>
      <xsl:otherwise>
        <script type="text/javascript" src="/_layouts/15/groupboard.js"/>
      </xsl:otherwise>
    </xsl:choose>
    <ink REL="stylesheet" Type="text/css" HREF="/_layouts/15/{$LCID}/styles/groupboard.css" />
    </xsl:if>
    <xsl:call-template name="View_Default_RootTemplate"/>
  </xsl:template>
  <xsl:template name="GroupBoardViewTimecardOverride" mode="RootTemplate" match="View[List/@TemplateType=420]" ddwrt:dvt_mode="root">
    <xsl:choose>
      <xsl:when test="./@BaseViewID='0'">
        <xsl:value-of select="$Rows/@resource.wss.GroupBoardTimeCardListViewWPError"/>
      </xsl:when>
      <xsl:when test="./@BaseViewID='1'">
        <xsl:call-template name="CTXGeneration"/>
        <script language="JavaScript">var _spUseDefaultFocus = true;</script>
        <GroupBoard:TCSettingsControl JSObjectName="gTCConfig" runat="server" />
        <GroupBoard:MyTimeCardControl runat="server" />
        <div id="TimeCardSaveButtonDiv">
          <asp:Button ID="Save" Text="save" runat="server" style="display:none;" />
        </div>
      </xsl:when>
    </xsl:choose>
  </xsl:template>
  <!-- 
       CallTo and SendTo field ... Same as user field
  -->
  <xsl:template ddwrt:dvt_mode="body" match="FieldRef[@Type='CallTo' or @Type='SendTo' or @Type='Facilities' or @Type='Confidential']" mode="body">
    <xsl:param name="thisNode" select="."/>
    <xsl:value-of disable-output-escaping="yes" select="$thisNode/@*[name()=current()/@Name]" />
  </xsl:template>
  <!-- Calltrack starts here -->
  <!-- Action field -->
  <xsl:template match ="FieldRef[@ID='0e66a972-f8a7-42c3-8c06-0249cdd86873']" mode="Computed_body">
    <xsl:param name="thisNode" select="."/>
    <xsl:variable name="cinfo">
      <xsl:call-template name="GB_ExtractCallTrackUsers">
        <xsl:with-param name="ExpandedCallTo" select="$thisNode/@ExpandedCallTo.id"/>
      </xsl:call-template>
    </xsl:variable>
    <xsl:variable name="ConfirmedTo" select="msxsl:node-set($cinfo)/extracted/text()"/>
    <xsl:if test="contains($ConfirmedTo,concat(';#',$Userid,';#'))">
    <xsl:choose>
      <!-- V4 mode, With Ribbon there's no submit button in the list view -->
      <xsl:when test="$MasterVersion &gt;=4">
        <xsl:choose>
          <xsl:when test="$thisNode/@Resolved.value=1">
            <input type="hidden" id="Action#{$List}#{$thisNode/@ID}" value="Unresolve"/>
          </xsl:when>
          <xsl:otherwise>
            <input type="hidden" id="Action#{$List}#{$thisNode/@ID}" value="Resolve"/>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:when>
      <!-- V3 mode, we need a button in each list item -->
      <xsl:otherwise>
        <xsl:choose>
          <xsl:when test="$thisNode/@Resolved.value=1">
            <input type="button" class="ms-sgs-markread-button"
                   value="{$thisNode/../@resource.wss.GroupBoardCalltrackActionUnresolve}"
                   onclick="Calltrack_Resolve('{$HttpVDir}/_layouts/15/','{$List}','{$thisNode/@ID}','Unresolve');"/>
          </xsl:when>
          <xsl:otherwise>
            <input type="button" class="ms-sgs-markread-button"
                   value="{$thisNode/../@resource.wss.GroupBoardCalltrackActionResolve}"
                   onclick="Calltrack_Resolve('{$HttpVDir}/_layouts/15/','{$List}','{$thisNode/@ID}','Resolve');"/>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:otherwise>
    </xsl:choose>
    </xsl:if>
  </xsl:template>
  <!--
  Build ConfirmedTo field value
  -->
  <xsl:template name="GB_ExtractCallTrackUsers">
    <xsl:param name="ExpandedCallTo"/>
    <xsl:choose>
      <xsl:when test="$ExpandedCallTo != ''">
        <xsl:call-template name="GB_ExtractUsersRecursive">
          <xsl:with-param name="userField" select="$ExpandedCallTo"/>
          <xsl:with-param name="extracted">;#</xsl:with-param>
          <xsl:with-param name="counter" select="0"/>
        </xsl:call-template>
      </xsl:when>
      <xsl:otherwise>
        <xsl:element name="extracted">;#</xsl:element>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
  <!-- Calltrack ends here -->
  <!-- Circulation starts here -->
  <!-- Action field -->
  <xsl:template match ="FieldRef[@ID='77df965a-78ad-4f35-b132-e3d39db0a8ef']" mode="Computed_body">
    <xsl:param name="thisNode" select="."/>
    <xsl:variable name="cinfo">
      <xsl:call-template name="GB_ExtractCirculationUsers">
        <xsl:with-param name="V4Confirmed" select="$thisNode/@V4Confirmed.id"/>
        <xsl:with-param name="V4NotConfirmed" select="$thisNode/@V4NotConfirmed.id"/>
      </xsl:call-template>
    </xsl:variable>
    <xsl:variable name="Confirmed" select="msxsl:node-set($cinfo)/confirm/extracted/text()"/>
    <xsl:variable name="NotConfirmed" select="msxsl:node-set($cinfo)/notconfirm/extracted/text()"/>
    <xsl:choose>
      <!-- V4 mode, With Ribbon there's no submit button in the list view -->
      <xsl:when test="$MasterVersion &gt;=4">
        <xsl:choose>
          <xsl:when test="contains($Confirmed, concat(';#',$Userid,';#'))">
            <input type="hidden" id="Action#{$List}#{$thisNode/@ID}" value="Disconfirm"/>
          </xsl:when>
          <xsl:when test="contains($NotConfirmed, concat(';#',$Userid,';#'))">
            <input type="hidden" id="Action#{$List}#{$thisNode/@ID}" value="Confirm"/>
          </xsl:when>
        </xsl:choose>
      </xsl:when>
      <!-- V3 mode, we need a button in each list item -->
      <xsl:otherwise>
        <xsl:choose>
          <xsl:when test="contains($Confirmed, concat(';#',$Userid,';#'))">
            <input type="button" class="ms-sgs-confirm-button"
                   value="{$thisNode/../@resource.wss.GroupBoardCirculationActionDisconfirm}"
                   onclick="Circulation_Confirm('{$HttpVDir}/_layouts/15/','{$List}','{$thisNode/@ID}','Disconfirm');"/>
          </xsl:when>
          <xsl:when test="contains($NotConfirmed, concat(';#',$Userid,';#'))">
            <input type="button" class="ms-sgs-confirm-button"
                   value="{$thisNode/../@resource.wss.GroupBoardCirculationActionConfirm}"
                   onclick="Circulation_Confirm('{$HttpVDir}/_layouts/15/','{$List}','{$thisNode/@ID}','Confirm');"/>
          </xsl:when>
        </xsl:choose>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
  <!--
  RefDetail - Comment
  -->
  <xsl:template match ="FieldRef[@Name='RefDetail']" mode="Computed_body">
    <xsl:param name="thisNode" select="."/>
    <xsl:value-of select="$thisNode/@Detail" disable-output-escaping="yes" />
  </xsl:template>
  <!--
  ConfirmedUser - n/n
  -->
  <xsl:template match ="FieldRef[@Name='ConfirmStatus']" mode="Computed_body">
    <xsl:param name="thisNode" select="."/>
    <xsl:variable name="cinfo">
      <xsl:call-template name="GB_ExtractCirculationUsers">
        <xsl:with-param name="V4Confirmed" select="$thisNode/@V4Confirmed.id"/>
        <xsl:with-param name="V4NotConfirmed" select="$thisNode/@V4NotConfirmed.id"/>
      </xsl:call-template>
    </xsl:variable>
    <xsl:variable name="ConfirmedCount" select="msxsl:node-set($cinfo)/confirm/counter/text()"/>
    <xsl:variable name="NotConfirmedCount" select="msxsl:node-set($cinfo)/notconfirm/counter/text()"/>
    <xsl:choose>
    <xsl:when test="$NotConfirmedCount = 0">
      <xsl:value-of select="$thisNode/../@resource.wss.GroupBoardCirculationStatusCompleted"/>
    </xsl:when>
    <xsl:when test="msxsl:string-compare(ddwrt:TodayIso(),$thisNode/@DueDate.ISO8601) >= 0">
      <strong><xsl:value-of select="$thisNode/../@resource.wss.GroupBoardCirculationStatusExpired"/></strong>
    </xsl:when>
    <xsl:otherwise>
      <xsl:value-of select="$ConfirmedCount"/>
      /
      <xsl:value-of select="$ConfirmedCount + $NotConfirmedCount"/>
    </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
  <!--
  Build confirmed/notConfirmed values
  -->
  <xsl:template name="GB_ExtractCirculationUsers">
    <xsl:param name="V4Confirmed"/>
    <xsl:param name="V4NotConfirmed"/>
    <xsl:element name="confirm">
      <xsl:choose>
        <xsl:when test="$V4Confirmed != ''">
          <xsl:call-template name="GB_ExtractUsersRecursive">
            <xsl:with-param name="userField" select="$V4Confirmed"/>
            <xsl:with-param name="extracted">;#</xsl:with-param>
            <xsl:with-param name="counter" select="0"/>
          </xsl:call-template>
        </xsl:when>
        <xsl:otherwise>
          <xsl:element name="counter">0</xsl:element>
          <xsl:element name="extracted">;#</xsl:element>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:element>
    <xsl:element name="notconfirm">
      <xsl:choose>
        <xsl:when test="$V4NotConfirmed != ''">
          <xsl:call-template name="GB_ExtractUsersRecursive">
            <xsl:with-param name="userField" select="$V4NotConfirmed"/>
            <xsl:with-param name="extracted">;#</xsl:with-param>
            <xsl:with-param name="counter" select="0"/>
          </xsl:call-template>
        </xsl:when>
        <xsl:otherwise>
          <xsl:element name="counter">0</xsl:element>
          <xsl:element name="extracted">;#</xsl:element>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:element>
  </xsl:template>
  <!-- Circulation ends here -->
  <!--
  Common user field manipulation template for Calltrack & Circulation
  It counts number of users, and generated string representation of
  multiple user field. (;#xx;#yy;#zz)
  -->
  <xsl:template name="GB_ExtractUsersRecursive">
    <xsl:param name="userField"/>
    <xsl:param name="extracted"/>
    <xsl:param name="counter"/>
    <xsl:variable name="afterDelimiter" select="substring-after($userField,';#')"/>
    <xsl:variable name="beforeDelimiter" select="substring-before($userField,';#')"/>
    <xsl:choose>
      <xsl:when test="$afterDelimiter and substring-after($afterDelimiter,';#')">
        <xsl:call-template name="GB_ExtractUsersRecursive">
          <xsl:with-param name="userField" select="substring-after($afterDelimiter,';#')"/>
          <xsl:with-param name="extracted" select="concat($extracted, $beforeDelimiter, ';#')"/>
          <xsl:with-param name="counter" select="$counter+1"/>
        </xsl:call-template>
      </xsl:when>
      <xsl:otherwise>
        <xsl:element name="counter">
          <xsl:value-of select="$counter+1"/>
        </xsl:element>
        <xsl:element name="extracted">
          <xsl:value-of select="concat($extracted, $beforeDelimiter, ';#')"/>
        </xsl:element>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
</xsl:stylesheet>
