<!--                                                                  -->
<!--  Copyright (C) 2006 RoyaltyShare, Inc.   All Rights Reserved     -->
<!--  $Id$  -->
<!--                                                                  -->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

  <xsl:template name="labelListLayout">
    <xsl:call-template name="searchResults" />
    <xsl:call-template name="buttons" />
  </xsl:template>

  <xsl:template name="filterForm">
    <div class="statementFilter">
        <form action="/rps/label" method="get">
            Now Viewing:
            <select name="filterBy">
                <option value="0">
                    <xsl:if test="/Root/Params/filterBy = 0">
                        <xsl:attribute name="selected">selected</xsl:attribute>
                    </xsl:if>
                    All Labels
                </option>
                <option value="1">
                    <xsl:if test="/Root/Params/filterBy = 1">
                        <xsl:attribute name="selected">selected</xsl:attribute>
                    </xsl:if>
                    Labels With Users
                </option>
                <option value="2">
                    <xsl:if test="/Root/Params/filterBy = 2">
                        <xsl:attribute name="selected">selected</xsl:attribute>
                    </xsl:if>
                    Labels Without Users
                </option>
            </select>&#160;<input type="submit" value="Update" />
        </form>
    </div>
    <br />
    <br />
  </xsl:template>

    <xsl:template name="searchResults">

        <script type="text/javascript" src="/production/javascript/labelList.js?v=1"></script>

        <div class="section" id="labelList">
            <xsl:call-template name="filterForm" />
            <xsl:choose>
                <xsl:when test="not(Params/Query) and count(Label) = 0">
                    <xsl:choose>
                        <xsl:when test="Params/filterBy">
                            <p>No labels match the current filter.</p>
                        </xsl:when>
                        <xsl:otherwise>
                            <p>No labels have been created.</p>
                        </xsl:otherwise>
                    </xsl:choose>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:if test="Params/Query">
                        <h2>Search Results</h2>
                    </xsl:if>
                    <xsl:call-template name="searchNav" />
  		            <xsl:call-template name="searchText" />
                    <xsl:if test="count(Label) != 0">
                        <table class="textChart hiOn" id="resultsHeader">
                            <tr>
                                <th class="rowLeft">Name</th>
                                <th>Client Label #</th>
                                <th>Label Users</th>
                                <th class="defaultCol">Default</th>
                                <th class="actionsCol">Actions</th>
                            </tr>
                            <xsl:for-each select="Label">
                                <tr class="row{position() mod 2}">
                                    <td class="rowLeft">
                                        <a href="label?LabelID={LabelID}&amp;c=show"><xsl:value-of select="LabelName" /></a>
                                    </td>
                                    <td>
                                        <xsl:value-of select="ClientLabelID" />
                                    </td>
                                    <td style="width: 150px">
                                        (<xsl:value-of select="UserCount" />)
                                        <xsl:if test="UserCount > 0">
                                            &#160;
                                            <a href="javascript:void(0);" onClick="showLabelUsers(this,'{LabelID}');" id="toggle_{LabelID}">Show Users</a>
                                        </xsl:if>
                                    </td>
                                    <td class="icon">
                                        <xsl:if test="IsDefault = 1"><img src="/production/images/icons/office/Checkmark-(16x16).png" height="16" width="16" /></xsl:if>
                                    </td>
                                    <td>
                                        <a href="label?c=edit&amp;LabelID={LabelID}">Edit</a>
                                        <xsl:if test="IsDefault = 0">, <a href="?c=set_default&amp;LabelID={LabelID}">Set as Default</a></xsl:if>
                                    </td>
                                </tr>
                                <tr class="labelUser row{position() mod 2}" id="labelUser_{LabelID}" style="display:none">
                                    <td />
                                    <td />
                                    <td class="subTable">
                                        <table class="textChart">
                                            <xsl:variable name="userID" select="UserID" />	
                                            <xsl:for-each select="/Root/UserList/User[UserID = $userID]">
<!--                                            <xsl:for-each select="Users/User"> -->
                                                <tr><td class="rowLeft"><xsl:value-of select="LastName" />, <xsl:value-of select="FirstName" /></td></tr>
                                            </xsl:for-each>
                                        </table>
                                    </td>
                                    <td />
                                    <td />
                                </tr>
                            </xsl:for-each>
                        </table>
                    </xsl:if>
                    <xsl:call-template name="searchNav" />
	  	            <br class="superBreak" />
                </xsl:otherwise>
            </xsl:choose>
        </div>
    </xsl:template>

</xsl:stylesheet>

