<!--                                                                  -->
<!--  Copyright (C) 2006 RoyaltyShare, Inc.   All Rights Reserved     -->
<!--                                                                  -->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:dyn="http://exslt.org/dynamic" extension-element-prefixes="dyn">
    <xsl:output method="html" indent="no" doctype-system="" encoding="utf-8" />

    <xsl:include href="/app/tools/rps/templates/ajax_request.xsl" />
    <xsl:include href="/app/tools/common/production/templates/components/index.xsl" />

    <xsl:variable name="ccompTest"><xsl:if test="//IsControlledComp = 1">1</xsl:if></xsl:variable>
    <xsl:variable name="contractName">AlbumContractID</xsl:variable>
    <xsl:variable name="contractID"><xsl:value-of select="/Root/Params/AlbumContractID" /></xsl:variable>

    <xsl:template name="pickLayout">
        <xsl:call-template name="catalogViewLayout" />
    </xsl:template>

    <xsl:template name="catalogViewLayout">
        <xsl:call-template name="trackList" />
        <xsl:call-template name="productView" />
    </xsl:template>

    <xsl:template name="trackList">
        <div class="Album-tab-table">
            <div class="ControlsHeader">
                <h3 class="ControlsHeader-text">Tracks</h3>
                <div>
                    <xsl:call-template name="addTrackButton" />
                </div>
            </div>
            <table class="Table" id="trackTable">
                <xsl:if test="Form/Album/TrackList/Track">
                    <thead>
                        <tr class="Table-row Table-row-header">
                            <th class="Table-col Table-col-icon">Detail</th>
                            <th class="Table-col" id="trackCol">Track</th>
                            <th class="Table-col" id="nameCol">Name</th>
                            <th class="Table-col"></th>
                            <th class="Table-col" id="lengthCol">Length</th>
                            <th class="Table-col" id="artistCol">Artist</th>
                            <th class="Table-col">Parental Advisory</th>
                            <th class="Table-col">Media Type</th>
                            <xsl:if test="Access/rps/track/edit">
                                <th class="Table-col Table-col-icon" id="trackEdit">Edit</th>
                            </xsl:if>
                        </tr>
                    </thead>
                    <tbody>
                        <xsl:for-each select="Form/Album/TrackList/Track">
                            <xsl:call-template name="trackListRow" />
                        </xsl:for-each>
                    </tbody>
                </xsl:if>
            </table>
            <xsl:variable name="pagination" select="/Root/Form/Album/TrackList/Pagination" />
            <xsl:if test="$pagination/TotalPages > 1">
                <div class="Table-controls Table-controls-bottom">
                    <div class="Table-controls-item Table-controls-item-pagination">
                        <xsl:call-template name="uiPagination">
                            <xsl:with-param name="lastPage" select="$pagination/TotalPages"/>
                            <xsl:with-param name="currentPage" select="$pagination/Current"/>
                            <xsl:with-param name="searchPreffix" select="'c=show&amp;'"/>
                            <xsl:with-param name="searchParams">
                                <xsl:text>&amp;AlbumID=</xsl:text>
                                <xsl:value-of select="/Root/Form/Album/AlbumID" />
                            </xsl:with-param>
                        </xsl:call-template>
                    </div>
                </div>
            </xsl:if>

        </div>
    </xsl:template>

    <xsl:template name="addTrackButton">
        <div class="ButtonsGroup">
            <xsl:call-template name="uiButton">
                <xsl:with-param name="content" select="'Edit Tracks'" />
                <xsl:with-param name="url">
                    <xsl:text>catalog?AlbumID=</xsl:text>
                    <xsl:value-of select="Form/Album/AlbumID" />
                    <xsl:text>&amp;c=da_edit</xsl:text>
                </xsl:with-param>
            </xsl:call-template>

            <xsl:call-template name="uiButton">
                <xsl:with-param name="content" select="'Add Tracks'" />
                <xsl:with-param name="url">
                    <xsl:text>track?AlbumID=</xsl:text>
                    <xsl:value-of select="Form/Album/AlbumID" />
                    <xsl:text>&amp;c=edit</xsl:text>
                </xsl:with-param>
            </xsl:call-template>
        </div>
    </xsl:template>


    <xsl:template name="trackListRow">

        <xsl:variable name="trackRowID">trackSummary_<xsl:value-of select="TrackID" /></xsl:variable>
        <tr id="{$trackRowID}">
            <xsl:call-template name="uiEvenOddTrClass">
                <xsl:with-param name="position" select="position()" />
            </xsl:call-template>
            <td class="Table-col Table-col-icon">
                <a href="javascript:void(0);" class="CollapseTrigger" onClick="showTrackDetails(this,'{TrackID}');" id="toggle_{TrackID}">
                    <span class="CollapseTrigger-icon">
                        <xsl:call-template name="icon">
                            <xsl:with-param name="type" select="'arrow-down'" />
                            <xsl:with-param name="role" select="'action'" />
                            <xsl:with-param name="className" select="'CollapseTrigger-glyph'" />
                        </xsl:call-template>
                    </span>
                </a>
            </td>
            <td class="Table-col">
                <span id="{$trackRowID}_TrackOrderDisplay">
                    <xsl:if test="TrackOrder &lt; 10">0</xsl:if><xsl:value-of select="TrackOrder" />
                </span>
            </td>
            <td class="Table-col">
                <a href="track?c=show&amp;TrackID={TrackID}"><xsl:value-of select="Title" /></a>&#160;
                <xsl:if test="/Root/Access/app/reports/k">
                    <xsl:variable name="trackID" select="TrackID" />
                    <xsl:for-each select="/Root/Form/TrackProductList/TrackProduct[AssetID = $trackID]">
                        <xsl:variable name="parentProductID" select="ParentProductID" />
                        <xsl:variable name="upc">
                            <xsl:choose>
                                <xsl:when test="normalize-space($parentProductID)">
                                    <xsl:value-of select="/Root/Form/ProductList/Product[ProductID = $parentProductID]/UPC" />
                                </xsl:when>
                                <xsl:otherwise>
                                    <xsl:value-of select="UPC" />
                                </xsl:otherwise>
                            </xsl:choose>
                        </xsl:variable>
                        <a href="/app/reports?c=k&amp;product={ProductID}" title="Sales Analytics for &quot;{$upc}&quot;" class="js-tooltip" id="analytics_{$trackID}">
                            <xsl:call-template name="icon">
                                <xsl:with-param name="type" select="'sales-analytics'" />
                            </xsl:call-template>
                        </a>
                    </xsl:for-each>
                </xsl:if>
            </td>

            <td class="Table-col Table-col-icon">
                <xsl:if test="normalize-space(AudioPreviewURL) and /Root/Access/rps/catalog/download_mp3">
                    <a href="{AudioPreviewURL}" title="Download MP3" id="preview_{TrackID}" class="js-tooltip">
                        <xsl:call-template name="icon">
                            <xsl:with-param name="type" select="'download'" />
                            <xsl:with-param name="role" select="'action'" />
                        </xsl:call-template>
                    </a>
                </xsl:if>
            </td>

            <td class="Table-col"><xsl:value-of select="Master/Duration" /></td>

            <td class="Table-col">
                <xsl:value-of select="ArtistName" />
                <xsl:if test="count(AdditionalArtistList/AdditionalArtist) != 0">
                    &#160;<a class="js-tooltip" id="artists_{TrackID}">
                        <xsl:attribute name="title">
                            <xsl:for-each select="AdditionalArtistList/AdditionalArtist">
                                <xsl:sort select="AdditionalArtistID" data-type="number" />
                                <xsl:call-template name="escapeJavascript">
                                    <xsl:with-param name="string" select="Name" />
                                </xsl:call-template> (<xsl:value-of select="Role/Role" />)<xsl:value-of select="$tipBreak" />
                            </xsl:for-each>
                        </xsl:attribute>
                        <xsl:call-template name="icon">
                            <xsl:with-param name="type" select="'more'" />
                        </xsl:call-template>
                    </a>
                </xsl:if>
            </td>

            <td class="Table-col">
                <xsl:call-template name="albumParentalAdvisory">
                    <xsl:with-param name="advisory" select="ParentalAdvisory" />
                </xsl:call-template>
            </td>

            <td class="Table-col">
                <xsl:choose>
                    <xsl:when test="MediaType = 2">Video</xsl:when>
                    <xsl:otherwise>Audio</xsl:otherwise>
                </xsl:choose>
            </td>

            <xsl:if test="/Root/Access/rps/track/edit">
                <td class="Table-col Table-col-data Table-col-icon">
                    <a href="/rps/track?c=edit&amp;TrackID={TrackID}" title="Edit" class="js-tooltip">
                        <xsl:call-template name="icon">
                            <xsl:with-param name="type" select="'edit'" />
                            <xsl:with-param name="role" select="'action'" />
                        </xsl:call-template>
                    </a>
                </td>
            </xsl:if>
        </tr>

        <xsl:if test="count(AdditionalArtistList/AdditionalArtist) > 0">
            <tr class="Table-row Table-row-data Table-row-sub" id="trackArtists_{TrackID}" style="display:none">
                <xsl:call-template name="uiEvenOddTrClass">
                    <xsl:with-param name="position" select="position()" />
                </xsl:call-template>
                <td class="Table-col" colspan="5" />
                <td class="Table-col" colspan="3">
                    <xsl:if test="/Root/Access/rps/track/edit">
                        <xsl:attribute name="colspan">4</xsl:attribute>
                    </xsl:if>
                    <xsl:for-each select="AdditionalArtistList/AdditionalArtist">
                        <xsl:sort select="AdditionalArtistID" />
                        <xsl:value-of select="Name" /> (<xsl:value-of select="Role/Role" />)
                    </xsl:for-each>
                </td>
            </tr>
        </xsl:if>

        <tr class="trackInfo Table-row Table-row-sub" id="trackDetails_{TrackID}" style="display:none">

            <xsl:call-template name="uiEvenOddTrClass">
                <xsl:with-param name="position" select="position()" />
            </xsl:call-template>

            <td class="Table-col" colspan="7">
                <xsl:if test="/Root/Access/rps/track/edit">
                    <xsl:attribute name="colspan">9</xsl:attribute>
                </xsl:if>
                <div class="Album-track-details">
                    <div class="ValuePair ValuePair-horizontal Album-track-details-info">
                        <div class="ValuePair-item Album-track-details-item">
                            <div class="ValuePair-label">Track</div>
                            <ul class="ValuePair-values-list">
                                <li class="ValuePair-values-item">Client Track ID: <xsl:value-of select="ClientTrackID" /></li>
                                <li class="ValuePair-values-item">
                                    <xsl:choose>
                                        <xsl:when test="/Root/Client/ClientID = 338">DTI:</xsl:when>
                                        <xsl:otherwise>Custom 1:</xsl:otherwise>
                                    </xsl:choose>
                                    <xsl:value-of select="Custom1" />
                                </li>
                                <li class="ValuePair-values-item">Custom 2: <xsl:value-of select="Custom2" /></li>
                                <li class="ValuePair-values-item">Custom 3: <xsl:value-of select="Custom3" /></li>
                            </ul>
                        </div>
                        <div class="ValuePair-item Album-track-details-item">
                            <div class="ValuePair-label">Master</div>
                            <ul class="ValuePair-values-list">
                                <li class="ValuePair-values-item">Title: <xsl:value-of select="Master/Title" /></li>
                                <li class="ValuePair-values-item">Artist: <xsl:value-of select="Master/ArtistName" /></li>
                                <li class="ValuePair-values-item">ISRC: <xsl:value-of select="Master/ISRC" /></li>
                                <li class="ValuePair-values-item">Recording Date: <xsl:value-of select="Master/DateRecorded" /></li>
                            </ul>
                        </div>
                        <div class="ValuePair-item Album-track-details-item">
                            <div class="ValuePair-label">Song</div>
                            <ul class="ValuePair-values-list">
                                <li class="ValuePair-values-item">Title: <xsl:value-of select="Master/Song/Title" /></li>
                                <li class="ValuePair-values-item">Composer: <xsl:value-of select="Master/Song/ComposerName" /></li>
                                <li class="ValuePair-values-item">ISWC: <xsl:value-of select="Master/Song/ISWC" /></li>
                            </ul>
                        </div>
                    </div>
                </div>
            </td>
        </tr>
    </xsl:template>

    <xsl:template name="productView">
        <div class="Album-tab-table" id="productViewTable">

            <div class="ControlsHeader">
                <h3 class="ControlsHeader-text">Products</h3>
                <div>
                    <xsl:if test="ClientTypes/ClientType[ClientTypeID = 2]/IsClientTypeFlag = 1 or ClientTypes/ClientType[ClientTypeID = 5]/IsClientTypeFlag = 1 or ClientTypes/ClientType[ClientTypeID = 6]/IsClientTypeFlag = 1">

                        <xsl:call-template name="uiButton">
                            <xsl:with-param name="content" select="'Add Product'" />
                            <xsl:with-param name="id" select="'addProductButton'" />
                            <xsl:with-param name="disabled">
                                <xsl:if test="not(Form/Album/TrackList/Track/TrackID)">
                                    <xsl:text>true</xsl:text>
                                </xsl:if>
                            </xsl:with-param>
                            <xsl:with-param name="url">
                                <xsl:text>product?c=edit&amp;AlbumID=</xsl:text>
                                <xsl:value-of select="Form/Album/AlbumID" />
                            </xsl:with-param>
                        </xsl:call-template>

                    </xsl:if>
                </div>
            </div>
            <table class="Table">

                <xsl:if test="Form/ProductList/Product">
                    <thead>
                        <tr class="Table-row Table-row-header">
                            <th class="Table-col" id="productType">Type</th>
                            <th class="Table-col" id="productTitle">Product Title</th>
                            <th class="Table-col" id="productID">Product ID</th>
                            <th class="Table-col" id="productUPC">UPC</th>
                            <th class="Table-col" id="productDate">Release Date</th>
                            <th class="Table-col" id="productStatus">Status</th>
                            <th class="Table-col Table-col-icon">Edit</th>
                        </tr>
                    </thead>
                    <tbody>
                        <xsl:for-each select="Form/ProductList/Product[ProductTypeID = 3]">
                            <xsl:call-template name="productRow" />
                        </xsl:for-each>
                        <xsl:for-each select="Form/ProductList/Product[ProductTypeID != 3]">
                            <xsl:call-template name="productRow">
                                <xsl:with-param name="daCount" select="count(/Root/Form/ProductList/Product[ProductTypeID = 3])" />
                            </xsl:call-template>
                        </xsl:for-each>
                    </tbody>
                </xsl:if>

            </table>
        </div>
    </xsl:template>

    <xsl:template name="productRow">
        <xsl:param name="daCount" select="'0'" />
        <tr class="Table-row Table-row-data">
            <td class="Table-col">
                <xsl:variable name="productTypeID" select="ProductTypeID" />

                <xsl:value-of select="/Root/Form/TypeList/Type[ProductTypeID = $productTypeID]/Description" />
                <xsl:if test="/Root/Access/app/reports/a and $productTypeID = 3">
                    &#160;<a class="js-tooltip" href="/app/reports?c=a&amp;product={ProductID}" title="Sales Analytics for &quot;{UPC}&quot;" id="analytics_{ProductID}">
                        <xsl:call-template name="icon">
                            <xsl:with-param name="type" select="'sales-analytics'" />
                        </xsl:call-template>
                    </a>
                    <script type="text/javascript">
                        addSweetTitle('analytics_<xsl:value-of select="ProductID" />');
                    </script>
                </xsl:if>
            </td>
            <td class="Table-col"><a href="/rps/product?c=show&amp;ProductID={ProductID}"><xsl:value-of select="Title" /></a></td>
            <td class="Table-col"><xsl:value-of select="ProductCode" /></td>
            <td class="Table-col"><xsl:value-of select="UPC" /></td>
            <td class="Table-col"><xsl:value-of select="ReleaseDate" /></td>
            <td class="Table-col">
                <xsl:variable name="productStatusID" select="ProductStatusID" />
                <xsl:value-of select="/Root/Form/StatusList/Status[ProductStatusID = $productStatusID]/Description" />
            </td>
            <td class="Table-col Table-col-icon">
                <a class="js-tooltip" title="Edit" href="/rps/product?c=edit&amp;ProductID={ProductID}">
                    <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>
    </xsl:template>

</xsl:stylesheet>
