本文介绍了如何在Activiti工作流中向所有用户任务表单添加标题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Alfresco Share中使用Activiti工作流,我需要添加工作流中所有用户任务表单共有的标题。该标头是一组只读属性(字段),在工作流中所有用户任务表单的顶部显示上下文工作流信息。例如,在客户端管理工作流中,标题可以显示客户端名称和姓氏,客户端文件代码等,并在只读文本框或标签中显示每个值。

I'm working with Activiti workflows in Alfresco Share and I need to add a header common to all the user task forms in a workflow. This header would be a set of read-only properties (fields) displaying context workflow information at the top of all the user task forms in the workflow. For example, in client management workflows, the header may show the client name and surnames, the client file code, etc., displaying each value in a read-only text box or label.

是否有一种简单的方法可以向工作流中的所有用户任务表单添加一组信息字段(并填充它们)?我知道可以创建一个包含所需属性的新方面,但是如何在运行时将该方面添加到我的任务类型中,并在需要时通过JavaScript设置其属性值?当前,工作流中的每个用户任务在工作流模型定义(XML文件)中都有其自己的自定义类型(即表单),除了一些标准审阅任务使用 wf:activitiReviewTask作为表单键。只读信息字段集应出现在所有表格中,包括标准的审阅任务表格。

Is there a simple way to add a set of information fields (and populate them as well) to all the user task forms in a workflow? I know it's possible to create a new aspect containing the desired properties, but how could I add that aspect at runtime to my task types and set their property values via JavaScript when needed? Currently, each user task in the workflow has its own custom type (i.e. form) in a workflow model definition (XML file), except for some "standard" review tasks, which are using "wf:activitiReviewTask" as form key. The set of read-only information fields should appear in all the forms, including the standard review task forms.

我想要实现以下目的(请参见红色方块):

I want to achieve something like this (see red square):

谢谢您的帮助。

更新1

我对表单模板没有经验。由于我的表单非常简单,因此我只使用了一些模型定义(方面和类型),并结合了一些Share自定义配置来设计它们。我希望在标题中显示的信息可以轻松地从JavaScript代码中检索,因为它存储在多个工作流上下文变量中。这就是我的想法,尚未经过测试,请告诉我这是否可行。如果没有,您能否提供一个使用表单模板的示例?

I have no experience with form templates. Since my forms are very simple, I just used a few model definitions (aspects & types) and some Share custom configuration combined to design them. The information I wish to display in the header can be easily retrieved from JavaScript code, since it's stored in several workflow context variables. This is what I had in mind, not tested yet, please tell me if it's a workable idea. If not, could you provide an example of how to do it using form templates?

mynsModel.xml

mynsModel.xml

<aspect name="myns:customerTaskHeader">
    <title>Customer task header</title>
    <properties>
        <property name="myns:customerName">
            <title>Name</title>
            <type>d:text</type>
        </property>
        <property name="myns:customerSurname">
            <title>Surname</title>
            <type>d:text</type>
        </property>         
    </properties>
</aspect>

workflowModel.xml

workflowModel.xml

<type name="wf:customerDelivery">
    <title>Delivery to customer</title>
    <parent>bpm:workflowTask</parent>
    <properties>
        <property name="wf:customerDeliveryType">
            <title>Delivery type</title>
            <type>d:text</type>         
        </property>
        <property name="wf:customerDeliveryStatus">
            <title>Signed</title>
            <type>d:boolean</type>                  
        </property>
    </properties>
    <mandatory-aspects>
        <aspect>myns:customerTaskHeader</aspect>
    </mandatory-aspects>    
</type>

share-config-custom.xml

share-config-custom.xml

<config evaluator="task-type" condition="wf:customerDelivery">
    <forms>
        <form>
            <field-visibility>
                <show id="myns:customerName" />
                <show id="myns:customerSurname" />
                <show id="packageItems" />
                <show id="wf:customerDeliveryType" />
                <show id="wf:customerDeliveryStatus" />
                <show id="bpm:comment" />   
                <show id="transitions" />
            </field-visibility>
            <appearance>
                <set id="" appearance="title" label-id="workflow.set.general" />
                <set id="items" appearance="title" label-id="workflow.set.items" />
                <set id="response" appearance="title" labelid="workflow.set.response" />
                <field id="bpm:comment" labelid="workflow.field.message">
                    <control template="/org/alfresco/components/form/controls/textarea.ftl">
                        <control-param name="style">width: 95%</control-param>
                    </control>
                </field>
                <field id="packageItems" set="items" />
                <field id="transitions" set="response" />
                <field id="myns:customerName" read-only="true">
                    <control template="/org/alfresco/components/form/controls/info.ftl" />
                </field>
                <field id="myns:customerSurname" read-only="true">
                    <control template="/org/alfresco/components/form/controls/info.ftl" />
                </field>
            </appearance>
        </form>
    </forms>
