【问题标题】:How to Add New Field to Alfresco/Share Form?如何在 Alfresco/Share 表单中添加新字段?
【发布时间】:2012-09-04 22:57:50
【问题描述】:

好的,所以我们知道 Alfresco 有标准的包装形式。例如,默认的 ad-hoc 表单如下所示:

现在,如果我想自定义该表单,比如添加一个单独的 Items 字段,我该怎么做呢?我的意思是,我想要一个只显示当前项目的字段。另一个字段显示同一空间中的所有相关项目。我有脚本可以将空间中的所有项目显示到单个项目字段中,所以我认为我应该能够操作它,但我首先需要附加项目字段才能这样做。

我一直在尝试弄乱一些 XML 文件,并且我设法获得了一个额外的 Items 标签以显示在表单上,​​但不是可以显示的实际框使用 Add 填充或使用 Remove All 取消填充。

我首先修改了 /opt/alfresco-4.0.d/tomcat/webapps/share/WEB-INF/classes/alfresco/form-config.xml

<alfresco-config>

   <plug-ins>
      <element-readers>
         <element-reader element-name="forms" class="org.alfresco.web.config.forms.FormsElementReader"/>
      </element-readers>
      <evaluators>
         <evaluator id="node-type" class="org.alfresco.web.config.forms.NodeTypeEvaluator" />
         <evaluator id="model-type" class="org.alfresco.web.config.forms.ModelTypeEvaluator" />
         <evaluator id="task-type" class="org.alfresco.web.config.forms.TaskTypeEvaluator" />
         <evaluator id="aspect" class="org.alfresco.web.config.forms.AspectEvaluator" />
      </evaluators>
   </plug-ins>

   <config>
      <forms>
         <default-controls>
            <type name="text" template="/org/alfresco/components/form/controls/textfield.ftl" />
            <type name="mltext" template="/org/alfresco/components/form/controls/textarea.ftl" />
            <type name="int" template="/org/alfresco/components/form/controls/number.ftl" />
            <type name="float" template="/org/alfresco/components/form/controls/number.ftl" />
            <type name="double" template="/org/alfresco/components/form/controls/number.ftl" />
            <type name="long" template="/org/alfresco/components/form/controls/number.ftl" />
            <type name="boolean" template="/org/alfresco/components/form/controls/checkbox.ftl" />
            <type name="date" template="/org/alfresco/components/form/controls/date.ftl" />
            <type name="datetime" template="/org/alfresco/components/form/controls/date.ftl">
               <control-param name="showTime">true</control-param>
            </type>
            <type name="period" template="/org/alfresco/components/form/controls/period.ftl" />
            <type name="any" template="/org/alfresco/components/form/controls/textfield.ftl" />
            <type name="category" template="/org/alfresco/components/form/controls/category.ftl" />
            <type name="content" template="/org/alfresco/components/form/controls/content.ftl" />
            <type name="association" template="/org/alfresco/components/form/controls/association.ftl" />
            <type name="association:cm:person" template="/org/alfresco/components/form/controls/authority.ftl" />
            <type name="association:cm:authority" template="/org/alfresco/components/form/controls/authority.ftl" />
            <type name="association:cm:authorityContainer" template="/org/alfresco/components/form/controls/authority.ftl" />
            <type name="association:packageItems" template="/org/alfresco/components/form/controls/workflow/packageitems.ftl" />
            <type name="association:singlePackageItem" template="/org/alfresco/components/form/controls/workflow/packageitems.ft" />
        <type name="transitions" template="/org/alfresco/components/form/controls/workflow/transitions.ftl" />
            <type name="taskOwner" template="/org/alfresco/components/form/controls/workflow/taskowner.ftl" />
            <type name="mbean_operations" template="/org/alfresco/components/form/controls/jmx/operations.ftl" />
            <!-- Data types that should always be rendered read-only -->
            <type name="qname" template="/org/alfresco/components/form/controls/readonly.ftl" />
            <type name="noderef" template="/org/alfresco/components/form/controls/readonly.ftl" />
            <type name="childassocref" template="/org/alfresco/components/form/controls/readonly.ftl" />
            <type name="assocref" template="/org/alfresco/components/form/controls/readonly.ftl" />
            <type name="path" template="/org/alfresco/components/form/controls/readonly.ftl" />
            <type name="locale" template="/org/alfresco/components/form/controls/readonly.ftl" />
         </default-controls>
         <constraint-handlers>
            <constraint type="MANDATORY" validation-handler="Alfresco.forms.validation.mandatory" event="keyup" />
            <constraint type="NUMBER" validation-handler="Alfresco.forms.validation.number" event="keyup" />
            <constraint type="MINMAX" validation-handler="Alfresco.forms.validation.numberRange" event="keyup" />
            <constraint type="LIST" validation-handler="Alfresco.forms.validation.inList" event="blur" />
            <constraint type="REGEX" validation-handler="Alfresco.forms.validation.repoRegexMatch" event="keyup" />
            <constraint type="LENGTH" validation-handler="Alfresco.forms.validation.length" event="keyup" />
         </constraint-handlers>
      </forms>
   </config>

