<!--                                                                  -->
<!--  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">
        <form action="/rps/label" method="get" class="Form Form-horizontal Form-horizontal-padded">
			<div class="Form-item">
				<label class="Form-label">
					<span class="Form-label-caption">Now Viewing</span>
					<div class="Form-input-wrapper">
						<xsl:variable name="itemList">
							<map>
								<mapEntry><name>All Labels</name><value>0</value></mapEntry>
								<mapEntry><name>Labels With Users</name><value>1</value></mapEntry>
								<mapEntry><name>Labels Without Users</name><value>2</value></mapEntry>
							</map>
						</xsl:variable>
						<xsl:call-template name="uiDropdown">
							<xsl:with-param name="items" select="$itemList"/>
							<xsl:with-param name="name" select="'filterBy'"/>
							<xsl:with-param name="className" select="'Dropdown-filterby'"/>
							<xsl:with-param name="active" select="/Root/Params/filterBy"/>
						</xsl:call-template>
					</div>
				</label>
			</div>
			<div class="Form-item">
				<xsl:call-template name="uiButton">
					<xsl:with-param name="content" select="'Update'" />
					<xsl:with-param name="type" select="'default'"/>
					<xsl:with-param name="className" select="'Form-button'"/>
					<xsl:with-param name="elemType" select="'submit'"/>
				</xsl:call-template>
			</div>
        </form>
  	</xsl:template>

    <xsl:template name="searchResults">
        <script type="text/javascript" src="/production/javascript/labelList.js?v=1"></script>
        <div 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="Table">
                            <thead>
                                <tr class="Table-row Table-row-header">
                                    <th class="Table-col Table-label-list-name">Name</th>
                                    <th class="Table-col">Client Label #</th>
                                    <th class="Table-col">Label Users</th>
                                    <th class="Table-col">Default</th>
                                    <th class="Table-col">Actions</th>
                                    <th class="Table-col Table-col-icon">Edit</th>
                                </tr>
                            </thead>
                            <tbody>
                                <xsl:for-each select="Label">
                                    <tr class="Table-row Table-row-data">
                                        <xsl:call-template name="uiEvenOddTrClass">
                                            <xsl:with-param name="position" select="position()"/>
                                        </xsl:call-template>

                                        <td class="Table-col">
                                            <a href="label?LabelID={LabelID}&amp;c=show"><xsl:value-of select="LabelName" /></a>
                                        </td>
                                        <td class="Table-col">
                                            <xsl:value-of select="ClientLabelID" />
                                        </td>
                                        <td class="Table-col">
                                            (<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="Table-col">
                                            <xsl:if test="IsDefault = 1">
                                                <xsl:call-template name="icon">
                                                    <xsl:with-param name="type" select="'complete'" />
                                                    <xsl:with-param name="size" select="'medium'" />
                                                    <xsl:with-param name="className" select="'List-default'" />
                                                </xsl:call-template>
                                            </xsl:if>
                                        </td>
                                        <td class="Table-col">
                                            <xsl:if test="IsDefault = 0"><a href="?c=set_default&amp;LabelID={LabelID}">Set as Default</a></xsl:if>
                                        </td>
    									<td class="Table-col Table-col-icon">
                                            <a href="label?c=edit&amp;LabelID={LabelID}">
    											<xsl:call-template name="icon">
    												<xsl:with-param name="type" select="'edit'" />
    												<xsl:with-param name="role" select="'action'" />
    											</xsl:call-template>
    										</a>
    									</td>
                                    </tr>
                                    <tr class="Table-row Table-row-data" id="labelUser_{LabelID}" style="display:none">
                                        <xsl:call-template name="uiEvenOddTrClass">
                                            <xsl:with-param name="position" select="position()"/>
                                        </xsl:call-template>
                                        <td class="Table-col" />
                                        <td class="Table-col" />
                                        <td class="Table-col">
    										<xsl:variable name="userID" select="UserID" />
    										<xsl:for-each select="/Root/UserList/User[UserID = $userID]">
    										<!-- <xsl:for-each select="Users/User"> -->
    											<p><xsl:value-of select="LastName" />, <xsl:value-of select="FirstName" /></p>
    										</xsl:for-each>
                                        </td>
                                        <td class="Table-col" />
                                        <td class="Table-col" />
                                        <td class="Table-col" />
                                    </tr>
                                </xsl:for-each>
                            </tbody>
                        </table>
                    </xsl:if>

                    <xsl:call-template name="searchNav" />

                </xsl:otherwise>
            </xsl:choose>
        </div>
    </xsl:template>

</xsl:stylesheet>