</config>

我在此(可能)解决方法中看到一些缺点:

Some drawbacks I see in this (possible) workaround:


  1. 所有任务类型定义必须包括 customerTaskHeader 方面。问题在于工作流中的许多用户任务都具有内置类型,而不是自定义类型。能够在运行时通过JavaScript代码将具有所有必需值的方面添加到任务类型会很好,但这可能是不可能的。

  2. 我需要一个不同的自定义配置share-config-custom.xml中每种任务类型的评估程序。同样的问题。

  3. 我觉得使用起来非常麻烦并且难以维护。此外,如果我错了,请纠正我,我看不到一种简单的方法来为工作流中所有任务表单的标题字段设置值。我想我应该为每个用户任务添加一个创建事件监听器,并使用以下代码:

  1. All the task type definitions must include the customerTaskHeader aspect. The problem is that many user tasks in the workflow have a built-in type, not a custom one. It would be nice to be able to add the aspect with all the required values to the task type at runtime by JavaScript code, but this is probably not possible.
  2. I need a different custom config evaluator for each task type in share-config-custom.xml. Same problem.
  3. I find it quite cumbersome to use and hard to maintain. Moreover, correct me if I'm wrong, I cannot see a simple way to set values to the header fields of all the task forms in the workflow. I think I should add a "create" event listener to every user task, with the following code:

[JavaScript代码]

[JavaScript Code]

    var customerName = execution.getVariable('customerName');
    var customerSurname = execution.getVariable('customerSurname');
    task.setVariable('myns_customerName', customerName);
    task.setVariable('myns_customerSurname', customerSurname);


推荐答案

定义自定义表单模板非常容易,如所述。作为该模板的一部分,您可以显示在开始呈现字段本身之前需要的任何信息。如果您需要在多个表单模板中显示该模板,甚至可以创建一个通用的包含模板。

It is pretty easy to define a custom form template, as documented on http://wiki.alfresco.com/wiki/Forms. As part of that template, you can display any information you need to before you start rendering the fields themselves. You could even create a common 'include' template if you need to show this in multiple form templates.

问题是您希望在标题中显示哪些信息,该信息存储在哪里?

The question is exactly what information you wish to display in the header, and where is that information stored? That will impact how you need to retrieve it for display to the user.

如果您需要的属性在任务项上可用,那么检索它们将很容易。通过表单字段值。然后可以将它们直接呈现为输出HTML。

If you the properties you need are available on the task item, then it is easy to retrieve them through the form field values. They can then then be rendered straight into the output HTML.

不过,从您的问题来看,我怀疑更有可能是这些值存储在其他位置,并且必须在显示之前从那里检索。在这种情况下,您将需要使用标准的共享模式来实现客户端功能(或组件),并修改表单模板,以便其生成的HTML导致该代码在被浏览器加载时运行。

What I suspect is more likely however, from your question, is that the values are stored somewhere else and must be retrieved from there prior to display. In that case, you would need to implement a client-side function (or component) using the standard Share pattern, and modify your form template so that the HTML it generates causes that code to be run when loaded by the browser.

在该组件中,您可以对存储库API进行XHR调用,以检索属性值,然后使用回调函数更新HTML页面以填充数据

Within that component, you can make XHR calls out to, say, the repository API, to retrieve the property values, and then update the HTML page using a callback function to populate the data for user display.

作为类似示例,请参见Share提供的 task owner.ftl 字段模板

As an example of something similar, see the task owner.ftl field template provided by Share

<#if field.value?? && field.value?length &gt; 0>
...
<script type="text/javascript">//<![CDATA[
YAHOO.util.Event.onContentReady("${fieldHtmlId}", function ()
{
   YAHOO.util.Dom.get("${fieldHtmlId}").innerHTML = Alfresco.util.userProfileLink("${userName}", "${fullName}", "", ${disableLink?string});
}, this);
//]]></script>
</#if>

此处,客户端功能使用 Alfresco.util.userProfileLink ,但是您可以实现自己的函数,该函数使用 Alfresco.util.Ajax.jsonGet()或类似方法检索数据,然后使用YAHOO.util进行填充Dom函数。

Here the client-side function uses Alfresco.util.userProfileLink, but you could implement your own function which uses Alfresco.util.Ajax.jsonGet() or similar to retrieve the data and then populate it using YAHOO.util.Dom functions.

但是,正如我所说,确切的方法取决于数据的位置以及显示方式。

But as I say, the exact method depends on where your data is and how you need to display it.

这篇关于如何在Activiti工作流中向所有用户任务表单添加标题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-21 01:16