如何在Alfresco 5.1.0添加事件表单中集成authority.ftl控件
嘿,我来帮你搞定Alfresco 5.1社区版里把用户选择控件集成到日历添加事件表单的事儿,步骤很清晰,跟着做就行:
1. 修改「添加事件」表单文件
create-event.get.html.ftl 首先找到你提到的share\WEB-INF\classes\alfresco\site-webscripts\org\alfresco\modules\create-event.get.html.ftl文件,定位到表单核心区域(一般在<@form>和</@form>标签之间),插入用户选择控件的代码。
比如我们要添加一个「事件参与者」选择框,代码示例如下:
<div class="form-group"> <label for="event-participants" class="control-label">${msg("form.label.participants")}</label> <@formControl field="participants" control="authority" options="{multiple:true, authorityType:'users'}" id="event-participants" /> </div>
这里的参数说明:
control="authority":明确指定使用你提到的authority.ftl权限控件multiple:true:允许同时选择多个用户(如果只需要单选,改成false即可)authorityType:'users':限制控件只显示系统用户,也可以改成'groups'只显示组,或者'all'同时显示用户和组
2. 扩展日历事件模型(可选,需存储用户信息时)
如果需要把选中的用户信息永久存储到日历事件中,就得扩展Alfresco的内容模型:
- 在
alfresco/extension/models目录下创建自定义模型文件,比如custom-calendar-model.xml,内容如下:
<model name="cc:customCalendar" xmlns="http://www.alfresco.org/model/dictionary/1.0"> <description>Custom Calendar Event Model</description> <author>Vishal</author> <version>1.0</version> <imports> <import uri="http://www.alfresco.org/model/content/1.0" prefix="cm"/> <import uri="http://www.alfresco.org/model/calendar/1.0" prefix="cal"/> </imports> <namespaces> <namespace uri="http://yourdomain.com/model/customcalendar/1.0" prefix="cc"/> </namespaces> <types> <!-- 给默认的日历事件类型添加自定义属性 --> <type name="cal:event"> <mandatory-aspects> <aspect>cc:eventParticipants</aspect> </mandatory-aspects> </type> </types> <aspects> <aspect name="cc:eventParticipants"> <properties> <property name="cc:participants"> <title>Event Participants</title> <description>Users invited to the calendar event</description> <type>d:multi-valued</type> <data-type>d:text</data-type> </property> </properties> </aspect> </aspects> </model>
- 在
alfresco/extension/custom-model-context.xml中配置加载这个模型,确保Alfresco启动时能识别它。
3. 配置后端WebScript处理字段
找到create-event.get.js(路径同html.ftl文件所在目录),在表单字段定义部分添加新字段的配置,让后端能识别并处理这个用户选择字段:
// 在现有字段定义后添加 form.addField({ id: "participants", name: "cc:participants", label: msg.get("form.label.participants"), control: { type: "authority", parameters: { multiple: true, authorityType: "users" } } });
如果不需要存储用户信息,只是临时使用(比如提交时发送通知),可以跳过模型扩展和这一步,直接在前端获取控件值处理即可。
4. 重启服务并测试
重启Alfresco Share和Repository服务,进入日历的「添加事件」页面,你就能看到和参考效果一致的用户选择控件了。选择用户后提交事件,检查事件属性是否正确存储了选中的用户信息。
内容的提问来源于stack exchange,提问作者Vishal Zanzrukia
相关产品推荐
相关产品推荐

