Mar*_*ans 1 forms customization alfresco alfresco-share
看似简单的要求
我需要一个包含 4 个字段(文本字段、权限和日期 x2)的表单,它的行为与编辑元数据表单完全一样,这些字段代表节点上的 4 个属性。
但是,此表单应作为与编辑元数据表单分开的 UI 提供,最好采用 UI 操作的方式;DocLibActions 中有一个带有图标的按钮,单击该按钮时会弹出一个窗体。
遇到的问题
我使用 UI 操作机制的问题是我无法将字段链接到属性。因此,每次打开表单时,都不会加载节点上可用的当前值。此外,不会自动强制执行适当的约束。我也想不出另一种方法来实现这个要求。
UI动作方式
从 UI 操作开始,我尝试使用form.destination保存noderef 的模型变量访问自定义字段控件 ftl 中的节点。但是,当我想通过它获取节点属性时,结果发现companyhomeftl 中所需的对象对表单控件不可用。
然后我继续编写一个自定义 java webscript,它使用给定的 nodeRef 返回我需要的 4 个属性,并使用 javascript 从我的自定义字段控件中调用它。这提出了以下两个问题:
date.ftl控件提出了相当大的挑战,但对控件来说更是挑战authority.ftl。当前表单定义
<config evaluator="string-compare" condition="my-action">
<forms>
<form>
<field-visibility>
<show id="textProperty" />
<show id="authorityProperty" />
<show id="dateProperty1" />
<show id="dateProperty2" />
</field-visibility>
<appearance>
<set id="generalSet" appearance="bordered-panel" label="General" />
<field id="textProperty" label="textProp" set="generalSet">
<control template="/org/alfresco/components/form/controls/propertyBasedTextfield.ftl">
<control-param name="propertyProvider">/alfresco/service/mark/custom/nodeProperties</control-param>
</control>
</field>
<field id="authorityProp" label="Authority" set="generalSet" >
<control template="/org/alfresco/components/form/controls/authority.ftl" >
<control-param name="compactMode">true</control-param>
</control>
</field>
<field id="dateProperty1" label="Date 1" set="generalSet">
<control template="/org/alfresco/components/form/controls/date.ftl" />
</field>
<field id="dateProperty2" label="Date 2" set="generalSet">
<control template="/org/alfresco/components/form/controls/date.ftl" />
</field>
</appearance>
</form>
</forms>
</config>
Run Code Online (Sandbox Code Playgroud)
我怎样才能最好地实施这个要求?请注意,使用 UI 操作不是强制性的;我可以以任何我想要的方式实现这一点。
Take a look at the Alfresco.doclib.Actions.onActionDetails() function in the actions.js client-side module (source code). The easiest method is to register your own custom action handler, which can be based on the code in onActionDetails(), but using your own custom form ID which exposes the basic form, e.g.
var templateUrl = YAHOO.lang.substitute(Alfresco.constants.URL_SERVICECONTEXT + "components/form?itemKind={itemKind}&itemId={itemId}&destination={destination}&mode={mode}&submitType={submitType}&formId={formId}&showCancelButton=true",
{
itemKind: "node",
itemId: nodeRef,
mode: "edit",
submitType: "json",
formId: "***custom-form-id***"
});
var editDetails = new Alfresco.module.SimpleDialog(this.id + "-editDetails-" + Alfresco.util.generateDomId());
editDetails.setOptions({
width: "40em",
templateUrl: templateUrl,
...
});
Run Code Online (Sandbox Code Playgroud)
You'll obviously need to add your custom form definition to a share-config-custom.xml file or similar, where you can also include your document library action definition.
You should not need to write any custom UI components.
Also you should not need to manually inject property values into the form when it is rendered by the UI, or write any web scripts to deal with the form submission - the forms framework will handle all of this for you if you use it correctly.