Freigeben über


Remove List Item Menu Options with Javascript

SharePoint has a lot of JavaScript code to manage UI, and a lot of customization can be done by modifying out-of-box JavaScript.  However, modifying system files is not a good idea.  Instead, you usually will want to copy the file and make your custom changes there.

One other way to make customizations is to “override” functions using pointers.  In our case, we didn’t want the “Manage Permissions” options to show up in the list item menu for most users.  Just removing the “Manage Permissions” permission for those user groups didn’t work because they also have the “Enumerate Permissions” permission, which is needed for general access to the list.  The “Manage Permissions” menu option shows up for either of these.

So, there is a handy function called AddManagePermsMenuItem in the core.js file that you can “override”.  In this example, I’m checking to see if the user has “Manage Permission” permission (0x20000000 bit is set):

var original_AddManagePermsMenuItem = AddManagePermsMenuItem;
AddManagePermsMenuItem = function(m, ctx, listId, url) {
if (!HasRights(0x0, 0x2000000))
return;
        original_AddManagePermsMenuItem(m, ctx, listId, url);
}

First it saves a pointer to the current function, then replaces the function with an anonymous function.  The anonymous function checks the rights and returns if the user doesn’t have “Manage Permission” rights.  If the user does, it calls the original AddManagePermsMenuItem through the pointer we saved earlier.

Place this script in your master page after the inclusion of core.js and any list view that uses that master page will no longer show the “Manage Permissions” option for most users.

Comments

  • Anonymous
    April 28, 2011
    The comment has been removed