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

<%@ include file="/inc/stdimports50.jsp" %><%-- This is in cougar --%>
<%@ include file="/inc/std_imports.jsp" %>

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

<%
    ORMProcessState     process         = (ORMProcessState)ProcessDecorator.getDefaultProcess(request);
    ObjectTransaction   objTran         = process.getTransaction ();
    Job                 job             = (Job) process.getAttribute("Job");
    AssessmentCriteria  criteria        = (AssessmentCriteria) getData(request, "AssessmentCriteria");
    CriteriaType        criteriaType    = (CriteriaType) getData(request, "CriteriaType");
    
    if(criteria == null)
    {
        criteria        =   AssessmentCriteria.createAssessmentCriteria(objTran);
        criteriaType    =   CriteriaType.forName((String) request.getParameter("CriteriaName"));

        criteria.setCriteriaType(criteriaType);
        job.addToAssessmentCriterias(criteria);
    }
%>

<oneit:form method="POST">
    
    <oneit:evalBody buffer="<%= getBuffer(request) %>">
    <%
        FormTag     myForm      =   FormTag.getActiveFormTag(request);
        FormBuilder formBuilder =   myForm.getFormBuilder();
        String      optionKey   =   WebUtils.getInputKey(request, criteria, AssessmentCriteria.FIELD_Importance);
        String      formValue   =   formBuilder.fieldValue (optionKey, criteria.getImportance() == null ? "" : criteria.getImportance().getName());
    %>        
       <div class="main-qualification">
            <span class="delete-qualification"><span></span></span>
            <oneit:ormInput obj="<%= criteria %>"  type="text" attributeName="Name"    cssClass="form-control" />
            <%
                for(Importance importance : Importance.getImportanceArray())
                {
                    boolean isSelected  = CollectionUtils.equals(formValue, importance.getName());
                    String  id          = "importance_" + importance.getName();
                    String  selectedStr = (isSelected) ? "checked" : "";
            %>
                    <div class="radio radio-primary qualification-radio">
                        <input type="radio" name="<%= optionKey %>" value="<%= importance.getName() %>" id="<%= id %>" <%= selectedStr %>/>
                        <label for="<%= id %>"><oneit:toString value="<%= importance %>" mode="EscapeHTML" /></label>
                    </div>
            <%
                }
            %>
        </div>
        
    </oneit:evalBody>
       
</oneit:form>