<%@ 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>
<%
    Job     job         =   (Job) process.getAttribute("Job");
    String  fourthPage  =   WebUtils.getSamePageInRenderMode(request, WebUtils.JOB_MATCH);

    Debug.assertion(job != null, "Job is null in admin portal create job");
%>
    
    <script type="text/javascript">
        
        function moveImportanceSection(elementRating){
            
            var importanceDiv   =   $(elementRating).closest('.criteria_section').find('.work-rating');
            var radioGroup      =   $("[name='" + $(elementRating).attr('name') +"']");
            
            if(radioGroup.is(':checked')){
                importanceDiv.insertAfter($("[name='" + $(elementRating).attr('name') +"']:checked").parent());
                importanceDiv.show();
            }
            else{
                importanceDiv.hide();
            }
        }
        
        $(document).ready(function(){
            
            $(".element_rating_radio").each(function (){
                moveImportanceSection(this);
            });
            
            $(".element_rating_radio").change(function(){
                moveImportanceSection(this);
            });
            
            $(".importance_radio").change(function(){
                var importanceGroup =   $(this).closest('.rate-toggle');
                
                importanceGroup.find('li.active').removeClass("active" );
                importanceGroup.find("input[type='radio']:checked").closest('li').addClass("active" );
            });
        });
        
    </script>
    
    <oneit:form name="editJob" method="post" enctype="multipart/form-data">
    
        <div class="container-fluid">
                 
            <oneit:dynInclude   page="/extensions/applicantportal/inc/multifieldtext.jsp"   data="<%= CollectionUtils.EMPTY_MAP%>"/>
            
            <h1 class="page-title">Create a job <span class="active-time">(Active for 30 days)</span> </h1>
       
            <oneit:dynInclude   page="/extensions/adminportal/inc/job_main_tabs.jsp"    PageNumber="3"    data="<%= CollectionUtils.EMPTY_MAP%>"/>

            <div class="form-page-area">
                <div class="create-job">
                    <div class="assessment-criteria">
                        <div class="form-group">
                            <label class="label-16 work-title">Workplace Culture</label>
                            <p>
                              Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit.
                            </p>      
                        </div>
                        <div class="form-group">
                            <select class="form-control">
                                <option>Optional: Select previously defined Workplace Culture</option>
                                <option>One 1</option>
                                <option>One 2</option>
                                <option>One 3</option>
                          </select>              
                        </div>              
                        <div class="form-brack-line-sub"></div> 
                    <%
                        FormTag     jobForm     = FormTag.getActiveFormTag(request);
                        FormBuilder formBuilder = jobForm.getFormBuilder();

                        job.pipelineJob().toCultureCriterias().toCultureElement().toRatings().uniqueVals(); //preloading data

                        for(CultureClass cultureClass : CultureClass.getCultureClassArray())
                        {
                    %>
                            <div class="form-group">
                                <div class="work-belonging">
                                    <oneit:toString value="<%= cultureClass %>" mode="EscapeHTML"/>
                                </div>
                            <%
                                for(CultureCriteria criteria : job.getCultureCriteriasForClass(cultureClass))
                                {
                                    String  optionKey   = WebUtils.getRadioSingleAssocKey(request, criteria, CultureCriteria.SINGLEREFERENCE_CultureElementRating);
                                    String  formValue   = formBuilder.fieldValue (optionKey, criteria.getCultureElementRating() == null ? "" : String.valueOf(criteria.getCultureElementRatingID()));
                            %>
                                    <div class="criteria_section culture-margin-bottom">
                                        <div class="work-radio-title">
                                            <oneit:toString value="<%= criteria.getCultureElement() %>" mode="EscapeHTML"/>
                                        </div>
                                    <%
                                        for (CultureElementRating rating : criteria.getCultureElement().getRatingsSet())
                                        {
                                            String  ratingId    = String.valueOf(rating.getID().longID());
                                            String  selectedStr = (CollectionUtils.equals(ratingId, formValue) ? "checked" : "");
                                    %>
                                            <div class="<%= "radio radio-primary workplace-radio " %>">
                                                <input type="radio" name="<%= optionKey %>" id="<%= ratingId %>"    class="element_rating_radio"    value="<%= ratingId %>" <%= selectedStr %> >
                                                <label for="<%= ratingId %>">
                                                    <oneit:toString value="<%= rating %>"   mode="EscapeHTML"/>
                                                </label>
                                            </div>
                                    <%
                                        }
                                    %>
                                        <div class="work-rating">
                                            <div class="rate-background">
                                                <span class="arrow-up-gray"></span>
                                                <span class="rate-label">
                                                    <oneit:ormlabel  obj="<%= criteria %>"   field="Importance" />
                                                </span>
                                                <span class="rate-toggle">
                                                    <ul class="nav nav-pills nav-justified">
                                                    <%
                                                        String  importanceKey   =   WebUtils.getInputKey(request, criteria, CultureCriteria.FIELD_Importance);
                                                        String  importanceValue =   formBuilder.fieldValue (importanceKey, criteria.getImportance() == null ? "" : criteria.getImportance().getName());

                                                        for(Importance importance : Importance.getImportanceArray())
                                                        {
                                                            boolean isSelected      =   CollectionUtils.equals(importanceValue, importance.getName());
                                                            String  importanceId    =   String.valueOf(criteria.getID().longID()) + "_importance_" + importance.getName();
                                                            String  selected        =   isSelected ? "checked" : "";
                                                            String  activeClass     =   isSelected ? "active" : "";
                                                    %>
                                                            <li class="<%= activeClass%>">
                                                                <a href="javascript:void(0)" class="importance">

                                                                    <input type="radio" name="<%= importanceKey %>" id="<%= importanceId %>"    class="importance_radio"    value="<%= importance.getName() %>" <%= selected %>/>
                                                                    <label for="<%= importanceId %>"><oneit:toString value="<%= importance %>" mode="EscapeHTML" /></label>
                                                                </a>
                                                            </li>
                                                    <%
                                                        }
                                                    %>
                                                    </ul>
                                                </span>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="form-brack-line-sub"></div>
                            <%
                                }
                            %>
                            </div>
                    <%
                        }
                    %>
                        
                        <div class="form-group">
                            <div class="save-assess">
                                <div class="checkbox checkbox-primary">
                                    <input id="checkbox2" type="checkbox" checked>
                                    <label for="checkbox2">
                                      Save this Assessment Criteria as a template
                                    </label>
                                </div>
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="input-group input-group-lg">                    
                                <div class="icon-addon addon-lg">
                                    <input type="text" placeholder="Template Name" class="form-control" id="email">
                                </div>
                                <span class="input-group-btn">
                                    <a href="#" class="btn btn-primary">SAVE</a>    <!-- todo -->
                                </span>
                            </div>
                        </div>
                        <div class="text-center">
                            <oneit:button   value="Proceed to Job Match"    name="gotoPage" cssClass="btn btn-primary top-margin-25 largeBtn"
                                            requestAttribs="<%= CollectionUtils.mapEntry("nextPage", fourthPage)
                                                                            .mapEntry("procParams", CollectionUtils.mapEntry("Job", job).toMap())
                                                                            .toMap() %>" />
                        </div>
                    </div>
                </div>
            </div>                                    
        </div>
    </oneit:form>
</oneit:dynIncluded>