﻿<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">

	<xsl:import href="RecurringTemplate.xslt"/>
	<xsl:output method="xml" indent="yes"/>

	<xsl:template match="/">
		<xsl:call-template name="AddTemplateAction">
			<xsl:with-param name="TemplatePathURL" select="AjaxRequest/TemplateURL"></xsl:with-param>
			<xsl:with-param name="TopicID" select="AjaxRequest/Params/TopicID"></xsl:with-param>
			<xsl:with-param name="TemplateID" select="AjaxRequest/Params/TemplateID"></xsl:with-param>
			<xsl:with-param name="TopicName" select="AjaxRequest/Params/TopicName"></xsl:with-param>
			<xsl:with-param name="BrandID" select="AjaxRequest/Params/BrandID"></xsl:with-param>
			<xsl:with-param name="Mode" select="AjaxRequest/Params/Mode"></xsl:with-param>
			<xsl:with-param name="TemplateRoles" select="AjaxRequest/Roles/."></xsl:with-param>
		</xsl:call-template>
	</xsl:template>


	<xsl:template name="AddTemplateAction">
		<xsl:param name="TemplatePathURL" select="'N/A'"></xsl:param>
		<xsl:param name="TopicID" select="'N/A'"></xsl:param>
		<xsl:param name="TemplateID" select="'N/A'"></xsl:param>
		<xsl:param name="TopicName" select="'N/A'"></xsl:param>
		<xsl:param name="BrandID" select="'N/A'"></xsl:param>
		<xsl:param name="TemplateRoles" select="'N/A'"></xsl:param>
		<xsl:param name="Mode" select="'N/A'"></xsl:param>
		<xsl:param name="ActionName"></xsl:param>
		<xsl:param name="StartDate"></xsl:param>
		<xsl:param name="DueDate"></xsl:param>
		<xsl:param name="Role"></xsl:param>
		<xsl:param name="Description"></xsl:param>
		<xsl:param name="DaysPrior">
			<xsl:text>99</xsl:text>
		</xsl:param>
		<xsl:param name="PageOrigin"></xsl:param>
		<xsl:param name="Sort">
			<xsl:text></xsl:text>
		</xsl:param>
		<xsl:param name="varItemTemplateDetailID" select="'N/A'"></xsl:param>
		<xsl:param name="RecurringPeriodType" select="'N/A'"></xsl:param>
		<xsl:param name="RepeatEveryN" select="'N/A'"></xsl:param>
		<xsl:param name="EndAfterN" select="'N/A'"></xsl:param>
		<xsl:param name="FirstOfMonthYN" select="'N/A'"></xsl:param>
		<xsl:param name="LastOfMonthYN" select="'N/A'"></xsl:param>
		<xsl:param name="MiddleOfMonthYN" select="'N/A'"></xsl:param>
		<xsl:param name="OnDaysBitmask" select="'N/A'"></xsl:param>

		<xsl:param name="Monday" select="'N/A'"></xsl:param>
		<xsl:param name="Tuesday" select="'N/A'"></xsl:param>
		<xsl:param name="Wednesday" select="'N/A'"></xsl:param>
		<xsl:param name="Thursday" select="'N/A'"></xsl:param>
		<xsl:param name="Friday" select="'N/A'"></xsl:param>
		<xsl:param name="Saturday" select="'N/A'"></xsl:param>
		<xsl:param name="Sunday" select="'N/A'"></xsl:param>
		<xsl:variable name="ItemTemplateDetailID">
			<xsl:choose>
				<xsl:when test="$varItemTemplateDetailID='N/A'">
					<xsl:text>0</xsl:text>
				</xsl:when>
				<xsl:otherwise>
					<xsl:value-of select="$varItemTemplateDetailID"/>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:variable>
		<xsl:variable   name="clsRecurringDetail">
			<xsl:choose>
				<xsl:when test="$ItemTemplateDetailID &gt;0">
					<xsl:text>display:table-row;</xsl:text>
				</xsl:when>
				<xsl:otherwise>
					<xsl:text>display:none;</xsl:text>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:variable>

		<xsl:variable name="clsMontlyRecurringVisibleStyle">
			<xsl:choose>
				<xsl:when test="$RecurringPeriodType='Monthly' and $ItemTemplateDetailID &gt;0">
					<xsl:text>display:table-row</xsl:text>
				</xsl:when>
				<xsl:otherwise>
					<xsl:text>display:none</xsl:text>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:variable>
		<xsl:variable name="clsWeeklyRecurringVisibleStyle">
			<xsl:choose>
				<xsl:when test="$RecurringPeriodType !='Monthly' and $ItemTemplateDetailID &gt;0">
					<xsl:text>display:table-row</xsl:text>
				</xsl:when>
				<xsl:otherwise>
					<xsl:text>display:none</xsl:text>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:variable>
		<table class="tableMaster">
			<tr>
				<td width="20%">
					<span class="publicationSummary">Action</span>
				</td>
				<td>
					<input id="txt_{$TopicID}_Action" type="text" value="{$ActionName}" class="text" tabindex="1"></input>
				</td>
			</tr>
			<tr style="display:none;">
				<td style="width:90px;">
					<span class="publicationSummary">
						Start Date
					</span>
				</td>
				<td>
					<input id="txt_{$TopicID}_StartDate" type="text"
                                 class="text" style="width:50px;"  tabindex="2" value="{$DueDate}"/>
				</td>
			</tr>
			<tr>
				<td style="width:90px;">
					<span class="publicationSummary">
						Due on Day #
					</span>
				</td>
				<td>
					<input id="txt_{$TopicID}_DueDate" type="text"
                              style="width:50px;" class="text" value="{$DueDate}" tabindex="3"/>
					<span class="labelGraySize10">(# of days from Start Date - 0, 1, 7 or -7, etc...) </span>
				</td>
			</tr>
		
			<xsl:call-template name="AddRecurringTemplate">
				<xsl:with-param name="varItemTemplateDetailID" select="$ItemTemplateDetailID"></xsl:with-param>
				<xsl:with-param name="TopicID" select="$TopicID"></xsl:with-param>
				<xsl:with-param name="RecurringPeriodType" select="$RecurringPeriodType"></xsl:with-param>
				<xsl:with-param name="clsRecurringDetail" select="$clsRecurringDetail"></xsl:with-param>
				<xsl:with-param name="clsWeeklyRecurringVisibleStyle" select="$clsWeeklyRecurringVisibleStyle"></xsl:with-param>
				<xsl:with-param name="RepeatEveryN" select="$RepeatEveryN"></xsl:with-param>
				<xsl:with-param name="EndAfterN" select="$EndAfterN"></xsl:with-param>
				<xsl:with-param name="Monday" select="$Monday"></xsl:with-param>
				<xsl:with-param name="Tuesday" select="$Tuesday"></xsl:with-param>
				<xsl:with-param name="Wednesday" select="$Wednesday"></xsl:with-param>
				<xsl:with-param name="Thursday" select="$Thursday"></xsl:with-param>
				<xsl:with-param name="Friday" select="$Friday"></xsl:with-param>
				<xsl:with-param name="Saturday" select="$Saturday"></xsl:with-param>
				<xsl:with-param name="Sunday" select="$Sunday"></xsl:with-param>
				<xsl:with-param name="clsMontlyRecurringVisibleStyle" select="$clsMontlyRecurringVisibleStyle"></xsl:with-param>
				<xsl:with-param name="FirstOfMonthYN" select="$FirstOfMonthYN"></xsl:with-param>
				<xsl:with-param name="MiddleOfMonthYN" select="$MiddleOfMonthYN"></xsl:with-param>
				<xsl:with-param name="LastOfMonthYN" select="$LastOfMonthYN"></xsl:with-param>
			</xsl:call-template>
			<tr>
				<td>
					<span class="publicationSummary">Responsible</span>
				</td>
				<td>
					<select id="ddl_{$TopicID}_Add_Roles" class="smallDropdown" tabindex="4">
						<xsl:for-each select="$TemplateRoles/Role">
							<xsl:variable name="RoleName" select="RoleName"></xsl:variable>
							<xsl:variable name="uniqueKey" select="uniqueKey"></xsl:variable>

							<xsl:choose>
								<xsl:when test="$uniqueKey = $Role">
									<option value="{uniqueKey}" selected="selected">
										<xsl:value-of select="$RoleName"/>
									</option>
								</xsl:when>
								<xsl:otherwise>
									<option value="{uniqueKey}">
										<xsl:value-of select="$RoleName"/>
									</option>
								</xsl:otherwise>
							</xsl:choose>
						</xsl:for-each>
					</select>
				</td>
			</tr>
			<tr>
				<td>
					<span class="publicationSummary">Days Prior</span>
				</td>
				<td>
					<input id="txt_{$TopicID}_DaysPrior" type="text" class="text" style="width:50px;"
                           value="{$DaysPrior}" tabindex="5"></input>
					<span class="labelGraySize10">(# of days prior to due date user can see it)</span>
				</td>
			</tr>
			<tr>
				<td>
					<span class="publicationSummary">Sort</span>
				</td>
				<td>
					<input id="txt_{$TopicID}_ActionSort" type="text" class="text" style="width:50px;"
                           value="{$Sort}" tabindex="6"></input>
				</td>
			</tr>
			<tr>
				<td>
					<span class="publicationSummary">Description</span>
				</td>
				<td>
					<textarea id="txt_{$TopicID}_Description" type="text" tabindex="7" rows="2" class="textArea">
						<xsl:value-of select="$Description"/>
					</textarea>
				</td>
			</tr>
			<tr>
				<td>
					<xsl:choose>
						<xsl:when test="$PageOrigin != 'itemdetail'">
							<xsl:choose>
								<xsl:when test="$Mode = 'Update'">
									<input type="button" class="smallButton" value="Update" style="margin-top:10px;" tabindex="8"
                                        onClick="clientPortal_AddActionInTemplate('txt_{$TopicID}_Action','txt_{$TopicID}_StartDate',
                                                                    'txt_{$TopicID}_DueDate','txt_{$TopicID}_DaysPrior', 'txt_{$TopicID}_ActionSort',
                                                                    '{$TemplateID}','{$TopicName}','{$BrandID}','ddl_{$TopicID}_Add_Roles','Update','{$TopicID}',
                                                                    'divClientPortalOperations_Container','txt_{$TopicID}_Description','{$PageOrigin}',
																	'chk_{$TopicID}_MakeRecurring_{$ItemTemplateDetailID}',
																	'hdfRecurringPeriodType_{$TopicID}_{$ItemTemplateDetailID}',
																	'txt_{$TopicID}_RepeatEveryN_{$ItemTemplateDetailID}',
																	'nmRepeatOnWeekly_{$ItemTemplateDetailID}','txt_{$TopicID}_EndAfter_{$ItemTemplateDetailID}',
																	'txt_{$TopicID}_RepeatEveryN_Month_{$ItemTemplateDetailID}',
																	'txt_{$TopicID}_StartOfMonth_{$ItemTemplateDetailID}','txt_{$TopicID}_MidOfMonth_{$ItemTemplateDetailID}',
																	'txt_{$TopicID}_EndOfMonth_{$ItemTemplateDetailID}',
																	'nmRepeatOnMonthly_{$ItemTemplateDetailID}','txt_{$TopicID}_EndAfter_Month_{$ItemTemplateDetailID}');"></input>
								</xsl:when>
								<xsl:otherwise>
									<input type="button" class="smallButton" value="Save" style="margin-top:10px;" tabindex="8"
                                        onClick="clientPortal_AddActionInTemplate('txt_{$TopicID}_Action','txt_{$TopicID}_StartDate',
                                                                    'txt_{$TopicID}_DueDate','txt_{$TopicID}_DaysPrior', 'txt_{$TopicID}_ActionSort',                                                                   
                                                                    '{$TemplateID}','{$TopicName}','{$BrandID}','ddl_{$TopicID}_Add_Roles',
                                                                    'AddNew','{$TopicID}','divClientPortalOperations_Container','txt_{$TopicID}_Description','{$PageOrigin}',
																	'chk_{$TopicID}_MakeRecurring_{$ItemTemplateDetailID}',
																	'hdfRecurringPeriodType_{$TopicID}_{$ItemTemplateDetailID}',
																	'txt_{$TopicID}_RepeatEveryN_{$ItemTemplateDetailID}',
																	'nmRepeatOnWeekly_{$ItemTemplateDetailID}','txt_{$TopicID}_EndAfter_{$ItemTemplateDetailID}',
																	'txt_{$TopicID}_RepeatEveryN_Month_{$ItemTemplateDetailID}',
																	'txt_{$TopicID}_StartOfMonth_{$ItemTemplateDetailID}','txt_{$TopicID}_MidOfMonth_{$ItemTemplateDetailID}',
																	'txt_{$TopicID}_EndOfMonth_{$ItemTemplateDetailID}',
																	'nmRepeatOnMonthly_{$ItemTemplateDetailID}','txt_{$TopicID}_EndAfter_Month_{$ItemTemplateDetailID}');"></input>
								</xsl:otherwise>
							</xsl:choose>
						</xsl:when>
						<xsl:otherwise>
							<xsl:choose>
								<xsl:when test="$Mode = 'Update'">
									<input type="button" class="smallButton" value="Update" style="margin-top:10px;" tabindex="8"
                                        onClick="clientPortal_AddActionInTemplate('txt_{$TopicID}_Action','txt_{$TopicID}_StartDate',
                                                                    'txt_{$TopicID}_DueDate','txt_{$TopicID}_DaysPrior', 'txt_{$TopicID}_ActionSort',
                                                                    '{$TemplateID}','{$TopicName}','{$BrandID}','ddl_{$TopicID}_Add_Roles',
                                                                    'Update','{$TopicID}','divTemplateItems','txt_{$TopicID}_Description','{$PageOrigin}',
																	'chk_{$TopicID}_MakeRecurring_{$ItemTemplateDetailID}',
																	'hdfRecurringPeriodType_{$TopicID}_{$ItemTemplateDetailID}',
																	'txt_{$TopicID}_RepeatEveryN_{$ItemTemplateDetailID}',
																	'nmRepeatOnWeekly_{$ItemTemplateDetailID}','txt_{$TopicID}_EndAfter_{$ItemTemplateDetailID}',
																	'txt_{$TopicID}_RepeatEveryN_Month_{$ItemTemplateDetailID}',
																	'txt_{$TopicID}_StartOfMonth_{$ItemTemplateDetailID}','txt_{$TopicID}_MidOfMonth_{$ItemTemplateDetailID}',
																	'txt_{$TopicID}_EndOfMonth_{$ItemTemplateDetailID}',
																	'nmRepeatOnMonthly_{$ItemTemplateDetailID}','txt_{$TopicID}_EndAfter_Month_{$ItemTemplateDetailID}');"></input>
								</xsl:when>
								<xsl:otherwise>
									<input type="button" class="smallButton" value="Save" style="margin-top:10px;" tabindex="8"
                                        onClick="clientPortal_AddActionInTemplate('txt_{$TopicID}_Action','txt_{$TopicID}_StartDate',
                                                                    'txt_{$TopicID}_DueDate','txt_{$TopicID}_DaysPrior', 'txt_{$TopicID}_ActionSort',                                                                  
                                                                    '{$TemplateID}','{$TopicName}','{$BrandID}','ddl_{$TopicID}_Add_Roles',
                                                                    'AddNew','{$TopicID}','divTemplateItems','txt_{$TopicID}_Description','{$PageOrigin}',
																	'chk_{$TopicID}_MakeRecurring_{$ItemTemplateDetailID}',
																	'hdfRecurringPeriodType_{$TopicID}_{$ItemTemplateDetailID}',
																	'txt_{$TopicID}_RepeatEveryN_{$ItemTemplateDetailID}',
																	'nmRepeatOnWeekly_{$ItemTemplateDetailID}','txt_{$TopicID}_EndAfter_{$ItemTemplateDetailID}',
																	'txt_{$TopicID}_RepeatEveryN_Month_{$ItemTemplateDetailID}',
																	'txt_{$TopicID}_StartOfMonth_{$ItemTemplateDetailID}','txt_{$TopicID}_MidOfMonth_{$ItemTemplateDetailID}',
																	'txt_{$TopicID}_EndOfMonth_{$ItemTemplateDetailID}',
																	'nmRepeatOnMonthly_{$ItemTemplateDetailID}','txt_{$TopicID}_EndAfter_Month_{$ItemTemplateDetailID}');
                                                ClientPortal_CloseAddNewTemplateItemBox('div_{$TopicID}_AddNewItem',
                                                                            'div_{$TopicID}_AddNewAction',
                                                                            'div_{$TopicID}_AddNewItemButton','{$TopicID}');"></input>
								</xsl:otherwise>
							</xsl:choose>
						</xsl:otherwise>
					</xsl:choose>
				</td>
				<td>
					<xsl:choose>
						<xsl:when test="$Mode = 'Update'">
							<input type="button" class="smallButton" value="Cancel" style="margin-top:10px;" tabindex="9"
                                   onClick="ClientPortal_CloseUpdateActionBox('div_{$TopicID}_EditAction');"></input>
						</xsl:when>
						<xsl:otherwise>
							<input type="button" class="smallButton" value="Cancel" style="margin-top:10px;" tabindex="9"
                                 onClick="ClientPortal_CloseAddNewTemplateItemBox('div_{$TopicID}_AddNewItem',
                                                                            'div_{$TopicID}_AddNewAction',
                                                                            'div_{$TopicID}_AddNewItemButton','{$TopicID}');"></input>
						</xsl:otherwise>
					</xsl:choose>
				</td>
			</tr>
		</table>
	</xsl:template>
</xsl:stylesheet>
