﻿<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:import href="ItemMenu.xslt"/>

    <xsl:template  match="/">
        <xsl:variable name="TemplatePathURL" select="ActionInfo/TemplateURL"></xsl:variable>
        <xsl:variable name="ItemID" select="ActionInfo/ItemID"></xsl:variable>
        <xsl:variable name="ItemName" select="ActionInfo/ItemName"></xsl:variable>
        <xsl:variable name="ItemDivPrefix" select="ActionInfo/Params/DivPrefix"></xsl:variable>
        <xsl:variable name="GoalID" select="ActionInfo/GoalID"></xsl:variable>
        <xsl:variable name="GoalName" select="ActionInfo/GoalName"></xsl:variable>
        <xsl:variable name="Mode" select="'GoalDetail'"></xsl:variable>
        <xsl:variable name="PermissionID" select="normalize-space(ActionInfo/PermissionID)"/>
        <xsl:variable name="HostName" select="normalize-space(ActionInfo/HostName)"></xsl:variable>
        <xsl:variable name="CommunityAdmin" select="normalize-space(ActionInfo/CommunityAdmin)"></xsl:variable>
        <xsl:variable name="ActionDueDate" select="normalize-space(ActionInfo/VisibleInfo/DueDate)"></xsl:variable>
        <xsl:variable name="IsVisible" select="normalize-space(ActionInfo/VisibleInfo/VisibleAction)"></xsl:variable>
        <xsl:variable name="TopicName" select="normalize-space(ActionInfo/TopicName)"></xsl:variable>


        <xsl:choose>
            <xsl:when test ="$IsVisible = 'NoVisible'">
                <div id="{$ItemDivPrefix}_summary">
                    <table cellpadding="0" cellspacing="0" border="0" width="100%">
                        <tr>
                            <td style="text-align:center;">
                                <div class="label">
                                    Related To: &#xa0;<a href="http://{$HostName}/Goal.aspx?ID={$GoalID}" class="link" target="_blank">
                                        <xsl:value-of select="$GoalName"/>
                                    </a>
                                </div>
                                <div class="label">
                                    Details for this item will be provided on&#xa0;<xsl:value-of select ="$ActionDueDate"/>
                                </div>
                            </td>
                        </tr>
                    </table>
                </div>
            </xsl:when>
            <xsl:otherwise>
                <div id="{$ItemDivPrefix}_summary">
                    <table cellpadding="0" cellspacing="0" border="0" width="100%">
                        <tr>
                            <td width="30px;">
                                <input type="checkbox" id="chkItem_1" name="chbNewDoIt" disabled="true" class="taskFilter"/>
                            </td>
                            <td style="text-align:left;">
                                <div class="labelHeader" style="cursor: pointer;">
                                    <xsl:value-of select ="$ItemName"/>
                                </div>
                            </td>
                            <td width="100px" style="text-align:center;">
                                <xsl:choose>
                                    <xsl:when test="$PermissionID = 3 or $PermissionID = 4">
                                        <span id="{$ItemDivPrefix}_summarizedMenu_ItemSelectDate" style="color: black;"
                                              name="&lt;OperationalData&gt;&lt;Version&gt;1.1&lt;/Version&gt;&lt;ItemID&gt;{$ItemID}&lt;/ItemID&gt;&lt;GoalID&gt;{$GoalID}&lt;/GoalID&gt;&lt;Mode&gt;{$Mode}&lt;/Mode&gt;&lt;ItemDivPrefix&gt;{$ItemDivPrefix}&lt;/ItemDivPrefix&gt;&lt;/OperationalData&gt;"
                                              onmouseover="this.style.textDecoration='underline'; this.style.cursor='pointer';"
                                              onmouseout="this.style.textDecoration='none';"
                                              onclick='dp("{$ItemDivPrefix}_summarizedMenu_ItemSelectDate", 
                                          "{$ItemDivPrefix}_summarizedMenu_ItemSelectDate")'>
                                            <xsl:value-of select="normalize-space(ActionInfo/DueDate)"/>
                                        </span>
                                        <input id="{$ItemDivPrefix}_summarizedMenu_ItemSelectDate_txt"
                                           type="text" class="dateTextBox" value="{ActionInfo/DueDate}" style="display: none;">
                                        </input>
                                    </xsl:when>
                                    <xsl:otherwise>
                                        <span id="{$ItemDivPrefix}_summarizedMenu_ItemSelectDate" style="color: black;">
                                            <xsl:value-of select="normalize-space(ActionInfo/DueDate)"/>
                                        </span>
                                    </xsl:otherwise>
                                </xsl:choose>
                            </td>
                            <td width="100px" style="text-align:center;">
                                <xsl:choose>
                                    <xsl:when test="$PermissionID = 3 or $PermissionID = 4">
                                        <span id="{$ItemDivPrefix}_summarizedMenu_ItemSelectStatus" style="color: black;"
                                              onmouseover="this.style.textDecoration='underline'; this.style.cursor='pointer'"
                                              onmouseout="this.style.textDecoration='none';"
                                              onclick='task_EditItemStatus(
                                                            "{$ItemDivPrefix}_opt_summarizedMenu_ItemSelectStatus", 
                                                            "{$ItemDivPrefix}_summarizedMenu_ItemSelectStatus",
                                                            "{ActionInfo/ItemStatus}");'>
                                            <xsl:value-of select="normalize-space(ActionInfo/ItemStatus)"/>
                                        </span>
                                        <select id="{$ItemDivPrefix}_opt_summarizedMenu_ItemSelectStatus"
                                            style="display: none;" name="StatusType" class="smallDropdown"
                                            onChange='return task_UpdateItemStatus(
                                                    "{$ItemID}",
                                                    "{$ItemDivPrefix}_opt_summarizedMenu_ItemSelectStatus",
                                                    "{$GoalID}", 
                                                    "{$Mode}",
                                                    "{$ItemDivPrefix}", 
                                                    "1.1");'>

                                            <option value="1" class="smallDropdown">
                                                <xsl:text>Not Started</xsl:text>
                                            </option>
                                            <option value="2" class="smallDropdown">
                                                <xsl:text>In Progress</xsl:text>
                                            </option>
                                            <option value="3" class="smallDropdown">
                                                <xsl:text>Waiting</xsl:text>
                                            </option>
                                            <option value="4" class="smallDropdown">
                                                <xsl:text>Completed</xsl:text>
                                            </option>
                                            <option value="5" class="smallDropdown">
                                                <xsl:text>Terminated</xsl:text>
                                            </option>
                                            <option value="6" class="smallDropdown">
                                                <xsl:text>Archived</xsl:text>
                                            </option>
                                        </select>
                                    </xsl:when>
                                    <xsl:otherwise>
                                        <span id="{$ItemDivPrefix}_summarizedMenu_ItemSelectStatus">
                                            <xsl:value-of select="normalize-space(ActionInfo/ItemStatus)"></xsl:value-of>
                                        </span>
                                    </xsl:otherwise>
                                </xsl:choose>
                            </td>
                            <td width="100px" style="text-align:center;">
                                <xsl:if test="normalize-space(ActionInfo/ResponsibleID) = normalize-space(ActionInfo/ResponsibleID)" >
                                    <span style="color: black;">
                                        <xsl:if test="normalize-space(ActionInfo/CurrentUserID) = normalize-space(ActionInfo/ResponsibleID)">
                                            Me
                                        </xsl:if>
                                        <xsl:if test="normalize-space(ActionInfo/CurrentUserID) != normalize-space(ActionInfo/ResponsibleID)">
                                            <xsl:value-of select="normalize-space(ActionInfo/UserFullName)"/>
                                        </xsl:if>
                                    </span>
                                </xsl:if>
                            </td>
                        </tr>
                    </table>
                </div>
                <div id="{$ItemDivPrefix}_description" style="margin-left: 30px; margin-top: 10px; margin-bottom: 10px;">
                    <xsl:apply-templates select ="ActionInfo/ActionDesc"></xsl:apply-templates>
                </div>
                <div id="{$ItemDivPrefix}_GoalName" style="margin-left: 30px; margin-top: 10px; margin-bottom: 10px;">
                    <span class="label">Related to:</span>
                    <a href="http://{$HostName}/Goal.aspx?ID={$GoalID}" target="_blank" class="link">
                        &#xa0;<xsl:apply-templates select ="$GoalName"></xsl:apply-templates>
                    </a>
                </div>
                <xsl:if test="$TopicName">
                    <div style="margin-left: 30px; margin-top: 10px; margin-bottom: 10px;">

                        <span class="label">Topic:</span>
                        <span class="link" style="text-decoration:none;">
                            <xsl:value-of select ="$TopicName"/>
                        </span>
                    </div>
                </xsl:if>
                <div id="{$ItemDivPrefix}_menu" style="margin-left: 20px;">
                    <xsl:call-template name="ItemMenu">
                        <xsl:with-param name="TemplatePathURL" select="$TemplatePathURL"></xsl:with-param>
                        <xsl:with-param name="ItemID" select="$ItemID"></xsl:with-param>
                        <xsl:with-param name="ItemDivPrefix">
                            <xsl:value-of select="$ItemDivPrefix" />
                        </xsl:with-param>
                        <xsl:with-param name="GoalID" select="$GoalID"></xsl:with-param>
                        <xsl:with-param name="Mode" select="$Mode"></xsl:with-param>
                        <xsl:with-param name="OperationDiv">
                            <xsl:value-of select="$ItemDivPrefix" />
                            <xsl:text>_operations</xsl:text>
                        </xsl:with-param>
                        <xsl:with-param name="PermissionID" select="$PermissionID"></xsl:with-param>
                        <xsl:with-param name="StatusID" select="normalize-space(ActionInfo/StatusID)"></xsl:with-param>
                        <xsl:with-param name="CommunityAdmin" select="$CommunityAdmin"></xsl:with-param>
                    </xsl:call-template>
                </div>
                <div id="{$ItemDivPrefix}_operations">
                    <xsl:value-of select="ActionInfo/NotesHTML" disable-output-escaping="yes"/>
                </div>
                <div id="{$ItemDivPrefix}_advertisement">

                </div>
                <div id="{$ItemDivPrefix}_attachedItem" style="margin-left: 20px;">
                </div>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>

    <xsl:template match ="ActionInfo/ActionDesc">
        <xsl:call-template name ="break"></xsl:call-template>
    </xsl:template>

    <xsl:template name="break">
        <xsl:param name="text" select="."/>
        <xsl:choose>
            <xsl:when test="contains($text, '&#xa;')">
                <xsl:value-of select="substring-before($text, '&#xa;')"/>
                <br/>
                <xsl:call-template name="break">
                    <xsl:with-param name="text" select="substring-after($text,'&#xa;')"/>
                </xsl:call-template>
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="$text"/>
            </xsl:otherwise>
        </xsl:choose>

    </xsl:template>
</xsl:stylesheet>