在SharePoint中动态显示Edit Control Block菜单项
我试图在SharePoint 2007中设置动态逐项菜单(编辑控制块)。我的目标是根据当前用户的组成员身份提供某些可用功能。
我知道控制此菜单项创建的CustomAction标记具有Rights属性。我遇到的问题是我使用的组在站点中具有相同的权限(ViewListItems,ManageAlerts等)。我们设置的组更多地处理功能,例如经理,员工等。我们希望能够将自定义功能分配给组,并使与该功能关联的菜单项仅对该组成员可见。每个人都具有相同的基本站点权限,但根据他们的登录凭据,它们将具有其他选项。
我看过几篇有关修改Core.js文件以在上下文菜单中隐藏项目的文章,但这是一种全有或者全无的方法。 http://blog.thekid.me.uk/archive/2008/04/29/sharepoint-custom-actions-in-a-list-view-webpart.aspx中有一篇有趣的文章,显示了如何动态修改动作菜单。修改此示例以检查用户组并根据成员资格显示或者隐藏菜单很简单。不幸的是,此示例似乎不适用于上下文菜单项,如http://forums.msdn.microsoft.com/en-US/sharepointdevelopment/thread/c2259839-24c4-4a7e-83e5-3925cdd17c44/所示。
有人知道不用JavaScript就能做到这一点的方法吗?如果不是,从javascript检查用户组的最佳方法是什么?
解决方案
回答
我们可以实现两种不同的Javascript函数,以动态地将菜单项添加到列表项下拉列表中。 Core.js(C:\ Program Files \ Common Files \ Microsoft Shared \ Web服务器扩展\ 12 \ TEMPLATE \ LAYOUTS \ 1033 \ CORE.JS)在为选定列表项生成菜单项时检查这些方法是否存在。 " Custom_AddDocLibMenuItems"和" Custom_AddListMenuItems"是Javascript方法的名称。
我认为我们可以用来解决特定问题的一篇文章,基于用户角色成员资格的动态菜单项自定义,可以在以下位置找到:
MSDN:自定义文档库项目的上下文菜单(请注意,此过程对于任何列表类型都是完全相同的)
本文概述了如何执行服务器端代码来定义将显示的菜单项:
[...] in more complex cases, you must retrieve the list of available commands from the server, because only there you can run your business logic and perhaps get the commands from a custom database. Typically, you want to do this if you are implementing a workflow solution where each document has its own process state, with commands associated to it. The solution for this situation is to have the Custom_AddDocLibMenuItems dynamically call a custom ASP.NET page. This page takes the ID of the document library and the specific item on the query string, and returns an XML string containing all the information for the commands available for that particular document. These commands are available according to the document's process status (or some other custom business logic). [...]
回答
不幸的是,如果不使用javascript,这是不可能完成的。 ECB不会呈现定义为自定义动作的服务器控件(与SiteActions等不同)。
要了解如何使用Javascript完成此操作,请查看以下文章:
http://www.helloitsliam.com/archive/2007/08/10/moss2007-%E2%80%93-item-level-menus-investigation.aspx