</alfresco-config>

这里唯一真正的变化是添加了&lt;type name="association:singlePackageItem" template="/org/alfresco/components/form/controls/workflow/packageitems.ft" /&gt;

接下来,我进入 /opt/alfresco-4.0.d/tomcat/webapps/share/WEB-INF/classes/alfresco/share-workflow-form-config.xml ,并修改如下:

<alfresco-config>

   <!-- ************************************** -->
   <!-- Workflow Definition Form Configuration -->
   <!-- ************************************** -->

   <!--
      When workflows are started some bpm:workflowXxx properties are copied to the task and named bpm:xxx
      I.e The bpm:workflowDueDate workflow property becomes the bpm:dueDate task property. 
   -->

   <!-- Ad Hoc Workflow Definition -->
   <config evaluator="string-compare" condition="jbpm$wf:adhoc">
      <forms>
         <form>
            <field-visibility>
               <show id="bpm:workflowDescription" />
               <show id="bpm:workflowDueDate" />
               <show id="bpm:workflowPriority" />
               <show id="bpm:assignee" />
               <show id="packageItems" /> 
                 <show id="singlePackageItem" />
               <show id="bpm:sendEMailNotifications" />
            </field-visibility>
            <appearance>
               <set id="" appearance="title" label-id="workflow.set.general" />
               <set id="info" appearance="" template="/org/alfresco/components/form/2-column-set.ftl" />
               <set id="assignee" appearance="title" label-id="workflow.set.assignee" />
               <set id="items" appearance="title" label-id="workflow.set.items" /> 
                 <set id="thisOneItem" appearance="title" label-id="workflow.set.items" />
               <set id="other" appearance="title" label-id="workflow.set.other" />

               <field id="bpm:workflowDescription" label-id="workflow.field.message">
                  <control template="/org/alfresco/components/form/controls/textarea.ftl">
                     <control-param name="style">width: 95%</control-param>
                  </control>
               </field>
               <field id="bpm:workflowDueDate" label-id="workflow.field.due" set="info" />
               <field id="bpm:workflowPriority" label-id="workflow.field.priority" set="info">
                  <control template="/org/alfresco/components/form/controls/workflow/priority.ftl" />
               </field>
               <field id="bpm:assignee" label-id="workflow.field.assign_to" set="assignee" />
               <field id="packageItems" set="items" /> 
                 <field id="singlePackageItem" set="thisOneItem" />
               <field id="bpm:sendEMailNotifications" set="other">
                  <control template="/org/alfresco/components/form/controls/workflow/email-notification.ftl" />
               </field>
            </appearance>
         </form>
      </forms>
   </config>


   <!-- Activiti Ad Hoc Workflow Definition -->
   <config evaluator="string-compare" condition="activiti$activitiAdhoc">
      <forms>
         <form>
            <field-visibility>
               <show id="bpm:workflowDescription" />
               <show id="bpm:workflowDueDate" />
               <show id="bpm:workflowPriority" />
               <show id="bpm:assignee" />
               <show id="packageItems" /> 
                 <show id="singlePackageItem" />
               <show id="bpm:sendEMailNotifications" />
            </field-visibility>
            <appearance>
               <set id="" appearance="title" label-id="workflow.set.general" />
               <set id="info" appearance="" template="/org/alfresco/components/form/2-column-set.ftl" />
               <set id="assignee" appearance="title" label-id="workflow.set.assignee" />
               <set id="items" appearance="title" label-id="workflow.set.items" /> 
                 <set id="thisOneItem" appearance="title" label-id="workflow.set.items" />
               <set id="other" appearance="title" label-id="workflow.set.other" />

               <field id="bpm:workflowDescription" label-id="workflow.field.message">
                  <control template="/org/alfresco/components/form/controls/textarea.ftl">
                     <control-param name="style">width: 95%</control-param>
                  </control>
               </field>
               <field id="bpm:workflowDueDate" label-id="workflow.field.due" set="info" />
               <field id="bpm:workflowPriority" label-id="workflow.field.priority" set="info">
                  <control template="/org/alfresco/components/form/controls/workflow/priority.ftl" />
               </field>
               <field id="bpm:assignee" label-id="workflow.field.assign_to" set="assignee" />
               <field id="packageItems" set="items" /> 
                 <field id="singlePackageItem" set="thisOneItem" />
               <field id="bpm:sendEMailNotifications" set="other">
                  <control template="/org/alfresco/components/form/controls/workflow/email-notification.ftl" />
               </field>
            </appearance>
         </form>
      </forms>
   </config>

</alfresco-config>

同样,这里唯一真正的变化是在&lt;show id="packageItems" /&gt; 的任何实例之后添加&lt;show id="singlePackageItem" /&gt;,在&lt;set id="items" appearance="title" label-id="workflow.set.items" /&gt; 的任何实例之后添加&lt;set id="thisOneItem" appearance="title" label-id="workflow.set.items" /&gt;,以及在任何实例之后添加&lt;field id="singlePackageItem" set="thisOneItem" /&gt; &lt;field id="packageItems" set="items" /&gt; 的。

