Search in sources :

Example 21 with FormProperty

use of org.activiti.engine.form.FormProperty in project my_curd by qinyou.

the class ActivitiUtils method getRenderedTaskFrom.

/**
 * 获得任务办理表单
 *
 * @param task
 * @return
 */
public static String getRenderedTaskFrom(Task task) {
    // 简单拼字符逻辑
    StringBuilder renderedForm = new StringBuilder("");
    String formKey = task.getFormKey();
    if (StringUtils.notEmpty(formKey)) {
        // 常用表单简化
        renderedForm.append("<tr> <td>审批结果:</td><td> ");
        for (String key : formKey.split(",")) {
            String temp = null;
            switch(key) {
                case "YES":
                    temp = "<input class='easyui-radiobutton'  checked='true' name='PROCESS_approve_审批结果' value='同意' label='同意' labelPosition='after' >";
                    break;
                case "NO":
                    temp = "<input style='margin-right:50px' class='easyui-radiobutton' name='PROCESS_approve_审批结果' value='拒绝' label='拒绝' labelPosition='after' >";
                    break;
            }
            if (temp != null) {
                log.info("temp: {}", temp);
                renderedForm.append(temp);
            }
        }
        renderedForm.append("</td></tr>");
    } else {
        // 动态表单处理
        List<FormProperty> formProperties = getFormService().getTaskFormData(task.getId()).getFormProperties();
        for (FormProperty formProperty : formProperties) {
            // 日期类型渲染
            if (formProperty.getType() instanceof DateFormType) {
                renderedForm.append("<tr><td>").append(formProperty.getName()).append("</td><td>");
                String datePattern = (String) formProperty.getType().getInformation("datePattern");
                String domClass;
                // 仅支持 date 或 dateTime 常用格式
                switch(datePattern) {
                    case "yyyy-MM-dd":
                        domClass = "easyui-datebox";
                        break;
                    case "yyyy-MM-dd HH:mm:ss":
                        domClass = "easyui-datetimebox";
                        break;
                    default:
                        domClass = "easyui-datetimebox";
                }
                renderedForm.append("<input class='").append(domClass).append("' name='").append(formProperty.getId()).append("' required='").append(formProperty.isRequired()).append("' >");
                renderedForm.append("</td></tr>");
            }
            // 字符串类型渲染
            if (formProperty.getType() instanceof StringFormType) {
                renderedForm.append("<tr><td>").append(formProperty.getName()).append("</td><td>");
                renderedForm.append("<input style='width:90%; height:50px' class='easyui-textbox' name='").append(formProperty.getId()).append("' required='").append(formProperty.isRequired()).append("' >");
                renderedForm.append("</td></tr>");
            }
            // 枚举渲染为下拉框
            if (formProperty.getType() instanceof EnumFormType) {
                renderedForm.append("<tr><td>").append(formProperty.getName()).append("</td><td>");
                renderedForm.append("<select panelHeight='auto' style='width:200px'  class='easyui-combobox' name='").append(formProperty.getId()).append("' required='").append(formProperty.isRequired()).append("' >");
                ((Map<String, String>) formProperty.getType().getInformation("values")).forEach((key, value) -> {
                    renderedForm.append("<option value='").append(key).append("'>").append(value).append("</option>");
                });
                renderedForm.append("</select>").append("</td></tr>");
            }
        // 更多类型 更复杂业务 自行扩展
        }
    }
    return renderedForm.toString();
}
Also used : StringFormType(org.activiti.engine.impl.form.StringFormType) FormProperty(org.activiti.engine.form.FormProperty) DateFormType(org.activiti.engine.impl.form.DateFormType) EnumFormType(org.activiti.engine.impl.form.EnumFormType)

Aggregations

FormProperty (org.activiti.engine.form.FormProperty)21 TaskFormData (org.activiti.engine.form.TaskFormData)10 HashMap (java.util.HashMap)9 StartFormData (org.activiti.engine.form.StartFormData)7 ArrayList (java.util.ArrayList)6 Map (java.util.Map)6 Deployment (org.activiti.engine.test.Deployment)6 LinkedHashMap (java.util.LinkedHashMap)4 Task (org.activiti.engine.task.Task)4 IdentityLinkDto (eu.bcvsolutions.idm.core.workflow.model.dto.IdentityLinkDto)3 WorkflowProcessDefinitionDto (eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowProcessDefinitionDto)3 WorkflowTaskInstanceDto (eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowTaskInstanceDto)3 EnumFormType (org.activiti.engine.impl.form.EnumFormType)3 IdentityLink (org.activiti.engine.task.IdentityLink)3 Field (com.vaadin.ui.Field)2 FormService (org.activiti.engine.FormService)2 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1