<%@ page extends="oneit.servlets.process.AJAXProcessJSP" %>

<%@ include file="/inc/stdimports50.jsp" %><%-- This is in cougar --%>
<%@ include file="/extensions/performa/inc/stdimports.jsp" %>
<%@ page import="oneit.utils.text.FormatUtils" %>

<%! protected String getName (ServletConfig config) { return "job_match_questions_jsp"; } %>

<%
    ORMProcessState     process         =   (ORMProcessState) ProcessDecorator.getDefaultProcess(request);
    ObjectTransaction   objTran         =   process.getTransaction ();
    JobApplication      jobApplication  =   (JobApplication) process.getAttribute("JobApplication");
    Job                 job             =   jobApplication.getJob();
    List<Question>      totalQuestions  =   (List<Question>) process.getAttribute("TotalQuestions");
    List<Question>      allQuestions    =   (List<Question>) process.getAttribute("AllQuestions");
    int                 actualNumber    =   request.getParameter ("actualNumber") != null ? Integer.valueOf(request.getParameter ("actualNumber")) : (int) getData(request, "actualNumber")  ;
    int                 questionNumber  =   request.getParameter ("questionNumber") != null ? Integer.valueOf(request.getParameter ("questionNumber")) : (int) getData(request, "questionNumber")  ;
    Question            question        =   allQuestions.get(questionNumber);
    QuestionType        questionType    =   question.getQuestionType();
    String              exitPage        =   WebUtils.getArticleLink(request, objTran, WebUtils.APPLY_JOB, "Page") + "&id=" + job.getID() + "&key=" + job.getRandomKey();
    String              currentPage     =   WebUtils.getArticleLink(request, objTran, WebUtils.JOB_APPLICATION, "JobMatchAssessment");
    String              nextPage        =   WebUtils.getArticleLink(request, objTran, WebUtils.JOB_APPLICATION, "SubmitApplication");

%>

<oneit:form name="editApplication"   method="POST">
    
    <oneit:evalBody buffer="<%= getBuffer(request) %>">
        <%
            if(actualNumber == 1 )
            {
                int     maxRating   =   7;
                int     midRating   =   4;
                String  otherRating =   "2, 3, 5, 6";
        %>
                <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><oneit:toString value="<%= midRating %>"  mode="EscapeHTML"/> means about average in importance to you</li>
                        <li><oneit:toString value="<%= maxRating %>"  mode="EscapeHTML"/> means of high importance to you</li>
                    </ul>
                    <p>Use the other numbers (<oneit:toString value="<%= otherRating %>"    mode="EscapeHTML"/>) to indicate in-between levels of importance to you.</p>            
                </div>
                <div class="selection-br-line"></div>
        <%
            }
            else if(questionType == QuestionType.IPSATIVE && actualNumber == 31)
            {
        %>
                <div class="main-sc-section sj-1">
                    <p>
                        For questions like these, indicate your preference by selecting the number closest to the term or idea that's most like you. We know that it can be challenging to make a choice sometimes, but try to avoid selecting the middle value.
                    </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    =   totalQuestions.size();

            if(actualNumber <= totNoOfQuestions)
            {
                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          =   actualNumber + "/" + totNoOfQuestions;
                boolean     completeApplication =   questionNumber + 1 >= allQuestions.size();

                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" : "");
                            int         actNumber   =   questionType == QuestionType.SCALAR ?  actualNumber + 1 : actualNumber + 2;
                    %>
                            <li class="<%= activeStr +  ((questionType == QuestionType.SCALAR) ?  "scaler" : "ipsative")%>">
                                <a href="javascript:void(0);">
                                    <input  type="radio"    name="<%= optionKey %>" id="<%= index %>"   onchange="gotoNextQuestion(<%= questionNumber + 1 %> , <%= actNumber %>, <%= completeApplication %>, <%= answer.getFinalAnswerValue(index) %>);"   class="answer_radio"    value="<%= answer.getFinalAnswerValue(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 class="section-btn text-center">
                    <oneit:button   value="Save and exit"   name="saveAndExitWorkStyle" id="saveAndExitWorkStyle" cssClass="<%= (!completeApplication) ? "box-btn-gray" : "box-btn-gray half-btn" %>"
                                    requestAttribs="<%= CollectionUtils.mapEntry("nextPage", exitPage)
                                                                        .mapEntry ("JobApplication", jobApplication)
                                                                        .mapEntry(UpdateMappedObjFP.FAIL_VALIDATION_ERRORS, Boolean.FALSE)
                                                                        .toMap() %>"/>

                    
                </div>
        <%
            }
        %>
            <div class="auto-save">
                <%-- <div>Autosaved 1 min ago.</div> --%>
            </div>
        </div>
    </oneit:evalBody>
       
</oneit:form>