Reputation: 2662
Okay, so we know that Alfresco has standard forms that it comes packaged with. For example, the default ad-hoc form is shown below:
Now, if I wanted to customize that form, say add a separate Items field, how exactly would I go about doing that? What I mean is, I want to have one field that displays only the current item. And another field that displays all the related items in that same space. I have the script to display all the items in a space into that singular items field, so I think I should be able to manipulate that, but I need the additional items field first in order to do so.
I've been trying to mess with some of the XML files, and I've managed to get an extra Items label to show up on the form, but not the actual box which can be populated with Add or depopulated with Remove All.
I did this by first modifying /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>
The only real change here being the addition of <type name="association:singlePackageItem" template="/org/alfresco/components/form/controls/workflow/packageitems.ft" />
.
Next, I went into /opt/alfresco-4.0.d/tomcat/webapps/share/WEB-INF/classes/alfresco/share-workflow-form-config.xml, and modified it like so:
<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>
And again, here the only real changes were the addition of <show id="singlePackageItem" />
after any instance of <show id="packageItems" />
, the addition of <set id="thisOneItem" appearance="title" label-id="workflow.set.items" />
after any instance of <set id="items" appearance="title" label-id="workflow.set.items" />
, and the addition of <field id="singlePackageItem" set="thisOneItem" />
after any instance of <field id="packageItems" set="items" />
.
But this is the result:
Now, I didn't think it would be THAT easy. However, I've tried some different pairings in the share-workflow-form-config.xml file, but this seems to be the only one that results in at least the visible showing of the extra label Items, albeit without the rest of the components. I was just wondering if anyone had any experience customizing these forms, and/or perhaps knew what I could be doing wrong here?
Upvotes: 1
Views: 8138
Reputation: 1298
Could you just post some pictures of what are you trying to achieve, maybe with what have you achieved already? Just to make clear. I don't understand why would you add another field "Items" when you have already one there doing it's job. Anyway, the ad-hoc form is part of a workflow, do you want to change a workflow form, or some other thing, like the upload and change properties of a node? these are different things. In both cases, you should work with files like share-workflow-form-config.xml or share-config-custom.xml. Anyway, you can't just add a component like "singlePackageItem" without declaring it somewhere. The id packageItems and the set Items are calling a file named packageItems.ftl that exposes the form that you see. You can find that file in:
/alfresco/tomcat/webapps/share/WEB-INF/classes/alfresco/site-webscripts/org/alfresco/components/form/controls/workflow
with all other ftl files that expose the forms that you see in a workflow. If you want to custom a form, and expose some custom properties or fields you should work with some (workflow) content modeling first, you can find a wiki here: Custom Share Workflow UI
If you can be more specific on what do you want to achieve, just ask, and I can see if I can help you.
Ok, maybe I've misunderstood, but this is my idea. You should have a controller js file with the script, and a template file ftl that exposes these documents in a field. editing* If you use the packageItems form field, you use the form that Alfresco offers as out-of-the-box. You should implement your own freemarker template file, that reads your script and exposes this list and this single file you need. You could start from looking at the code in the default form controls in Share: '/Alfresco/tomcat/webapps/share/WEB-INF/classes/alfresco/site-webscripts/org/alfresco/components/form/controls/' then, you could recall your own ftl form control from the share-workflow-form-config.xml like this:
<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>
Upvotes: 3