<!--                                                                  -->
<!--  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="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/ajax_request.xsl" />
    <xsl:include href="/app/tools/bookpub/templates/messaging.xsl" />


    <xsl:template name="pickLayout">
        <div class="addItem" style="padding: 0 10px 5px 10px; font-size: 90%">
            <h1 style="margin-bottom: 2px">Simple Lists</h1>
            <span class="subtle">Add book products to any simple list.</span>

            <xsl:if test="WatchListList">
                <div class="watchLists" style="padding-top: 10px;">
                    <xsl:for-each select="WatchListList/WatchList[IsOwner = 1 or Public = 1]">

                        <xsl:if test="WatchListID = /Root/Params/WatchListID">
                            <xsl:if test="/Root/Messages/Message/Type = 'error'">
                                <p class="error">
                                    <xsl:if test="/Root/Messages/Message/Code = 'field_duplicate'">
                                        You have already added this product to this list.
                                    </xsl:if>
                                    <xsl:if test="/Root/Messages/Message/Code = 'field_blank'">
                                        All elgible products have already been added to this list.
                                    </xsl:if>
                                </p>
                            </xsl:if>

                            <xsl:if test="/Root/Messages/Message/Type = 'success'">
                                <p class="success">
                                    Added to <xsl:value-of select="Name" />
                                </p>
                            </xsl:if>
                        </xsl:if>

                        <xsl:choose>
                            <xsl:when test="/Root/Messages/Message/Type = 'success' and WatchListID = /Root/Params/WatchListID">
                                <xsl:call-template name="listLink" />
                            </xsl:when>
                            <xsl:otherwise>
                                <xsl:call-template name="addLink" />
                            </xsl:otherwise>
                        </xsl:choose>
                        <br /><br />
                    </xsl:for-each>
                </div>

                <hr />

            </xsl:if>

            <div class="watchLists" style="padding: 10px 0px">

                <script type="text/javascript">
                    $(document).ready(function() {
                        $("#simpleListForm<xsl:value-of select="Params/BookID" />").hide();
                        $("#simpleListFormShow<xsl:value-of select="Params/BookID" />").on('click', function()
                        {
                            $("#simpleListForm<xsl:value-of select="Params/BookID" />").slideToggle(500);
                        });
                    });
                </script>

                <a href="#" style="font-weight: bold;" id="simpleListFormShow{Params/BookID}">Create a New Simple List</a>

                <script type="text/javascript">
                    $(document).ready(function() {
                        $("#simpleListForm<xsl:value-of select="/Root/Params/BookID" />").on('submit', function()
                        {
                           var parentID = $(this).parent().parent().parent().attr("id");
                           var watchListName = document.getElementById('WatchListName<xsl:value-of select="/Root/Params/BookID" />').value;
                           displayInline('/bookpub/market?c=create_list&amp;WatchListName=' + watchListName + '&amp;ProductID=<xsl:value-of select="/Root/Params/ProductID" />&amp;BookID=<xsl:value-of select="/Root/Params/BookID" />',0,parentID);
                           return false;
                        });
                    });
                </script>

                <form method="post" action="#" id="simpleListForm{/Root/Params/BookID}" style="padding-top: 10px; text-align: center">
                    <span class="subtle">Enter a name for your new simple list.</span>
                    <br />
                    <input type="text" class="nameField" name="WatchListName{/Root/Params/BookID}" id="WatchListName{/Root/Params/BookID}" style="margin: 10px auto" />
                    <br />
                    <input type="submit" value="Create" />
                </form>

            </div>

        </div>
    </xsl:template>


    <xsl:template name="addLink">

        <script type="text/javascript">
            $(document).ready(function() {
                $("#addToList<xsl:value-of select="WatchListID" /><xsl:value-of select="/Root/Params/BookID" />").on('click', function()
                {
                   var parentID = $(this).parent().parent().parent().attr("id");
                   displayInline('/bookpub/market?c=add_item&amp;ProductID=<xsl:value-of select="/Root/Params/ProductID" />&amp;BookID=<xsl:value-of select="/Root/Params/BookID" />&amp;WatchListID=<xsl:value-of select="WatchListID" />',0,parentID)
                });
            });
        </script>

        <a href="javascript:void(0)" id="addToList{WatchListID}{/Root/Params/BookID}" style="font-weight: bold;">
            <xsl:value-of select="Name" />
        </a>
    </xsl:template>


    <xsl:template name="listLink">
        <span style="font-size: 90%; padding-left: 10px;">&gt; <a href="/bookpub/market?c=main&amp;WatchListID={WatchListID}" style="font-weight: bold;">
            Go to <xsl:value-of select="Name" />
        </a>
        </span>
    </xsl:template>


</xsl:stylesheet>
