﻿<?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="../Version_2_0/PagingTemplate.xslt"/>

    <xsl:key name="DistinctActivePortals" match="LocalOffice" use="./ActiveYN"></xsl:key>

    <xsl:output method="xml" indent="yes"/>




    <xsl:template match="/">
        <xsl:variable name="LocalOffcXML" select="AjaxRequest/LocalOfficesXML/."></xsl:variable>
        <xsl:variable name="TemplateURL" select="AjaxRequest/TemplateURL"></xsl:variable>
        <xsl:variable name="Action" select="AjaxRequest/Action"></xsl:variable>
        <xsl:variable name="HostName" select="AjaxRequest/HostName"></xsl:variable>
        <xsl:variable name="PortalItemID" select="AjaxRequest/Params/PortalItemID"></xsl:variable>
        <xsl:variable name="ActiveYN" select="AjaxRequest/Params/ActiveYN"></xsl:variable>
        <xsl:variable name="PortalName" select="AjaxRequest/Params/PortalName"></xsl:variable>
        <xsl:variable name="ParentBrandID">
            <xsl:choose>
                <xsl:when test="AjaxRequest/LocalOfficesXML/ParentBrandID">
                    <xsl:value-of select="AjaxRequest/LocalOfficesXML/ParentBrandID"/>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:value-of select="AjaxRequest/BrandID"/>
                </xsl:otherwise>
            </xsl:choose>
        </xsl:variable>
        <xsl:variable name="BrandID" select="AjaxRequest/BrandID"></xsl:variable>
        <xsl:variable name="PageSize" select="AjaxRequest/Params/PageSize"></xsl:variable>
        <xsl:variable name="PageNumber" select="AjaxRequest/Params/PageNumber"></xsl:variable>
        <xsl:variable name="TotalPages">
            <xsl:choose>
                <xsl:when test="AjaxRequest/LocalOfficesXML/LocalOffice/TotalPages">
                    <xsl:value-of select="AjaxRequest/LocalOfficesXML/LocalOffice/TotalPages"/>
                </xsl:when>
            </xsl:choose>
        </xsl:variable>
        <xsl:variable name="TotalRecords">
            <xsl:choose>
                <xsl:when test="AjaxRequest/LocalOfficesXML/LocalOffice/TotalRecords">
                    <xsl:value-of select="AjaxRequest/LocalOfficesXML/LocalOffice/TotalRecords"/>
                </xsl:when>
            </xsl:choose>
        </xsl:variable>
        <xsl:variable name="CurrentPageNumber" select="AjaxRequest/LocalOfficesXML/CurrentPageNumber"></xsl:variable>
        <xsl:variable name="NodeCount" select="count($LocalOffcXML/LocalOffice)"></xsl:variable>
		<xsl:variable name="UserID" select="AjaxRequest/UserID"></xsl:variable>
		<xsl:variable name="BetaVersion" select="AjaxRequest/Settings/BetaVersion"></xsl:variable>

        <div>
            <div style="height:30px;margin-bottom:10px;">
                <div id="div_LoadAddNewLocalOffice" class="verticallyMiddle onMouseOver divBrowseGradient textCenter spanBrowseGradientTextGray marginTop10"
                     style="width:130px;line-height:24px;float:right" parentBrandID="{$ParentBrandID}"
                     onclick="LoadCoachInfoWizard('LoadAddNewLocalOffice',0,'divClientPortalOperations_Container',-99);"
                     onmouseover="document.getElementById('img_AddSource').src='{$TemplateURL}Web/Images/Ver_2_0/icon_add_over.png';"
                     onmouseout="document.getElementById('img_AddSource').src='{$TemplateURL}Web/Images/Ver_2_0/icon_Add.png';">
                    <img id="img_AddSource"
                         src="{$TemplateURL}Web/Images/Ver_2_0/icon_Add.png" align="absmiddle" style="padding-left:8px;" class="marginRight5"></img>
                    <span id="span_saveSource" class="capitalFont">Add New Portal</span>
                </div>
            </div>
            <div id="div_PortalFilters" class="marginTop5 marginBottom10">
                <span class="packageTitle marginRight5">
                    Portal
                </span>
                <input id="txt_PortalName" type="text" class="text" style="width:300px;margin-right:10px;" value="{$PortalName}"
                       onkeypress="portal_LoadLocalOffice_filter('{$PortalItemID}', 'div_PortalsList','{$PageSize}',
                                                                '{$PageNumber}','txt_PortalName', 'opt_ActivePortal', event);"></input>

                <span class="packageTitle marginRight5">
                    Active
                </span>
                <select id="opt_ActivePortal" class="smallDropdown"
                        onchange="return portal_LoadLocalOffice_filter('{$PortalItemID}', 'div_PortalsList','{$PageSize}',
                                                                '{$PageNumber}','txt_PortalName', 'opt_ActivePortal', null);">
                    <option value="-99">-Select-</option>
                    <option value="1">Yes</option>
                    <option value="0">No</option>
                </select>
            </div>

            <xsl:choose>
                <xsl:when test="count($LocalOffcXML/LocalOffice) &gt; 0">
                    <div id="div_PortalsList">
                        <xsl:call-template name="Template_PortalList">
                            <xsl:with-param name="LocalOffcXML" select="$LocalOffcXML"></xsl:with-param>
                            <xsl:with-param name="PortalItemID" select="$PortalItemID"></xsl:with-param>
                            <xsl:with-param name="TotalPages" select="$TotalPages"></xsl:with-param>
                            <xsl:with-param name="CurrentPageNumber" select="$CurrentPageNumber"></xsl:with-param>
                            <xsl:with-param name="TotalRecords" select="$TotalRecords"></xsl:with-param>
                            <xsl:with-param name="PageSize" select="$PageSize"></xsl:with-param>
                            <xsl:with-param name="NodeCount" select="$NodeCount"></xsl:with-param>
                            <xsl:with-param name="Action" select="$Action"></xsl:with-param>
							<xsl:with-param name="UserID" select="$UserID"></xsl:with-param>
							<xsl:with-param name="BetaVersion" select="$BetaVersion"></xsl:with-param>
                        </xsl:call-template>
                    </div>
                </xsl:when>
                <xsl:otherwise>
                    <div id="div_PortalsList" align="center">
                        There are no portals
                    </div>
                </xsl:otherwise>
            </xsl:choose>


            <div  style="height:30px;margin-bottom:10px;">
                <div id="div_LoadAddNewLocalOffice" class="verticallyMiddle onMouseOver divBrowseGradient textCenter spanBrowseGradientTextGray marginTop20"
                     style="width:130px;line-height:24px;float:right" parentBrandID="{$ParentBrandID}"
                     onclick="LoadCoachInfoWizard('LoadAddNewLocalOffice',0,'divClientPortalOperations_Container',-99);"
                     onmouseover="document.getElementById('img_AddSource').src='{$TemplateURL}Web/Images/Ver_2_0/icon_add_over.png';"
                     onmouseout="document.getElementById('img_AddSource').src='{$TemplateURL}Web/Images/Ver_2_0/icon_Add.png';" >
                    <img id="img_AddSource"
                         src="{$TemplateURL}Web/Images/Ver_2_0/icon_Add.png" align="absmiddle" style="padding-left:8px;" class="marginRight5"></img>
                    <span id="span_saveSource" class="capitalFont">Add New Portal</span>
                </div>
            </div>
        </div>
    </xsl:template>


    <xsl:template name="Template_PortalList">
        <xsl:param name="LocalOffcXML" select="'N/A'"></xsl:param>
        <xsl:param name="PortalItemID" select="'N/A'"></xsl:param>
        <xsl:param name="TotalPages" select="'N/A'"></xsl:param>
        <xsl:param name="CurrentPageNumber" select="'N/A'"></xsl:param>
        <xsl:param name="TotalRecords" select="'N/A'"></xsl:param>
        <xsl:param name="PageSize" select="'N/A'"></xsl:param>
        <xsl:param name="NodeCount" select="'N/A'"></xsl:param>
        <xsl:param name="Action" select="'N/A'"></xsl:param>
		<xsl:param name="UserID" select="'N/A'"></xsl:param>
		<xsl:param name="BetaVersion" select="'N/A'"></xsl:param>

        <table class="tableMaster" cellpadding="3" cellspacing="3">

            <tr>
                <td width="10%"></td>
                <td width="25%">
                    <span class="packageTitle">Portal</span>
                </td>
                <td width="25%">
                    <span class="packageTitle">City</span>
                </td>
                <td width="15%">
                    <span class="packageTitle">State</span>
                </td>
                <td width="10%">
                    <span class="packageTitle">Active</span>
                </td>
                <td width="15%">
                    <span class="packageTitle">Admin</span>
                </td>
            </tr>
            <tr>
                <td colspan="6">
                    <xsl:if test="count($LocalOffcXML/LocalOffice[ActiveYN = 1]) &gt; 0">
                        <div class="packageTitle onMouseOver seperatorLine" style="font-size:18px;" title="Click to hide"
                                        onclick="return expandCollapseByGroup('div_ActivePortals');">
                            Active
                        </div>
                        <div id="div_ActivePortals">
                            <xsl:call-template name="PortalListHTML">
                                <xsl:with-param name="LocalOffcXML" select="$LocalOffcXML"></xsl:with-param>
                                <xsl:with-param name="PortalItemID" select="$PortalItemID"></xsl:with-param>
                                <xsl:with-param name="Active">
                                    <xsl:text>1</xsl:text>
                                </xsl:with-param>
								<xsl:with-param name="UserID" select="$UserID"></xsl:with-param>
								<xsl:with-param name="BetaVersion" select="$BetaVersion"></xsl:with-param>
                            </xsl:call-template>
                        </div>
                    </xsl:if>

                    <xsl:if test="count($LocalOffcXML/LocalOffice[ActiveYN = 0]) &gt; 0">
                        <div class="packageTitle onMouseOver seperatorLine" style="font-size:18px;" title="Click to hide"
                                      onclick="return expandCollapseByGroup('div_InactivePortals');">
                            Inactive
                        </div>
                        <div id="div_InactivePortals">
                            <xsl:call-template name="PortalListHTML">
                                <xsl:with-param name="LocalOffcXML" select="$LocalOffcXML"></xsl:with-param>
                                <xsl:with-param name="PortalItemID" select="$PortalItemID"></xsl:with-param>
                                <xsl:with-param name="Active">
                                    <xsl:text>0</xsl:text>
                                </xsl:with-param>
								<xsl:with-param name="UserID" select="$UserID"></xsl:with-param>
								<xsl:with-param name="BetaVersion" select="$BetaVersion"></xsl:with-param>
                            </xsl:call-template>
                        </div>
                    </xsl:if>
                </td>
            </tr>
           


            <tr>
                <td colspan="6" class="textCenter">
                    <xsl:call-template name="PortalPagingTemplate">
                        <xsl:with-param name="TotalPages" select="$TotalPages"></xsl:with-param>
                        <xsl:with-param name="PortalItemID" select="$PortalItemID"></xsl:with-param>
                        <xsl:with-param name="DivID">
                            <xsl:text>divClientPortalOperations_Container</xsl:text>
                        </xsl:with-param>
                        <xsl:with-param name="Mode">
                            <xsl:choose>
                                <xsl:when test="$Action = 'LoadLocalOffice'">
                                    <xsl:text>PortalAdminList</xsl:text>
                                </xsl:when>
                                <xsl:when test="$Action = 'LoadFilteredLocalOffice'">
                                    <xsl:text>FilteredPortalAdminList</xsl:text>
                                </xsl:when>
                            </xsl:choose>
                        </xsl:with-param>
                        <xsl:with-param name="CurrentPageNumber" select="$CurrentPageNumber"></xsl:with-param>
                        <xsl:with-param name="PermissionsXML" select="$LocalOffcXML"></xsl:with-param>
                        <xsl:with-param name="TotalRecords" select="$TotalRecords"></xsl:with-param>
                        <xsl:with-param name="PageSize" select="$PageSize"></xsl:with-param>
                        <xsl:with-param name="NodeCount" select="$NodeCount"></xsl:with-param>
                    </xsl:call-template>
                </td>
            </tr>

        </table>

    </xsl:template>

    <xsl:template name="PortalListHTML">
        <xsl:param name="LocalOffcXML" select="'N/A'"></xsl:param>
        <xsl:param name="PortalItemID" select="'N/A'"></xsl:param>
		<xsl:param name="Active" select="'N/A'"></xsl:param>
		<xsl:param name="UserID" select="'N/A'"></xsl:param>
		<xsl:param name="BetaVersion" select="'N/A'"></xsl:param>
		
        <xsl:for-each select ="$LocalOffcXML/LocalOffice
                                  [generate-id() = generate-id(key('DistinctActivePortals', ./ActiveYN ))]">

            <xsl:variable name="ActiveYN" select="ActiveYN"></xsl:variable>

            <xsl:for-each select="../LocalOffice[ActiveYN = $ActiveYN and ActiveYN = $Active]">

                <table class="tableMaster" cellpadding="5" cellspacig="5">

                    <tr>
                        <td width="10%">
                            <img src="{ImageURL}" onload='setWidthAndHeightImage(this,"60");' style='display:none;'></img>
                        </td>
                        <td width='25%'>
                            <span>
								<xsl:choose>
									<xsl:when test='$BetaVersion &gt;2.5'>
										<a href="Javascript:void(0)" onclick="LoadActivityDashboard('{$PortalItemID}','{ItemID}','PortalSpecific','1','-3','-1','divClientPortalOperations_Container',1,{$UserID});"
								 style="text-decoration:none;font-family: 'PT Sans' , sans-serif; font-size: 12px; color: #6D6E71; font-weight: 700;">
											<xsl:value-of select="BrandKey"/>
										</a>
									</xsl:when>
									<xsl:otherwise>
										<a href="ClientPortal.aspx?ID={ItemID}" target="_blank"
								 style="text-decoration:none;font-family: 'PT Sans' , sans-serif; font-size: 12px; color: #6D6E71; font-weight: 700;">
											<xsl:value-of select="BrandKey"/>
										</a>
									</xsl:otherwise>
								</xsl:choose>
                              
                            </span>
                        </td>
                        <td width="25%">
                            <span class="publicationSummary">
                                <xsl:value-of select="City"/>
                            </span>
                        </td>
                        <td width="15%">
                            <span class="publicationSummary">
                                <xsl:value-of select="State"/>
                            </span>
                        </td>
                        <td width="10%">
                            <span id="span_{ItemID}_Active" class="publicationSummary onMouseOver"
                                  onclick="document.getElementById('optPortalAdminList_{ItemID}_Active').style.display='inline';
                                                   document.getElementById('span_{ItemID}_Active').style.display='none';">
                                <xsl:choose>
                                    <xsl:when test="ActiveYN = 1">
                                        <xsl:text>Yes</xsl:text>
                                    </xsl:when>
                                    <xsl:otherwise>
                                        <xsl:text>No</xsl:text>
                                    </xsl:otherwise>
                                </xsl:choose>
                            </span>

                            <select id="optPortalAdminList_{ItemID}_Active" class="smallDropdown" style="width:50px;display:none;"
                                    onchange="updatePortalActiveYN('{ItemID}','optPortalAdminList_{ItemID}_Active','span_{ItemID}_Active');">
                                <xsl:choose>
                                    <xsl:when test="ActiveYN = 1">
                                        <option value="1" selected="selected">Yes</option>
                                        <option value="0">No</option>
                                    </xsl:when>
                                    <xsl:otherwise>
                                        <option value="1">Yes</option>
                                        <option value="0" selected="selected">No</option>
                                    </xsl:otherwise>
                                </xsl:choose>
                            </select>
                        </td>
                        <td width="15%">
                            <select id="opt_localOfficeAdmin_{ItemID}" class="smallDropdown" style="width:80px;"
                                    onchange="SelectLocalOfficeAdminOption('{$PortalItemID}','{ItemID}','{BrandID}','opt_localOfficeAdmin_{ItemID}')">
                                <option>-Select-</option>
                                <option value="1">Edit</option>
                                <option value="2">Add Me</option>
                            </select>
                        </td>
                    </tr>
                </table>
            </xsl:for-each>
        </xsl:for-each>
    </xsl:template>

</xsl:stylesheet>

