﻿<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:import href="GenericTemplates/AutoSuggestUsers.xslt"/>
    <xsl:import href="ClientPortal/ClientContactControl.xslt"/>


    <xsl:template match="/">
        <xsl:variable name ="taskID" select="normalize-space(ShareIt/itemID)"/>
        <xsl:variable name ="goalID" select="normalize-space(ShareIt/goalID)"/>
        <xsl:variable name ="itemTypeID" select="normalize-space(ShareIt/itemType)"/>
        <xsl:variable name ="proPackageID" select="normalize-space(ShareIt/ProPackageID)"/>
        <xsl:variable name ="portalTypeID" select="normalize-space(ShareIt/portalTypeID)"/>
        <xsl:variable name ="TemplatePathURL" select="normalize-space(ShareIt/TemplateURL)"/>
        <xsl:variable name ="LoggedInUserID" select="normalize-space(ShareIt/LoggedInUserID)"/>
        <xsl:variable name="PermissionID" select="ShareIt/Permissions/Local/Permission[AuthorizedID = $LoggedInUserID]/PermissionTypeID"></xsl:variable>
        
        <div id ="div_{normalize-space($taskID)}_shareIt" style="margin: 20px;">
            <xsl:if test ="normalize-space($itemTypeID) = 'Project' or normalize-space($itemTypeID) = 'Goal'">
                <div id="divSeparatorLineImage_{$taskID}" style="margin-left: -20px;margin-right: -20px;margin-top:-15px;">
                    <img style="width:100%;" src="{$TemplatePathURL}Web/Images/Ver_2_0/dropshadow_730.png"></img>
                </div>
                <div id="divOperationHeading_{$taskID}" class="divOperationHeading" style="padding-top:20px;padding-bottom:20px;">
                    SHARE IT – INVITE OTHERS TO JOIN THIS GOAL – BUILD YOUR TEAM
                </div>
                <div class="tableLocal" >
                    <span class="labelHeader">
                        Participants
                    </span>
                </div>
            </xsl:if>
            <xsl:if test ="count(ShareIt/Permissions/Inherited/Permission) != 0">
                <div id ="div_{normalize-space($taskID)}_shareIt_inherited" class="tableInherit" onClick='return ChangeInheritedPermissions
                                ("div_{normalize-space($taskID)}_shareIt","{normalize-space($taskID)}","{normalize-space($goalID)}");'>
                    <xsl:for-each select ="ShareIt/Permissions/Inherited/Permission">
                        <div id ="div_{normalize-space($taskID)}_shareIt_inherited_{normalize-space(ItemPermissionID/.)}">
                            <span style="margin-left:10px" class="link" onclick='return false;'>[X]</span>

                            <span style="margin-left:10px">
                                <xsl:value-of select ="normalize-space(AuthorizedName/.)"/>
                            </span>
                            <span style="margin-left:10px" class="link">
                                [<xsl:value-of select ="normalize-space(Permission/.)"/>]
                            </span>
                        </div>
                    </xsl:for-each>
                </div>
            </xsl:if>


            <xsl:if test ="count(ShareIt/Permissions/Local/Permission) !=0">

                <div id ="div_{normalize-space($taskID)}_shareIt_local">
                    <xsl:for-each select ="ShareIt/Permissions/Local/Permission">
                      
                        
                        <div id ="div_{normalize-space($taskID)}_shareIt_local_{normalize-space(ItemPermissionID/.)}" >
                            <xsl:variable name="PermissionTypeID">
                                <xsl:value-of select="normalize-space(PermissionTypeID/.)"/>
                            </xsl:variable>
                            <table class="tableMaster" cellpadding="3" cellspacing="3">
                                <tr>
                                    <td width="5%" class="verticallyMiddle textLeft">
                                        <xsl:if test="$PermissionID = 4">
                                            <img style="margin-left:10px" class="onMouseOver" src="{$TemplatePathURL}/Web/Images/Ver_2_0/BT_x.png" height="10" width="10"
                                                 onClick='return SecureIt_DeleteItemPermission(
                                            "{normalize-space(ItemPermissionID/.)}",
                                            "div_{normalize-space($taskID)}_shareIt_local_{normalize-space(ItemPermissionID/.)}");'></img>
                                        </xsl:if>
                                    </td>
                                    <td width="10%" class="verticallyMiddle textLeft">
                                        <xsl:choose>
                                            <xsl:when test="UserImage != ''">
                                                <img src="{UserImage}" height="50" width="50" align="absmiddle"></img>
                                            </xsl:when>
                                            <xsl:otherwise>
                                                <img src="{$TemplatePathURL}Web/Images/Ver_2_0/DefaultUserPic.jpg" height="50" width="50" align="absmiddle"></img>
                                            </xsl:otherwise>
                                        </xsl:choose>
                                    </td>
                                    <td width="35%" class="verticallyMiddle textLeft">
                                        <span class="packageTitle onMouseOver"
                                              onclick="LoadEmployeeDetail('{AuthorizedID}','divClientPortalOperations_Container','{ItemID}');">
                                            <xsl:value-of select ="normalize-space(AuthorizedName/.)"/>
                                        </span>
                                    </td>
                                    <td width="50%" class="verticallyMiddle textLeft">
                                        <xsl:choose>
                                            <xsl:when test="$PermissionID = 4">
                                                <span id ="spn_lnk_{normalize-space(ItemPermissionID/.)}_PermType" class="packageTitle onMouseOver textLeft"
                                           onClick='return EditItemPermission( "spn_opt_{normalize-space(ItemPermissionID/.)}_PermType","spn_lnk_{normalize-space(ItemPermissionID/.)}_PermType");'>
                                                    [<xsl:choose>
                                                        <xsl:when test='$portalTypeID = 4 and Permission = "Edit"'>
                                                            <xsl:text>Manager</xsl:text>
                                                        </xsl:when>
                                                        <xsl:when test='$portalTypeID = 8 and ($proPackageID = 4 or $proPackageID = 5) and Permission = "Edit"'>
                                                            <xsl:text>Manager</xsl:text>
                                                        </xsl:when>
                                                        <xsl:when test='$portalTypeID = 8 and ($proPackageID = 4 or $proPackageID = 5) and Permission = "View"'>
                                                            <xsl:text>User Access</xsl:text>
                                                        </xsl:when>
                                                        <xsl:when test='$portalTypeID = 8 and ($proPackageID = 4 or $proPackageID = 5) and Permission = "Notify"'>
                                                            <xsl:text>User Restricted</xsl:text>
                                                        </xsl:when>
                                                        <xsl:otherwise>
                                                            <xsl:value-of select ="normalize-space(Permission/.)"/>
                                                        </xsl:otherwise>
                                                    </xsl:choose>]
                                                </span>
                                            </xsl:when>
                                            <xsl:otherwise>
                                                <span id ="spn_lnk_{normalize-space(ItemPermissionID/.)}_PermType" class="packageTitle onMouseOver textLeft">
                                                    [<xsl:choose>
                                                        <xsl:when test='$portalTypeID = 4 and Permission = "Edit"'>
                                                            <xsl:text>Manager</xsl:text>
                                                        </xsl:when>
                                                        <xsl:when test='$portalTypeID = 8 and ($proPackageID = 4 or $proPackageID = 5) and Permission = "Edit"'>
                                                            <xsl:text>Manager</xsl:text>
                                                        </xsl:when>
                                                        <xsl:when test='$portalTypeID = 8 and ($proPackageID = 4 or $proPackageID = 5) and Permission = "View"'>
                                                            <xsl:text>User Access</xsl:text>
                                                        </xsl:when>
                                                        <xsl:when test='$portalTypeID = 8 and ($proPackageID = 4 or $proPackageID = 5) and Permission = "Notify"'>
                                                            <xsl:text>User Restricted</xsl:text>
                                                        </xsl:when>
                                                        <xsl:otherwise>
                                                            <xsl:value-of select ="normalize-space(Permission/.)"/>
                                                        </xsl:otherwise>
                                                    </xsl:choose>]
                                                </span>
                                            </xsl:otherwise>
                                        </xsl:choose>




                                        <span id ="spn_opt_{normalize-space(ItemPermissionID/.)}_PermType" style="display:none;">
                                            <select name="PermType" onChange='return UpdateItemPermission(this, "{normalize-space(ItemPermissionID/.)}",
                                            "{normalize-space($taskID)}","div_{normalize-space($taskID)}_shareIt","{normalize-space($goalID)}");'>
                                                <xsl:for-each select="../../../PermissionType/Type">
                                                    <xsl:if test ="$PermissionTypeID=ID">
                                                        <option value="{ID/.}" selected="selected">
                                                            <xsl:value-of select="normalize-space(Name/.)"/>
                                                        </option>
                                                    </xsl:if>
                                                    <xsl:if test ="$PermissionTypeID!=ID">
                                                        <option value="{ID/.}">
                                                            <xsl:value-of select="normalize-space(Name/.)"/>
                                                        </option>
                                                    </xsl:if>
                                                </xsl:for-each>
                                            </select>
                                        </span>
                                    </td>
                                </tr>
                            </table>
                        </div>
                    </xsl:for-each>

                </div>

            </xsl:if>

            <xsl:if test ="normalize-space($itemTypeID) = 'Action' or normalize-space($itemTypeID) = 'ItemSummary'">
                <div style="margin-top:10px;">
                    <xsl:if test =" count (ShareIt/Permissions/Inherited/Permission) = 0">
                        <span class="link"
                              onclick='return SecureIt_RestoreInheritedPermissions("div_{normalize-space($taskID)}_shareIt",
                                        "{normalize-space($taskID)}","{normalize-space($goalID)}");'>
                            [Restore Default Security]
                        </span>
                    </xsl:if>
                </div>
            </xsl:if >
            <div style='width:100px;'>
                <xsl:call-template name="AutoSuggestUsers">
                    <xsl:with-param name="goalID" select="$goalID"></xsl:with-param>
                    <xsl:with-param name="taskID" select="$taskID"></xsl:with-param>
                    <xsl:with-param name="origin" select="'ShareIt'"></xsl:with-param>
                </xsl:call-template>
            </div>
        </div>

    </xsl:template>
</xsl:stylesheet>