但结果是这样的:

现在,我认为这不会那么容易。但是,我在 share-workflow-form-config.xml 文件中尝试了一些不同的配对,但这似乎是唯一一个至少可以看到额外标签 Items,尽管没有其他组件。我只是想知道是否有人有自定义这些表单的经验,和/或可能知道我在这里做错了什么?

【问题讨论】:

    标签: xml forms customization share alfresco


    【解决方案1】:

    您能否发布一些您正在努力实现的目标的图片,也许是您已经实现的目标?只是为了说清楚。 我不明白当你已经有一个字段在做它的工作时,你为什么要添加另一个字段“项目”。无论如何,临时表单是工作流的一部分,您是否要更改工作流表单或其他一些东西,例如节点的上传和更改属性?这些是不同的东西。 在这两种情况下,您都应该使用 share-workflow-form-config.xmlshare-config-custom.xml 等文件。 无论如何,你不能只添加一个像“singlePackageItem”这样的组件而不在某处声明它。 id packageItems 和 set Items 正在调用一个名为 packageItems.ftl 的文件,该文件公开您看到的表单。您可以在以下位置找到该文件:

    /alfresco/tomcat/webapps/share/WEB-INF/classes/alfresco/site-webscripts/org/alfresco/components/form/controls/workflow
    

    与所有其他 ftl 文件一起公开您在工作流程中看到的表单。如果您想自定义表单,并公开一些自定义属性或字段,您应该首先使用一些(工作流)内容建模,您可以在此处找到一个 wiki: Custom Share Workflow UI

    如果您可以更具体地说明您想要实现的目标,请询问,我可以看看是否可以帮助您。

    好吧,也许我误解了,但这是我的想法。您应该有一个带有脚本的控制器 js 文件,以及一个在字段中公开这些文档的模板文件 ftl。编辑* 如果您使用 packageItems 表单字段,则使用 Alfresco 提供的即用型表单。您应该实现自己的 freemarker 模板文件,该文件读取您的脚本并公开此列表和您需要的单个文件。 您可以从查看 Share 中默认表单控件中的代码开始: '/Alfresco/tomcat/webapps/share/WEB-INF/classes/alfresco/site-webscripts/org/alfresco/components/form/controls/' 然后,您可以从 share-workflow-form-config.xml 中调用您自己的 ftl 表单控件,如下所示:

       <config evaluator="string-compare" condition="jbpm$wf:adhoc">
          <forms>
             <form>
                <field-visibility>
                   <show id="bpm:workflowDescription" />
                   <show id="bpm:workflowDueDate" />
                   <show id="bpm:workflowPriority" />
                   <show id="bpm:assignee" />
                   <show id="my:ListFiles" />
                   <show id="packageItems" />
                   <show id="wf:notifyMe" />
                </field-visibility>
                <appearance>
                   <set id="" appearance="title" label-id="workflow.set.general" />
                   <set id="info" appearance="" template="/org/alfresco/components/form/2-column-set.ftl" />
                   <set id="assignee" appearance="title" label-id="workflow.set.assignee" />
                   <set id="items" appearance="title" label-id="workflow.set.items" />
                   <set id="other" appearance="title" label-id="workflow.set.other" />
    
                   <field id="bpm:workflowDescription" label-id="workflow.field.message">
                      <control template="/org/alfresco/components/form/controls/textarea.ftl">
                         <control-param name="style">width: 95%</control-param>
                      </control>
                   </field>
                   <field id="bpm:workflowDueDate" label-id="workflow.field.due" set="info" />
                   <field id="bpm:workflowPriority" label-id="workflow.field.priority" set="info">
                      <control template="/org/alfresco/components/form/controls/workflow/priority.ftl" />
                   </field>
    **<field id="my:ListFiles" set="items">
                      <control template="/org/alfresco/components/form/controls/workflow/customListItems.ftl" />
                   </field>**
                   <field id="packageItems" set="items" />
                   <field id="wf:notifyMe" set="other" />
                </appearance>
             </form>
          </forms>
       </config>
    

    【讨论】:

    • 嗨,如果我不够具体,对不起,我已经继续并用一些图片编辑了 OP。但本质上,我希望有一个仅显示当前项目的字段。另一个字段显示同一空间中的所有相关项目。我有脚本可以将空间中的所有项目显示到单个项目字段中,所以我认为我应该能够操纵它,但我需要先添加其他项目字段才能这样做。
    • 嗯,这只是我目前根据规则运行的基本 javascript 文件,因此它不是 Web 脚本。但是我的问题是,如果我只是想复现原始items字段的功能,为什么不能使用同一个模板呢?
    • 我在我原来的回答中回答了,很抱歉这么混乱..无论如何,itemsPackage 并没有达到你想要的效果,所以如果你想使用那个文件 (itemsPackage.ftl)公开你的 js 文件,你应该在 freemarker 中更改和编码。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多