<%@ 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" %>

<oneit:dynIncluded>
<%
    String          currentPage     =   WebUtils.getSamePageInRenderMode(request, "JobMatchAssessment");
    String          nextPage        =   WebUtils.getSamePageInRenderMode(request, "SubmitApplication");
    JobApplication  jobApplication  =   (JobApplication) process.getAttribute("JobApplication");
    Job             job             =   jobApplication.getJob();
    int             questionNumber  =   process.getAttribute("QuestionNumber")!= null ? (int) process.getAttribute("QuestionNumber") : 0;
    String          sectionNo       =   jobApplication.isIncludeAssessmentCriteria() ? "3" : "2";
    List<Question>  allQuestions    =   (List<Question>) process.getAttribute("AllQuestions");
    
    if(allQuestions == null)
    {
        allQuestions    =   job.getAllLeftQuestions();
        
        process.setAttribute("AllQuestions", allQuestions);
    }
    
    boolean toRedirect  =   jobApplication.initAssessmentAnswers(allQuestions);
    
    if(toRedirect)
    {
        %><%@include file="/saferedirect.jsp" %><%
    }
%>
    <script>
        $(document.body).addClass('bg-color');
        
        $(document).ready(function(){
            
            $(".answer_radio").change(function(){
                $(".ratting-number li.active").removeClass("active" );
                $(".ratting-number input[type='radio']:checked").closest('li').addClass("active" );
            });
        });
    </script>
    
    <div class="main-application-outline">
        <div class="selection-aust-logo">
            <img src="images/australia-post.png" />
            <span><oneit:toString value="<%= job.getJobTitle() %>"  mode="EscapeHTML"/></span>
        </div>
        <div class="show-mobile-title">
            <div class="mobile-title-page">Profile Assessment</div>
            <div class="mobile-estimated">Estimated time to complete: 
                <span class="estimated-time-20">&nbsp;20 mins</span>
            </div>
        </div>
        <div class="section-c-title m-hide">
            Profile Assessment
            <span>Estimated time to complete: 
                <span class="estimated-time-20">&nbsp;20 mins</span>
            </span>
        </div>
        <div class="section-tab-view">
            
            <oneit:form name="editApplication"  method="post"   enctype="multipart/form-data">
            
                <oneit:dynInclude   page="/extensions/applicantportal/inc/multifieldtext.jsp"           data="<%= CollectionUtils.EMPTY_MAP%>"/>
                
                <oneit:dynInclude   page="/extensions/applicantportal/inc/application_main_tabs.jsp"    PageNumber="3"  data="<%= CollectionUtils.EMPTY_MAP%>"/>

                <div class="section-page-area section-job-match">
                    <div class="main-sc-section sj-1">
                        <p>Using the scale given, indicate how important to you are the following aspects in your work life. Use the following system:</p>
                        <ul class="security-level">
                            <li><span>1</span> means of very little importance to you</li>
                            <li><span>4</span> means about average in importance to you</li>
                            <li><span>7</span> means of high importance to you</li>
                        </ul>
                        <p>Use the other numbers (2, 3, 5, 6) to indicate in-between levels of importance to you.</p>            
                    </div>
                    <div class="selection-br-line"></div>
                    <div class="main-sc-section main-rate-section">
                    <%
                        FormTag     applicationForm     =   FormTag.getActiveFormTag(request);
                        FormBuilder formBuilder         =   applicationForm.getFormBuilder();
                        int         totNoOfQuestions    =   allQuestions.size();

                        if(questionNumber < totNoOfQuestions)
                        {
                            Question        question        =   allQuestions.get(questionNumber);
                            QuestionType    questionType    =   question.getQuestionType();
                            Answer          answer          =   jobApplication.getAnswerForQuestion(question);
                            String          optionKey       =   WebUtils.getInputKey(request, answer, Answer.FIELD_AnswerNo);
                            String          formValue       =   formBuilder.fieldValue (optionKey, answer.getAnswerNo() == null ? "" : String.valueOf(answer.getAnswerNo()));
                            String          numberText      =   (questionNumber + 1) + "/" + totNoOfQuestions;

                            if(questionType == QuestionType.SCALAR)
                            {
                        %>    
                                <div class="rateing-title">
                                    Rate the importance of each item below
                                    <span><oneit:toString value="<%= numberText %>"   mode="EscapeHTML"/></span>
                                </div>
                                
                                <div class="rating-box-title">
                                    <oneit:toString value="<%= question.getDescription() %>"    mode="EscapeHTML"/>
                                </div>
                        <%
                            }
                            else
                            {
                        %>    
                                <div class="rateing-title">
                                    Select your preference on the scale below 
                                    <span><oneit:toString value="<%= numberText %>"   mode="EscapeHTML"/></span>
                                </div>
                        <%
                            }
                        %>
                            <div class="ratting-box">
                            <%
                                if(questionType == QuestionType.SCALAR)
                                {
                            %>
                                    <span>Very little importance</span>
                            <%
                                }
                                else
                                {
                            %>
                                    <span class="left-s-label"><div><%= FormatUtils.stringify(question.getDescription(), "EscapeHTML") %></div></span> <!-- toString tag not used due to styling issue with additional span tag -->
                            <%
                                }
                            %>
                                <ul class="pagination ratting-number">
                                <%
                                    for(int index=1; index <= (questionType == QuestionType.SCALAR ? 7 : 5); index++)
                                    {
                                        String  activeStr   = (CollectionUtils.equals(String.valueOf(index), formValue) ? "active" : "");
                                        String  selectedStr = (CollectionUtils.equals(String.valueOf(index), formValue) ? "checked" : "");
                                %>
                                        <li class="<%= activeStr %>">
                                            <a href="javascript:void(0);">
                                                <input  type="radio"    name="<%= optionKey %>" id="<%= index %>"   class="answer_radio"    value="<%= index %>" <%= selectedStr %>>
                                                <label  for="<%= index %>"><%= index %></label>
                                            </a>
                                        </li>
                                <%
                                    }
                                %>
                                </ul>
                            <%
                                if(questionType == QuestionType.SCALAR)
                                {
                            %>
                                    <span>High importance</span>
                            <%
                                }
                                else if(question.getRightQuestion() != null)
                                {
                            %>
                                    <span class="right-s-label"><div><%= FormatUtils.stringify(question.getRightQuestion().getDescription(), "EscapeHTML") %></div></span>
                            <%
                                }
                            %>
                            </div>
                    <%
                        }
                    %>
                        <div>
                            <span style="float: left">
                            <%
                                if(questionNumber>0)
                                {
                            %>
                                    <oneit:button   value="Previous"    name="gotoPage" cssClass="box-btn-gray" 
                                                    requestAttribs="<%= CollectionUtils.mapEntry("nextPage", currentPage)
                                                                                    .mapEntry("procParams", CollectionUtils.mapEntry("QuestionNumber", (questionNumber - 1)).toMap())
                                                                                    .toMap() %>"/>
                            <%
                                }
                            %>
                            </span>
                            <span style="float: right">
                            <%
                                if((questionNumber+1)<totNoOfQuestions)
                                {
                            %>
                                    <oneit:button   value="Next"    name="gotoPage" cssClass="box-btn" 
                                                    requestAttribs="<%= CollectionUtils.mapEntry("nextPage", currentPage)
                                                                                    .mapEntry("procParams", CollectionUtils.mapEntry("QuestionNumber", (questionNumber + 1)).toMap())
                                                                                    .toMap() %>"/>
                            <%
                                }
                            %>
                            </span>
                        </div>
                        <div class="auto-save">
                        <%
                            if((questionNumber+1) == totNoOfQuestions)
                            {
                        %>
                                <oneit:button   value="Complete"    name="completeApplication"  cssClass="box-btn"
                                                requestAttribs="<%= CollectionUtils.mapEntry("nextPage", nextPage)
                                                                                .mapEntry("procParams", CollectionUtils.mapEntry("JobApplication", jobApplication).toMap())
                                                                                .mapEntry("attribNamesToRestore", Collections.singleton("JobApplication"))
                                                                                .mapEntry("restartProcess", Boolean.TRUE)
                                                                                .toMap() %>"/>
                        <%
                            }
                        %>
                            <%-- <div>Autosaved 1 min ago.</div> --%>
                        </div>
                    </div>                      
                </div>
            </oneit:form>
        </div>
    </div>
</oneit:dynIncluded>