<%@ 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" %>
<%@ page import="oneit.utils.text.FormatUtils"%>

<%
    Job                     job             =   (Job) process.getAttribute("Job");
    List<JobApplication>    applications    =   (List<JobApplication>) getData(request, "applications");
    String                  currentPage     =   (String) getData(request, "currentPage");
    String                  applicationPage =   WebUtils.getSamePageInRenderMode(request, WebUtils.VIEW_APPLICATION);
%>

<oneit:dynIncluded>
    <script type="text/javascript">
        $(document).ready(function() 
        {            
            $(".app-process").change(function()
            {
                var id  = $(this).closest('.appli-row').attr('id');
                $('.save-application' + id).click();
            });
        });
    </script>
    <div class="view-appli-list">
    <%
        int j   = 0;

        for(JobApplication jobApplication : applications)
        {
            String  jobMatch    =   FormatUtils.stringify(jobApplication.getJobMatchPercentage(), "PercentageWholeNumber", "0");
            String  culture     =   FormatUtils.stringify(jobApplication.getCulturePercentage(), "PercentageWholeNumber", "0");
            String  criteria    =   FormatUtils.stringify(jobApplication.getCriteriaPercentage(), "PercentageWholeNumber", "0");
            String  appID       =   "app-id-" + jobApplication.getID().toString();
    %>
            <div class="appli-row"  id="<%= jobApplication.getID() %>">
                <div class="appli-checkbox appli-l eq-second-height">
                    <div class="checkbox-list">
                        <input type="checkbox"  name="IsSelected" value="<%= jobApplication.getObjectID().toString() %>"  id="<%= appID %>" class="applicant" >
                        <label for="<%= appID %>"></label>
                    </div>
                </div>
                <div class="appli-list-name appli-l eq-second-height">
                    <oneit:button   value=" "   name="gotoPage" cssClass="<%= jobApplication.getID()+"" %>" skin="link"
                                                requestAttribs="<%= CollectionUtils.mapEntry("nextPage", applicationPage)
                                                                                .mapEntry("procParams", CollectionUtils.mapEntry("JobApplication", jobApplication).toMap()).toMap() %>">
                        <oneit:toString value="<%= jobApplication.getCandidate() %>"    mode="EscapeHTML" />
                        <div class="appli-int-status">
                            <oneit:toString value="<%= jobApplication.getApplicantStatusStr() %>"   mode="EscapeHTML" />
                        </div>
                    </oneit:button>
                </div>
                <div class="appli-overall appli-l eq-second-height">
                    <div class="rank">
                        Overall rank
                    </div>
                    <!--TODO: logic needed to be worked out. Added to note that there are three colors-->
                    <div class="<%= "appli-percent-no " + (j == 0 ? "first green" : (j < 3 ? "blue" : "grey" ))%>">
                        <oneit:toString value="<%= jobApplication.getOverallSuitability() %>"   mode="Integer" />
                    </div>
                </div> 
                <div class="appli-jcs appli-l eq-second-height">
                    <span class="appli-view-bar">
                        <div class="progress">
                            <div class="progress-bar" role="progressbar" aria-valuenow="<%= jobMatch %>" aria-valuemin="0" aria-valuemax="100" 
                                    style="<%= "width: " + jobMatch %>">
                            </div>
                        </div>
                    </span>
                    role fit
                </div>
                <div class="appli-jcs appli-l eq-second-height">
                    <span class="appli-view-bar">
                        <div class="progress">
                            <div class="progress-bar" role="progressbar" aria-valuenow="<%= culture %>" aria-valuemin="0" aria-valuemax="100" 
                                    style="<%= "width: " + culture %>">
                            </div>                                
                        </div>
                    </span>
                    culture fit
                </div>
                <div class="appli-jcs appli-l eq-second-height">
                    <span class="appli-view-bar">
                        <div class="progress">
                            <div class="progress-bar" role="progressbar" aria-valuenow="<%= criteria %>" aria-valuemin="0" aria-valuemax="100" 
                                    style="<%= "width: " + criteria %>">
                            </div>
                        </div>
                    </span>
                    requirements
                </div>
                <div class="appli-status appli-l eq-second-height">
                    <div class="appli-list-drop">
                        <oneit:ormEnum  obj="<%= jobApplication %>" attributeName="AppProcessOption"    cssClass="form-control app-process"   
                                        enums="<%= jobApplication.getValidProcessOptions() %>"/>
                    </div>
                </div> 
                <oneit:button   name="changeApplicationStatus"  value=" "   cssClass="<%= "save-application" +  jobApplication.getID().toString() + " hidden"%>"
                                requestAttribs="<%= CollectionUtils.mapEntry("nextPage", currentPage)
                                                                    .mapEntry ("restartProcess", Boolean.TRUE)
                                                                    .mapEntry ("attribNamesToRestore", Collections.singleton("Job"))
                                                                    .mapEntry("JobApplication", jobApplication)
                                                                    .toMap() %>" />
            </div>
    <%
            j++;
        }
    %>
    </div>
</oneit:dynIncluded>
