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

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

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

<%
    ORMProcessState             process     =   (ORMProcessState)ProcessDecorator.getDefaultProcess(request);
    ObjectTransaction           objTran     =   process.getTransaction ();
    Job                         job         =   (Job) process.getAttribute("Job");
    AssessmentCriteriaTemplate  template    =   (AssessmentCriteriaTemplate) process.getAttribute("AssessmentCriteriaTemplate");
    int                         sortOrder   =   job != null ? job.getWorkFlowsCount() : template.getWorkFlowsCount();
    ApplicationStatus           status      =   Utils.getApplicationStatus(sortOrder);
    WorkFlow                    workflow    =   null;

    if(sortOrder < 9 && status != null)
    {
        workflow    =   WorkFlow.createWorkFlow(objTran);

        workflow.setApplicationStatus(status);
        workflow.setSortOrder(sortOrder);

        if(job != null)
        {
            job.addToWorkFlows(workflow);
        }
        else
        {
            template.addToWorkFlows(workflow);
        }
%>

    <oneit:form method="POST">

        <oneit:evalBody buffer="<%= getBuffer(request) %>">
        <%
            FormTag     myForm          =   FormTag.getActiveFormTag(request);
            FormBuilder formBuilder     =   myForm.getFormBuilder();
            String      deleteVarKey    =   FormTag.getVariableKey (request);

            FormTag.setVariable (request, deleteVarKey, "objToDelete", workflow);
            FormTag.setVariable (request, deleteVarKey, "jqToDelete", "#" + workflow.getID());
        %>
            <div class="form-group row" id="<%= workflow.getID() %>">
                <div class="col-md-12">
                    <div class="workflow-row">
                        <span><%= workflow.getSortOrder() %></span>
                        <oneit:ormInput obj="<%= workflow %>"    type="text" attributeName="Name"    cssClass="form-control" /> 
                        <div class="remove-icon" onclick="return deleteWorkflow (<%= deleteVarKey %>)">_</div>
                    </div>
                </div>
            </div>
        </oneit:evalBody>

    </oneit:form>
<%
    }
%>