﻿<?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:output method="xml" indent="yes" omit-xml-declaration="yes"/>

	<xsl:template match="/">
		<xsl:variable name="itemID" select="AjaxRequest/Params/ItemID"></xsl:variable>
		<xsl:variable name="ItemDetailColumn" select="AjaxRequest/ItemDetail/Columns"></xsl:variable>
		<xsl:variable name="ItemData" select="AjaxRequest/ItemDetail/ItemData"></xsl:variable>
		<xsl:variable name="GoalIsLand" select="AjaxRequest/ItemDetail/IsLand"></xsl:variable>
		<xsl:variable name="TaskDivID" select="AjaxRequest/TaskDivID"/>
		<xsl:variable name="List" select="AjaxRequest/ItemDetail/List"/>
		<xsl:variable name="ResponsibleList" select="AjaxRequest/ItemDetail/ResponsibleList/Responsible"/>
		<xsl:variable name="LoggedInUserID" select="AjaxRequest/LoggedInUserID"></xsl:variable>
		<xsl:variable name="PermissionID" select="AjaxRequest/ItemDetail/PermissionID"></xsl:variable>

		<xsl:for-each select="$ItemData">
			<table id="divTopicItemFull">
				<xsl:call-template name="TopicItemDetailed">
					<xsl:with-param name="CurrentRecordRow" select="."></xsl:with-param>
					<xsl:with-param name="PermissionID" select="$PermissionID"></xsl:with-param>
					<xsl:with-param name="ItemDetailColumn" select="$ItemDetailColumn"></xsl:with-param>
					<xsl:with-param name="itemID" select="$itemID"></xsl:with-param>
					<xsl:with-param name="TaskDivID" select="$TaskDivID"></xsl:with-param>
					<xsl:with-param name="List" select="$List"></xsl:with-param>
					<xsl:with-param name="ResponsibleList" select="$ResponsibleList"></xsl:with-param>
					<xsl:with-param name="LoggedInUserID" select="$LoggedInUserID"></xsl:with-param>
				</xsl:call-template>
			</table>
			<div id="divTopicItemSmall">
				<xsl:call-template name="TopicItemIsland">
					<xsl:with-param name="CurrentBriefRecordRow" select="."></xsl:with-param>
					<xsl:with-param name="GoalIsLand" select="$GoalIsLand"></xsl:with-param>
					<xsl:with-param name="itemID" select="$itemID"></xsl:with-param>
					<xsl:with-param name="TaskDivID" select="$TaskDivID"></xsl:with-param>
					<xsl:with-param name="PermissionID" select="$PermissionID"></xsl:with-param>
					<xsl:with-param name="List" select="$List"></xsl:with-param>
				</xsl:call-template>
			</div>
		</xsl:for-each>

	</xsl:template>


	<xsl:template name="TopicItemDetailed">
		<xsl:param name="CurrentRecordRow" select="'N/A'"></xsl:param>
		<xsl:param name="PermissionID" select="'N/A'"></xsl:param>
		<xsl:param name="ItemDetailColumn" select="'N/A'"></xsl:param>
		<xsl:param name="itemID" select="'N/A'"></xsl:param>
		<xsl:param name="TaskDivID" select="'N/A'"></xsl:param>
		<xsl:param name="List" select="'N/A'"></xsl:param>
		<xsl:param name="ResponsibleList" select="'N/A'"></xsl:param>
		<xsl:param name="LoggedInUserID" select="'N/A'"></xsl:param>

		<xsl:variable name="DataToggle">
			<xsl:choose>
				<xsl:when test="$PermissionID = 3 or $PermissionID &gt;= 4">
					<xsl:text>dropdown</xsl:text>
				</xsl:when>
			</xsl:choose>
		</xsl:variable>

		<xsl:variable name="CurrentItemID">
			<xsl:value-of select="$CurrentRecordRow/ItemID"/>
		</xsl:variable>
		<xsl:variable name="CurrentResponsibleID">
			<xsl:value-of select="$CurrentRecordRow/ResponsibleID"/>
		</xsl:variable>
		<xsl:variable name="OnClickDueDate">
			<xsl:choose>
				<xsl:when test="$PermissionID=3 or $PermissionID=4">
					<xsl:text>dp('div_item_</xsl:text>
					<xsl:value-of select="$CurrentItemID"></xsl:value-of>
					<xsl:text>_title_content_subTitle', 'div_item_</xsl:text>
					<xsl:value-of select="$CurrentItemID"></xsl:value-of>
					<xsl:text>_title_content_subTitle')</xsl:text>
				</xsl:when>
			</xsl:choose>
		</xsl:variable>
		<tr class="ExpandRow paddingNone">
			<xsl:for-each select="$ItemDetailColumn/Cols[Visibility=1]">
				<xsl:variable name="CurrentColName">
					<xsl:value-of select="ColName"/>
				</xsl:variable>
				<xsl:variable name="CurrentColValue">
					<xsl:value-of select="$CurrentRecordRow/child::node()[name(.) = $CurrentColName]"/>
				</xsl:variable>
				<td>
					<xsl:choose>
						<xsl:when test="$CurrentColName='Item'">
							<span class="onMouseOver pull-left clsSpanTopic_{$CurrentItemID}" id="spanTopic_{$CurrentItemID}" style="margin-right: 4px;"
								  onClick=" LoadCoreGoalTask_3_0('{$itemID}', '{$TaskDivID}', '', '', 1,'{$CurrentItemID}')">
								<xsl:value-of select="$CurrentColValue"/>
							</span>
							<i  title="Edit" id="icnEditTopic_{$CurrentItemID}" class="pull-left onMouseOver fa fa-pencil-square-o clsIcnEditTopic_{$CurrentItemID}"
							   onclick="$('.clsSpanTopic_{$CurrentItemID}').css('display','none');
							   $('.clsIcnEditTopic_{$CurrentItemID}').css('display','none');
							   $('.clsTxtTopic_{$CurrentItemID}').css('display','block');$('#txtTopic_{$CurrentItemID}').focus();" style="font-size: 15px;"></i>
							<input type="text" id="txtTopic_{$CurrentItemID}" value="{$CurrentColValue}" style="display:none;" class="txtnw form-control clsTxtTopic_{$CurrentItemID}"
								   onkeyup="UpdateActionName_3_0_EnterKey({$CurrentItemID}, 'spanTopic_{$CurrentItemID}', 'txtTopic_{$CurrentItemID}', event,'topic')"></input>
						</xsl:when>
						<xsl:when test="$CurrentColName='Priority'">
							<div class="col-md-12">
								<div class="btn-group ">
									<button type="button" class="multiselect dropdown-toggle btn padinone" data-toggle="{$DataToggle}" title="" aria-expanded="false" style="width: auto;">
										<span class="onMouseOver star-default glyphicon glyphicon-star star_{$CurrentColValue}"  id="span_{$CurrentColName}_{$CurrentItemID}"></span>
									</button>
									<ul class=" dropdown-menu {$CurrentColName}" id="ddl_{$CurrentColName}_{$CurrentItemID}" previousValue="{$CurrentColValue}">
										<xsl:choose>
											<xsl:when test="$PermissionID =3 or $PermissionID =4">
												<xsl:for-each select="$List/Priority/Option">
													<xsl:variable name="OnClickPriority">
														<xsl:text>UpdateItemPriority_3_0('</xsl:text>
														<xsl:value-of select="$CurrentItemID"></xsl:value-of>
														<xsl:text>','</xsl:text>
														<xsl:value-of select="Value"></xsl:value-of>
														<xsl:text>')</xsl:text>
													</xsl:variable>
													<xsl:choose>
														<xsl:when test="Value=$CurrentColValue">
															<li class="active" val="{Value}">
																<a href="javascript:void(0);" onclick="{$OnClickPriority}">
																	<label class="radio" style="padding-left: 0px;">
																		<span class="glyphicon glyphicon-star star_{Value}" ></span>
																	</label>
																</a>
															</li>
														</xsl:when>
														<xsl:otherwise>
															<li class="" val="{Value}">
																<a href="javascript:void(0);" onclick="{$OnClickPriority}">
																	<label class="radio" style="padding-left: 0px;">
																		<span class="glyphicon glyphicon-star star_{Value}" ></span>
																	</label>
																</a>
															</li>
														</xsl:otherwise>
													</xsl:choose>
												</xsl:for-each>
											</xsl:when>
										</xsl:choose>
									</ul>
								</div>
							</div>
						</xsl:when>
						<xsl:when test="$CurrentColName='CompletionPercentage'">
							<xsl:variable name="BarColor">
								<xsl:choose>
									<xsl:when test="round($CurrentColValue)=100">
										<xsl:text>progress-bar-success</xsl:text>
									</xsl:when>
									<xsl:otherwise>
										progress-bar-info
									</xsl:otherwise>
								</xsl:choose>
							</xsl:variable>
							<div class="progress Mrgin">
								<div class="progress-bar {$BarColor}" role="progressbar"  style="width:{$CurrentColValue}%">
									<span class="">
										<xsl:value-of select="round($CurrentColValue)"></xsl:value-of>%
									</span>
								</div>
							</div>
						</xsl:when>
						<xsl:when test="$CurrentColName='Responsible'">
							<xsl:variable name="ShowHideTask">
								<xsl:choose>
									<xsl:when test="$PermissionID = 3 or $PermissionID &gt;= 4">
										<xsl:text>ShowHideTask('ddlResponsible_</xsl:text>
										<xsl:value-of select="$CurrentItemID"></xsl:value-of>
										<xsl:text>','spanResponsible_</xsl:text>
										<xsl:value-of select="$CurrentItemID"></xsl:value-of>
										<xsl:text>');</xsl:text>
									</xsl:when>
								</xsl:choose>
							</xsl:variable>
							<xsl:choose>
								<xsl:when test="$PermissionID = 3 or $PermissionID &gt;= 4">
									<select style="display:none" id="ddlResponsible_{$CurrentItemID}" onchange="UpdateTopicItemResponsible('{$CurrentItemID}','ddlResponsible_{$CurrentItemID}','spanResponsible_{$CurrentItemID}')">
										<option value="-99"></option>
										<xsl:for-each select="$ResponsibleList">
											<xsl:variable name="ResponsibleName">
												<xsl:choose>
													<xsl:when test="UserID= $LoggedInUserID">
														<xsl:text>Me</xsl:text>
													</xsl:when>
													<xsl:otherwise>
														<xsl:value-of select="FirstName"/>
													</xsl:otherwise>
												</xsl:choose>
											</xsl:variable>
											<xsl:choose>
												<xsl:when test="$CurrentResponsibleID = UserID">
													<option value="{UserID}" selected="">
														<xsl:value-of select="$ResponsibleName"/>
													</option>
												</xsl:when>
												<xsl:otherwise>
													<option value="{UserID}">
														<xsl:value-of select="$ResponsibleName"/>
													</option>
												</xsl:otherwise>
											</xsl:choose>
										</xsl:for-each>
									</select>
								</xsl:when>
							</xsl:choose>
							<a href="javascript:void(0);" id="spanResponsible_{$CurrentItemID}" class="onMouseOver colorRes" onclick="{$ShowHideTask}">
								<xsl:choose>
									<xsl:when test="$CurrentColValue !=''">
										<xsl:choose>
											<xsl:when test="$CurrentResponsibleID= $LoggedInUserID">
												<xsl:text>Me</xsl:text>
											</xsl:when>
											<xsl:otherwise>
												<xsl:value-of select="$CurrentColValue"/>
											</xsl:otherwise>
										</xsl:choose>
									</xsl:when>
									<xsl:otherwise>Set Responsible</xsl:otherwise>
								</xsl:choose>
							</a>
						</xsl:when>
						<xsl:when test="$CurrentColName='TargetDateLabel'">
							<div onclick="{$OnClickDueDate}"
									  id="div_item_{$CurrentItemID}_title_content_subTitle"
									  name="&lt;OperationalData&gt;&lt;Version&gt;2.0&lt;/Version&gt;
											  &lt;ItemID&gt;{$CurrentItemID}&lt;/ItemID&gt;&lt;GoalID&gt;{$itemID}&lt;/GoalID&gt;
											  &lt;Mode&gt;GoalTopicDetail30&lt;/Mode&gt;		
											 &lt;ReflectDivID&gt;div_item_{$CurrentItemID}_title_container&lt;/ReflectDivID&gt;
											  &lt;/OperationalData&gt;">
								<a id="div_item_{$CurrentItemID}_title_container" href="javascript:void(0);" class="colorRes">
									<xsl:choose>
										<xsl:when test="$CurrentColValue =''">
											<xsl:text>Set Date</xsl:text>
										</xsl:when>
										<xsl:otherwise>
											<xsl:value-of select="$CurrentColValue"/>
										</xsl:otherwise>
									</xsl:choose>

								</a>
							</div>

						</xsl:when>
						<xsl:otherwise>
							<span>
								<xsl:value-of select="$CurrentColValue"/>
							</span>
						</xsl:otherwise>
					</xsl:choose>
				</td>
			</xsl:for-each>
		</tr>
	</xsl:template>

	<xsl:template name="TopicItemIsland">
		<xsl:param name="CurrentBriefRecordRow" select="'N/A'"></xsl:param>
		<xsl:param name="GoalIsLand" select="'N/A'"></xsl:param>
		<xsl:param name="itemID" select="'N/A'"></xsl:param>
		<xsl:param name="TaskDivID" select="'N/A'"></xsl:param>
		<xsl:param name="PermissionID" select="'N/A'"></xsl:param>
		<xsl:param name="List" select="'N/A'"></xsl:param>

		<xsl:variable name="DataToggle">
			<xsl:choose>
				<xsl:when test="$PermissionID = 3 or $PermissionID &gt;= 4">
					<xsl:text>dropdown</xsl:text>
				</xsl:when>
			</xsl:choose>
		</xsl:variable>

		<xsl:variable name="CurrentItemID">
			<xsl:value-of select="$CurrentBriefRecordRow/ItemID"/>
		</xsl:variable>
		<xsl:variable name="CurrentResponsibleID">
			<xsl:value-of select="$CurrentBriefRecordRow/ResponsibleID"/>
		</xsl:variable>

		<div id="divIsLand_{$CurrentItemID}" class="full_column ExpandRow">
			<div class="left_column" style="width:100%;padding:2px;">
				<xsl:for-each select="$GoalIsLand/Left[Visibility=1]">
					<xsl:variable name="CurrentLeftColName">
						<xsl:value-of select="ColName"/>
					</xsl:variable>
					<xsl:variable name="CurrentColValue">
						<xsl:value-of select="$CurrentBriefRecordRow/child::node()[name(.) = $CurrentLeftColName]"/>
					</xsl:variable>
					<xsl:choose>
						<xsl:when test="$CurrentLeftColName='Item'">
							<div class="MiDiv outarea ExpandRow onMouseOver clsSpanTopic_{$CurrentItemID}"
								 id="spanTopic_{$CurrentItemID}_IsLand"
								 onClick="LoadCoreGoalTask_3_0('{$itemID}', '{$TaskDivID}', '', '', 1,'{$CurrentItemID}')">
								<xsl:value-of select="$CurrentColValue"/>
							</div>
							<i title="Edit" id="icnEditTopic_{$CurrentItemID}_IsLand" class="pull-left onMouseOver fa fa-pencil-square-o clsIcnEditTopic_{$CurrentItemID}"
						   onclick="$('.clsSpanTopic_{$CurrentItemID}').css('display','none'); 
							   $('.clsIcnEditTopic_{$CurrentItemID}').css('display','none');
							   $('.clsTxtTopic_{$CurrentItemID}').css('display','block');$('#txtTopic_{$CurrentItemID}_IsLand').focus();"
							   style="margin:10px 5% 0 0; font-size: 15px;"></i>
							<input type="text" id="txtTopic_{$CurrentItemID}_IsLand" value="{$CurrentColValue}" style="display:none;"
								   class="txtnw form-control MiDiv outarea clsTxtTopic_{$CurrentItemID}"
								   onkeyup="UpdateActionName_3_0_EnterKey({$CurrentItemID}, 'spanTopic_{$CurrentItemID}', 'txtTopic_{$CurrentItemID}_IsLand', event,'topic')"></input>

						</xsl:when>
						<xsl:when test="$CurrentLeftColName='Priority'">
							<div class="float_padding">
								<div>
									<div class="btn-group ">
										<button  type="button" class="multiselect dropdown-toggle btn padinone" data-toggle="{$DataToggle}" title="" aria-expanded="false" style="width: auto;padding:0px;">
											<span class="onMouseOver star-default glyphicon glyphicon-star star_{$CurrentColValue}"  id="span_Brief_{$CurrentLeftColName}_{$CurrentItemID}"></span>
											<!--<b class="caret"></b>-->
										</button>
										<ul class=" dropdown-menu {$CurrentLeftColName}" id="ddl_Brief_{$CurrentLeftColName}_{$CurrentItemID}" previousValue="{$CurrentColValue}">
											<xsl:choose>
												<xsl:when test="$PermissionID = 3 or $PermissionID &gt;= 4">
													<xsl:for-each select="$List/Priority/Option">
														<xsl:variable name="OnClickPriority">
															<xsl:text>UpdateItemPriority_3_0('</xsl:text>
															<xsl:value-of select="$CurrentItemID"></xsl:value-of>
															<xsl:text>','</xsl:text>
															<xsl:value-of select="Value"></xsl:value-of>
															<xsl:text>')</xsl:text>
														</xsl:variable>
														<xsl:choose>
															<xsl:when test="Value=$CurrentColValue">
																<li class="active" val="{Value}">
																	<a href="javascript:void(0);" onclick="{$OnClickPriority}">
																		<label class="radio" style="padding-left: 0px;">
																			<span class="glyphicon glyphicon-star star_{Value}" ></span>
																		</label>
																	</a>
																</li>
															</xsl:when>
															<xsl:otherwise>
																<li class="" val="{Value}">
																	<a href="javascript:void(0);" onclick="{$OnClickPriority}">
																		<label class="radio" style="padding-left: 0px;">
																			<span class="glyphicon glyphicon-star star_{Value}" ></span>
																		</label>
																	</a>
																</li>
															</xsl:otherwise>
														</xsl:choose>
													</xsl:for-each>
												</xsl:when>
											</xsl:choose>
										</ul>
									</div>
								</div>
							</div>
						</xsl:when>
						<xsl:otherwise>
							<div class="LeftDiv ExpandRow">
								<xsl:value-of select="$CurrentColValue"/>
							</div>
						</xsl:otherwise>
					</xsl:choose>
				</xsl:for-each>
				<!-- Right Div-->
				<div class="right_column RightDiv Progres">
					<xsl:for-each select="$GoalIsLand/Right[Visibility=1]">
						<xsl:variable name="CurrentRightColName">
							<xsl:value-of select="ColName"/>
						</xsl:variable>
						<xsl:variable name="CurrentColValue">
							<xsl:value-of select="$CurrentBriefRecordRow/child::node()[name(.) = $CurrentRightColName]"/>
						</xsl:variable>
						<xsl:choose>
							<xsl:when test="$CurrentRightColName='CompletionPercentage'">
								<xsl:variable name="BarColor">
									<xsl:choose>
										<xsl:when test="round($CurrentColValue)=100">
											<xsl:text>progress-bar-success</xsl:text>
										</xsl:when>
										<xsl:otherwise>
											progress-bar-info
										</xsl:otherwise>
									</xsl:choose>
								</xsl:variable>
								<div class="progress Mrgin" >
									<div class="progress-bar {$BarColor}" role="progressbar"  style="width:{$CurrentColValue}%">
										<span class="">
											<xsl:value-of select="round($CurrentColValue)"></xsl:value-of>%
										</span>
									</div>
								</div>

							</xsl:when>
							<xsl:otherwise>
								<div class="float_padding">
									<xsl:value-of select="$CurrentColValue"/>
								</div>
							</xsl:otherwise>
						</xsl:choose>
					</xsl:for-each>
				</div>
			</div>
		</div>
	</xsl:template>

</xsl:stylesheet>
