<!--                                                                  -->
<!--  Copyright (C) 2009 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="http://www.w3.org/TR/html4/strict.dtd" doctype-public="-//W3C//DTD HTML 4.01//EN" encoding="utf-8" />

    <xsl:include href="/app/tools/bookpub/templates/global.xsl" />

    <xsl:variable name="dynamicList">
        <xsl:choose>
            <xsl:when test="/Root/Form/WatchList/Dynamic = 0">0</xsl:when>
            <xsl:when test="/Root/Form/WatchList/Dynamic = ''">0</xsl:when>
            <xsl:otherwise>1</xsl:otherwise>
        </xsl:choose>
    </xsl:variable>


    <xsl:template name="pickLayout">

        <link href="/production/css/bookpub/market.css?v=2" rel="stylesheet" type="text/css" />
        <script src="/production/javascript/jquery/jquery-3.6.0.min.js"></script>
        <script type="text/javascript" src="/production/javascript/bookpub/market.js?v=3"></script>
        <script type="text/javascript" src="/production/javascript/bookpub/validate/watchList.js?v=1"></script>

        <form method="post" action="/bookpub/market">
            <input type="hidden" name="c" value="edit" />
            <input type="hidden" name="formSubmit" value="1" />
            <xsl:if test="normalize-space(Form/WatchList/WatchListID)">
                <input type="hidden" name="Form_WatchList_WatchListID" value="{Form/WatchList/WatchListID}" />
            </xsl:if>
            <xsl:if test="normalize-space(Form/WatchList/GlobalID)">
                <input type="hidden" name="Form_WatchList_GlobalID" value="{Form/WatchList/GlobalID}" />
            </xsl:if>
            <div class="section" id="editList">
                <xsl:call-template name="editListForm" />
            </div>
            <div class="section">
                <xsl:call-template name="buttons" />
            </div>
        </form>
    </xsl:template>


    <xsl:template name="submitButton">
        <input name="submitButton" type="submit" id="submitButton">
            <xsl:attribute name="value">
                <xsl:if test="normalize-space(Form/WatchList/WatchListID)">Update</xsl:if>
                <xsl:if test="not(normalize-space(Form/WatchList/WatchListID))">Create</xsl:if>
            </xsl:attribute>
        </input>
    </xsl:template>


    <xsl:template name="cancelButton">
        <input type="button" value="Back to Market" onClick="location.href='/bookpub/market?WatchListID={Form/WatchList/WatchListID}'" />

        <xsl:variable name="canDelete">
            <xsl:choose>
                <xsl:when test="Form/WatchList/IsOwner = 1">1</xsl:when>
                <xsl:when test="User/AccessLevel = 1">1</xsl:when>
                <xsl:when test="User/AccessLevel = 2">1</xsl:when>
                <xsl:when test="User/AccessLevel = 3">1</xsl:when>
                <xsl:otherwise>0</xsl:otherwise>
            </xsl:choose>
        </xsl:variable>

        <xsl:if test="normalize-space(Form/WatchList/WatchListID) and $canDelete = 1">
            <input type="button" value="Delete" onClick="confirmDeleteList({Form/WatchList/WatchListID});" />
        </xsl:if>
    </xsl:template>


    <xsl:template name="editListForm">
        <table>
            <xsl:call-template name="nameRow" />
            <xsl:call-template name="descriptionRow" />
            <xsl:call-template name="publicRow" />
            <xsl:call-template name="dynamicRow" />
            <xsl:call-template name="dynamicCriteria" />
            <xsl:call-template name="ownerRow" />
        </table>

        <br /><br />

        <xsl:if test="normalize-space(Form/WatchList/ModifiedDate)">
            <div class="lastModified">
    		    <b>Last Modified:</b>&#160;<xsl:value-of select="Form/WatchList/ModifiedDate" /><xsl:if test="normalize-space(Form/WatchList/ModifiedBy)"> by <xsl:value-of select="Form/WatchList/ModifiedBy" /></xsl:if>
            </div>
        </xsl:if>

        <div class="requiredText">
            *Required field
        </div>

        <br />

    </xsl:template>


    <xsl:template name="nameRow">
		<tr>
			<td class="leftCol"><label for="Form_WatchList_Name">*List Name</label></td>
			<td>
				<xsl:call-template name="inlineError">
					<xsl:with-param name="path">Form/WatchList/Name</xsl:with-param>
					<xsl:with-param name="displayName">List Name</xsl:with-param>
				</xsl:call-template>
				<input type="text" class="nameField" name="Form_WatchList_Name" id="Form_WatchList_Name" value="{Form/WatchList/Name}" >
                </input>
			</td>
		</tr>
    </xsl:template>


    <xsl:template name="descriptionRow">
        <tr class="labelTop">
            <td class="leftCol">Description</td>
            <td>
                <textarea rows="6" cols="40" name="Form_WatchList_Description">
                    <xsl:value-of select="Form/WatchList/Description" />
                </textarea>
            </td>
        </tr>
    </xsl:template>


    <xsl:template name="publicRow">
		<tr class="checkboxRow">
			<td class="leftCol"><label for="Form_WatchList_Public">Public</label></td>
			<td>
				<input type="checkbox" name="Form_WatchList_Public" value="1">
                    <xsl:if test="Form/WatchList/Public = 1">
                        <xsl:attribute name="checked">checked</xsl:attribute>
                    </xsl:if>
                </input>
                By selecting this option, all users can view this list.
			</td>
		</tr>
    </xsl:template>


    <xsl:template name="dynamicRow">
		<tr class="checkboxRow">
			<td class="leftCol"><label for="Form_WatchList_Dynamic">Dynamic</label></td>
			<td>
				<input type="checkbox" name="Form_WatchList_Dynamic" value="1" onClick="dynamicList(this.checked)">
                    <xsl:if test="Form/WatchList/Dynamic = 1">
                        <xsl:attribute name="checked">checked</xsl:attribute>
                    </xsl:if>
                </input>
                I would like book products to be added to this Watch list automatically based on the following criteria:
			</td>
		</tr>
    </xsl:template>


    <xsl:template name="dynamicCriteria">
        <tr>
            <td></td>
            <td>
                <table id="criteriaList">
                    <xsl:call-template name="pubDateRow" />
                    <xsl:call-template name="productFormatRow" />
                    <xsl:call-template name="marketRankRow" />
                    <xsl:call-template name="authorRow" />
                    <xsl:call-template name="imprintRow" />
                    <xsl:call-template name="publisherRow" />
                    <xsl:call-template name="serviceRow" />
                    <xsl:call-template name="alertRow" />
                </table>
            </td>
        </tr>
    </xsl:template>


    <xsl:template name="pubDateRow">
		<tr>
			<td class="leftCol"><label for="Form_WatchList_PublicationDate">Publication Date</label></td>
			<td>
				<select name="Form_WatchList_PublicationDate" id="Form_WatchList_PublicationDate" class="dynamicField">
                    <xsl:if test="$dynamicList = 0">
                        <xsl:attribute name="disabled">true</xsl:attribute>
                    </xsl:if>

                    <xsl:variable name="selectedPubDate" select="Form/WatchList/PublicationDate" />

                    <xsl:call-template name="formOption">
                        <xsl:with-param name="value">7</xsl:with-param>
                        <xsl:with-param name="text">Last 7 days</xsl:with-param>
                        <xsl:with-param name="selected" select="$selectedPubDate" />
                    </xsl:call-template>

                    <xsl:call-template name="formOption">
                        <xsl:with-param name="value">30</xsl:with-param>
                        <xsl:with-param name="text">Last 30 days</xsl:with-param>
                        <xsl:with-param name="selected" select="$selectedPubDate" />
                    </xsl:call-template>

                    <xsl:call-template name="formOption">
                        <xsl:with-param name="value">90</xsl:with-param>
                        <xsl:with-param name="text">Last 90 days</xsl:with-param>
                        <xsl:with-param name="selected" select="$selectedPubDate" />
                    </xsl:call-template>

                    <xsl:call-template name="formOption">
                        <xsl:with-param name="value">180</xsl:with-param>
                        <xsl:with-param name="text">Last six months</xsl:with-param>
                        <xsl:with-param name="selected" select="$selectedPubDate" />
                    </xsl:call-template>

                    <xsl:call-template name="formOption">
                        <xsl:with-param name="value">365</xsl:with-param>
                        <xsl:with-param name="text">Last year</xsl:with-param>
                        <xsl:with-param name="selected" select="$selectedPubDate" />
                    </xsl:call-template>

                    <xsl:call-template name="formOption">
                        <xsl:with-param name="value">0</xsl:with-param>
                        <xsl:with-param name="text">Anytime</xsl:with-param>
                        <xsl:with-param name="selected" select="$selectedPubDate" />
                    </xsl:call-template>

                </select>
			</td>
		</tr>
    </xsl:template>


    <xsl:template name="productFormatRow">
		<tr>
			<td class="leftCol"><label for="Form_WatchList_Format">Book Product Format</label></td>
			<td style="vertical-align: top;">
			    <input type="hidden" name="Form_WatchList_Format" id="Form_WatchList_Format" value="1" />
			    All Digital
			    <!--
				<select name="Form_WatchList_Format" id="Form_WatchList_Format" class="dynamicField">
                    <xsl:if test="$dynamicList = 0">
                        <xsl:attribute name="disabled">true</xsl:attribute>
                    </xsl:if>

                    <xsl:variable name="selectedFormat" select="Form/WatchList/Format" />

                    <xsl:call-template name="formOption">
                        <xsl:with-param name="value">0</xsl:with-param>
                        <xsl:with-param name="text">All formats</xsl:with-param>
                        <xsl:with-param name="selected" select="$selectedFormat" />
                    </xsl:call-template>

                    <xsl:call-template name="formOption">
                        <xsl:with-param name="value">1</xsl:with-param>
                        <xsl:with-param name="text">All Digital</xsl:with-param>
                        <xsl:with-param name="selected" select="$selectedFormat" />
                    </xsl:call-template>

                    <xsl:call-template name="formOption">
                        <xsl:with-param name="value">2</xsl:with-param>
                        <xsl:with-param name="text">All Physical</xsl:with-param>
                        <xsl:with-param name="selected" select="$selectedFormat" />
                    </xsl:call-template>

                </select>
                -->
			</td>
		</tr>
    </xsl:template>


    <xsl:template name="marketRankRow">
		<tr>
			<td class="leftCol"><label for="Form_WatchList_Rank">Market Rank</label></td>
			<td>
				<select name="Form_WatchList_Rank" id="Form_WatchList_Rank" class="dynamicField">
                    <xsl:if test="$dynamicList = 0">
                        <xsl:attribute name="disabled">true</xsl:attribute>
                    </xsl:if>

                    <xsl:variable name="selectedRank" select="Form/WatchList/Rank" />

                    <xsl:call-template name="formOption">
                        <xsl:with-param name="value">10</xsl:with-param>
                        <xsl:with-param name="text">Top 10</xsl:with-param>
                        <xsl:with-param name="selected" select="$selectedRank" />
                    </xsl:call-template>

                    <xsl:call-template name="formOption">
                        <xsl:with-param name="value">20</xsl:with-param>
                        <xsl:with-param name="text">Top 20</xsl:with-param>
                        <xsl:with-param name="selected" select="$selectedRank" />
                    </xsl:call-template>

                    <xsl:call-template name="formOption">
                        <xsl:with-param name="value">50</xsl:with-param>
                        <xsl:with-param name="text">Top 50</xsl:with-param>
                        <xsl:with-param name="selected" select="$selectedRank" />
                    </xsl:call-template>

                    <xsl:call-template name="formOption">
                        <xsl:with-param name="value">100</xsl:with-param>
                        <xsl:with-param name="text">Top 100</xsl:with-param>
                        <xsl:with-param name="selected" select="$selectedRank" />
                    </xsl:call-template>

                    <xsl:call-template name="formOption">
                        <xsl:with-param name="value">0</xsl:with-param>
                        <xsl:with-param name="text">All rankings</xsl:with-param>
                        <xsl:with-param name="selected" select="$selectedRank" />
                    </xsl:call-template>

                </select>

                <label for="Form_WatchList_Market" style="margin-right: 2px"> for </label>
				<select name="Form_WatchList_Market" id="Form_WatchList_Market" class="dynamicField">
                    <xsl:if test="$dynamicList = 0">
                        <xsl:attribute name="disabled">true</xsl:attribute>
                    </xsl:if>

                    <xsl:variable name="selectedMarket" select="Form/WatchList/Market" />

                    <xsl:call-template name="formOption">
                        <xsl:with-param name="value">8</xsl:with-param>
                        <xsl:with-param name="text">Amazon</xsl:with-param>
                        <xsl:with-param name="selected" select="$selectedMarket" />
                    </xsl:call-template>

                    <!--
                    <xsl:call-template name="formOption">
                        <xsl:with-param name="value">9</xsl:with-param>
                        <xsl:with-param name="text">Apple</xsl:with-param>
                        <xsl:with-param name="selected" select="$selectedMarket" />
                    </xsl:call-template>
                    -->

                    <xsl:call-template name="formOption">
                        <xsl:with-param name="value">16</xsl:with-param>
                        <xsl:with-param name="text">Barnes &amp; Noble</xsl:with-param>
                        <xsl:with-param name="selected" select="$selectedMarket" />
                    </xsl:call-template>

                    <xsl:call-template name="formOption">
                        <xsl:with-param name="value">60</xsl:with-param>
                        <xsl:with-param name="text">New York Times Best Sellers</xsl:with-param>
                        <xsl:with-param name="selected" select="$selectedMarket" />
                    </xsl:call-template>

                    <xsl:call-template name="formOption">
                        <xsl:with-param name="value">0</xsl:with-param>
                        <xsl:with-param name="text">Available Market (Average)</xsl:with-param>
                        <xsl:with-param name="selected" select="$selectedMarket" />
                    </xsl:call-template>

                </select>
			</td>
		</tr>
    </xsl:template>


    <xsl:template name="authorRow">
		<tr>
			<td class="leftCol"><label for="Form_WatchList_Author">Author Last Name</label></td>
			<td>
				<input type="text" name="Form_WatchList_Author" id="Form_WatchList_Author" class="dynamicField" value="{Form/WatchList/Author}">
                    <xsl:if test="$dynamicList = 0">
                        <xsl:attribute name="disabled">true</xsl:attribute>
                    </xsl:if>
                </input>
			</td>
		</tr>
    </xsl:template>


    <xsl:template name="imprintRow">
		<tr>
			<td class="leftCol"><label for="Form_WatchList_ImprintID">Imprint</label></td>
			<td>
				<select name="Form_WatchList_ImprintID" id="Form_WatchList_ImprintID" class="dynamicField">
                    <xsl:if test="$dynamicList = 0">
                        <xsl:attribute name="disabled">true</xsl:attribute>
                    </xsl:if>

                    <option value="">Choose...</option>

                    <xsl:for-each select="ImprintList/Imprint">
                        <option value="{ImprintID}">
                            <xsl:if test="ImprintID = /Root/Form/WatchList/ImprintID">
                                <xsl:attribute name="selected">selected</xsl:attribute>
                            </xsl:if>
                            <xsl:value-of select="Name" />
                        </option>
                    </xsl:for-each>

                </select>
			</td>
		</tr>
    </xsl:template>


    <xsl:template name="publisherRow">
		<tr>
			<td class="leftCol"><label for="Form_WatchList_PublisherID">Publisher</label></td>
			<td>
				<select name="Form_WatchList_PublisherID" id="Form_WatchList_PublisherID" class="dynamicField">
                    <xsl:if test="$dynamicList = 0">
                        <xsl:attribute name="disabled">true</xsl:attribute>
                    </xsl:if>

                    <option value="">Choose...</option>

                    <xsl:for-each select="PublisherList/Publisher">
                        <option value="{PublisherID}">
                            <xsl:if test="PublisherID = /Root/Form/WatchList/PublisherID">
                                <xsl:attribute name="selected">selected</xsl:attribute>
                            </xsl:if>
                            <xsl:value-of select="Name" />
                        </option>
                    </xsl:for-each>

                </select>
			</td>
		</tr>
    </xsl:template>


    <xsl:template name="serviceRow">
		<tr>
			<td class="leftCol"><label for="Form_WatchList_ServiceID">Service</label></td>
			<td>
				<select name="Form_WatchList_ServiceID" id="Form_WatchList_ServiceID" class="dynamicField">
                    <xsl:if test="$dynamicList = 0">
                        <xsl:attribute name="disabled">true</xsl:attribute>
                    </xsl:if>

                    <option value="">Choose...</option>

                    <xsl:for-each select="ServiceList/Service">
                        <option value="{ServiceID}">
                            <xsl:if test="ServiceID = /Root/Form/WatchList/ServiceID">
                                <xsl:attribute name="selected">selected</xsl:attribute>
                            </xsl:if>
                            <xsl:value-of select="ServiceName" />
                        </option>
                    </xsl:for-each>

                </select>
			</td>
		</tr>
    </xsl:template>

    <xsl:template name="alertRow">
		<tr class="checkboxRow">
			<td class="leftCol"><label for="Form_WatchList_Alert">Alert</label></td>
			<td>
				<input type="checkbox" name="Form_WatchList_Alert" value="1" class="dynamicField">
                    <xsl:if test="$dynamicList = 0">
                        <xsl:attribute name="disabled">true</xsl:attribute>
                    </xsl:if>
                    <xsl:if test="Form/WatchList/Alert = 1">
                        <xsl:attribute name="checked">checked</xsl:attribute>
                    </xsl:if>
                </input>
                Only display products with active Alerts.
			</td>
		</tr>
    </xsl:template>


    <xsl:template name="ownerRow">
        <xsl:if test="normalize-space(Form/WatchList/WatchListID)">
    		<tr class="ownerRow">
    			<td class="leftCol">Owner</td>
    			<td>
                    <xsl:value-of select="Form/WatchList/CreatedBy" />
    			</td>
    		</tr>
		</xsl:if>
    </xsl:template>


    <xsl:template name="formOption">
        <xsl:param name="value" />
        <xsl:param name="text" />
        <xsl:param name="selected" />

	    <option value="{$value}">
	        <xsl:if test="$selected = $value">
	            <xsl:attribute name="selected">selected</xsl:attribute>
	        </xsl:if>
	        <xsl:value-of select="$text" />
	    </option>
    </xsl:template>


</xsl:stylesheet>
