<%@ page extends="oneit.servlets.jsp.JSPInclude" %>

<%@ include file="/inc/stdimports50.jsp" %><%-- This is in cougar --%>
<%@ include file="/inc/stdcms.jsp" %><%-- This is in cougar --%>
<%@ include file="/extensions/performa/inc/stdimports.jsp" %>
 
<oneit:dynIncluded>
<%
    String      nextPage    =   WebUtils.getSamePageInRenderMode(request, WebUtils.EDIT_CULTURE);
    SecUser     secUser     =   SecUser.getTXUser(transaction);
    CompanyUser companyUser =   secUser.getExtension(CompanyUser.REFERENCE_CompanyUser);
    HiringTeam  hiringTeam  =   companyUser.getSelectedTeam();
    Map<String, String[]>   parameterMap    =   request.getParameterMap();
    Client                  selectedClient  =   null;

    String              clientPage      =   WebUtils.getSamePageInRenderMode(request, "Page");
    ClientSortOption    clientSortOpt   =   (ClientSortOption) process.getAttribute("ClientSortOption");
    Client[]            clients         =   (Client[]) process.getAttribute("Clients");

    CultureCriteriaTemplate[]   templates   =   (CultureCriteriaTemplate[]) process.getAttribute("CultureCriteriaTemplates");

    if( request.getParameter("ClientSortOption") != null)
    {
        clientSortOpt  =   ClientSortOption.forName((String) request.getParameter("ClientSortOption"));
    }
    
    if(clientSortOpt == null)
    {
        clientSortOpt   =   ClientSortOption.ALPHA_A_Z;
    }
    
    if(templates == null)
    {
        templates   =   CultureCriteriaTemplate.SearchByAll()
                                                .andHiringTeam(new EqualsFilter<>(hiringTeam))
                                                .andCompanyUser(new EqualsFilter<>(companyUser))
                                                .search(transaction);
        
        process.setAttribute("CultureCriteriaTemplates", templates);
    }
     
    // handle client
    if( parameterMap.containsKey("Client"))
    {
        if(!request.getParameter("Client").isEmpty())
        {
            selectedClient  =   Client.getClientByID(transaction, Long.valueOf(request.getParameter("Client")));
        }
    }
    else
    {
        selectedClient  =   (Client) session.getAttribute("Client");
    }
    
    session.setAttribute("Client", selectedClient);
 
    if(clients == null)
    {
        clients =   Utils.getClientsByHiringTeam(transaction);
        
        process.setAttribute("Clients", clients);
    }
    List<Client>    sortedClients   =   Utils.getClientsSorted(clients, clientSortOpt);
    
    process.setAttribute("ClientSortOption", clientSortOpt);
%>
    <oneit:form name="cultureTemplates" method="post"    enctype="multipart/form-data">

        <div class="dashboard-content-area second-part">
                        
            <div class="jobs-list-shorting">
                <div class="d-job-title all-jobs-title">Manage Culture Templates</div>
                <%
                    if(false)
                    {
                %>
                    <div class="shorting-dropdown">
                        <span class="order-label">Select Client</span>
                        <select class="form-control"    onChange="location=this.value">
                            <%
                                for (ClientSortOption  sortOption : ClientSortOption.getClientSortOptionArray())
                                {
                                    String  optionLink  =    clientPage + "&ClientSortOption=" + sortOption.getName() ;
                            %>
                                    <option <%= (clientSortOpt != null && clientSortOpt == sortOption ? "selected" : "" )%>  value="<%= optionLink %>">
                                        <oneit:toString value="<%= sortOption.getDescription() %>"   mode="EscapeHTML"/>
                                    </option>
                            <%
                                }
                            %>
                        </select>
                    </div>
                <%
                    }
                %>
            </div>
            
                    
            <div class="main-client-list">
            <%
                for(CultureCriteriaTemplate template : templates)
                {
            %>
                    <div class="template-list"   id="<%= template.getID() %>">
                        <div class="template-row">
                            <div class="job-template-left job-template-cl1 culture">
                                <div class="template-name heading">
                                    <oneit:toString value="<%= template.getTemplateName() %>" mode="EscapeHTML" />
                                </div>
                            </div>
                            <div class="job-template-left job-template-cl2">
                                <span class="grey-span">CLIENT</span>
                                <div class="template-name">
                                    <oneit:toString value="<%= template.getClient() %>" mode="EscapeHTML" />
                                </div>
                            </div>
                            <div class="job-template-left job-template-cl4">
                                <span class="grey-span">LAST UPDATED</span>
                                <div class="template-name">
                                    <oneit:toString value="<%= template.getObjectLastModified() %>" mode="MidDate" />
                                </div>
                                <div class="m-user-right-padlock">
                                    <oneit:button   value=" "    name="gotoPage"    skin="link"
                                            requestAttribs="<%= CollectionUtils.mapEntry("nextPage", nextPage + "&CultureCriteriaTemplateID=" + template.getObjectID())
                                                                                .mapEntry("procParams", CollectionUtils.mapEntry("CultureCriteriaTemplate", template).toMap())
                                                                                .toMap() %>">
                                        <span class="m-user-right-padlockicon">
                                            <span class="pencil"></span>
                                        </span>
                                    </oneit:button>
                                </div>
                            </div>
                        </div>
                    </div>
            <%
                }
            %>
            </div>
        </div>
    </oneit:form>
</oneit:dynIncluded>