<%@ 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>
<%
    boolean toRedirect  =   GenericObjDF.getOrCreateObject (request, "Client", Client.REFERENCE_Client);
    Client  client      =   (Client) process.getAttribute("Client");

    if (toRedirect)
    {
        SecUser     loggedInUser    =   SecUser.getTXUser(transaction);
        CompanyUser companyUser     =   loggedInUser.getExtension(CompanyUser.REFERENCE_CompanyUser);

        client.setCompany(companyUser.getCompany());

        %><%@include file="/saferedirect.jsp"%><%
    }

    Debug.assertion(client != null && !toRedirect, "Invalid client in admin portal edit client");
    
    String  nextPage    =   WebUtils.getSamePageInRenderMode(request, "Page");
%>

    <script>
        $(document).ready(function() 
        {
            recalcFunction = setupRecalc ($("editClient"), {'recalcOnError':true});

            $("#upload").change(function(){
                readURL(this);
            });

            $("#remove-logo").click(function(){
               removeLogo();
            });
        });
    </script>
    <div class="container-fluid">
        <div class="row content">
            <div class="main-content-area">
                <h1 class="page-title"><%= "Client" + (client.getClientName() != null ? " - " + client.getClientName() : "") %></h1>  
                <div class="client-form-area">
                    <oneit:form name="editClient" method="post"    enctype="multipart/form-data">
                        <div style="padding-left: 15px; padding-right: 15px;">
                            <oneit:dynInclude   page="/extensions/applicantportal/inc/multifieldtext.jsp"   data="<%= CollectionUtils.EMPTY_MAP%>"/>
                        </div>
                        <div class="form-group">
                            <label><oneit:label GUIName="Client Name" /></label>
                            <oneit:ormInput obj="<%= client %>" type="text" attributeName="ClientName"   cssClass="form-control" />                                
                        </div>
                        <div class="form-group">
                            <label><oneit:ormlabel  obj="<%= client %>" field="ClientLogo" /></label>
                            <div class="main-upload-logo">
                                <span class="u-img-tag" style="<%= client.getClientLogo() != null ? "" : "display: none" %>">
                                    <tagfile:img    src="<%= ThumbnailUtils.filterImage(DiskFileBinaryContent.getRelativeURL(client.getClientLogo()), "KEEP", new ScaleWithin (0,90)) %>"
                                                    class="upload-img-w-h"  id="client-logo"/>
                                    <span class="remove-logo-btn">
                                        <img src="images/logo-remove-btn.png" id="remove-logo">
                                        <oneit:ormInput obj="<%= client %>" type="text" attributeName="IsLogoDeleted"  style="display:none;" />
                                    </span>
                                </span>

                                <span class="up-rep-btn">
                                    <oneit:ormInput obj="<%= client %>" type="file" attributeName="ClientLogo"  accept="image/*"    id="upload"
                                                    style="visibility: hidden; width: 1px; height: 1px"/>
                                    <a href="javascript:void(0)" onclick="document.getElementById('upload').click(); return false" id="replace-btn">
                                        <%= client.getClientLogo() != null ? "Replace" : "Upload" %>
                                    </a>
                                </span>
                            </div>
                        </div>

                        <div class="form-brack-line-sub"></div>

                        <div class="form-group">
                            <label><oneit:ormlabel  obj="<%= client %>" field="Email" /></label>
                            <oneit:ormInput obj="<%= client %>" type="text" attributeName="Email"   cssClass="form-control" />                                
                        </div>
                        <div class="form-group row">
                            <div class="col-md-6">
                                <label><oneit:ormlabel  obj="<%= client %>" field="ContactName" /></label>
                                <oneit:ormInput obj="<%= client %>" type="text" attributeName="ContactName"   cssClass="form-control" />                                
                            </div>
                            <div class="col-md-6">
                                <label><oneit:ormlabel  obj="<%= client %>" field="ContactSurname" /></label>
                                <oneit:ormInput obj="<%= client %>" type="text" attributeName="ContactSurname"   cssClass="form-control" />                                
                            </div>
                        </div>
                        <div class="form-group">
                            <label><oneit:ormlabel  obj="<%= client %>" field="Phone" /></label>
                            <oneit:ormInput obj="<%= client %>" type="text" attributeName="Phone"   cssClass="form-control" />                                
                        </div>

                        <div class="form-brack-line-sub"></div>

                        <div class="form-group row">
                            <div class="col-md-4">
                                <label><oneit:ormlabel  obj="<%= client %>" field="Country" /></label>
                                <oneit:ormEnum  obj="<%= client %>"    attributeName="Country" cssClass="form-control"/>
                            </div>
                            <div class="col-md-4">
                                <label><oneit:ormlabel  obj="<%= client %>" field="State" /></label>
                                <oneit:ormEnum  obj="<%= client %>" attributeName="State" cssClass="form-control"/>
                            </div>
                            <div class="col-md-4">
                                <label><oneit:ormlabel  obj="<%= client %>" field="PostCode" /></label>
                                <oneit:ormInput obj="<%= client %>" type="text" attributeName="PostCode"    cssClass="form-control" />      
                            </div>
                        </div>
                        <div class="form-group row">
                            <div class="col-md-6">
                                <label><oneit:ormlabel  obj="<%= client %>" field="City" /></label>
                                <oneit:ormInput obj="<%= client %>" type="text" attributeName="City"    cssClass="form-control" />      
                            </div>
                            <div class="col-md-6">
                                <label><oneit:ormlabel   obj="<%= client %>"   field="TimeZone"/></label>
                                <oneit:ormEnum  obj="<%= client %>" attributeName="TimeZone"    cssClass="form-control"/>
                            </div>
                        </div>
                        <div class="text-center form-group">
                            <oneit:button   value="Save Updates"    name="saveClient"   cssClass="btn btn-primary largeBtn"
                                            requestAttribs="<%= CollectionUtils.mapEntry("nextPage", nextPage).toMap() %>" />
                        </div> 
                    </oneit:form>
                </div>
            </div>
        </div>
    </div>
</oneit:dynIncluded>
