Core.js: Disable ECB menu items in Document library or List based on permissions. …mystery solved…


Create a custom core.js from the original core.js as described in this link: http://msdn.microsoft.com/en-us/library/cc768565.aspx 
  1. Follow the steps below and you can hide ECB items based on permissions i.e. SPBasePermissions like you could disable some ECB menu items as below…
  2. Disable the send menu as below by commenting AddSendSubMenu
       1: if (currentItemFSObjType !=1)
       2:     {
       3:         /*
       4:         AddSendSubMenu(m,ctx);
       5:         */
       6:         AddDocTransformSubMenu(m,ctx);
       7:     }

  3. Now disabling “Edit Properties” menu item based on permissions—> Manage Lists .i.e. ox800

Basically you need to put an if else with condition as HasRights(0x0, 0x800)

0x0—> Empty mask

              0x800—> Manage Lists ( SPBaseUserPermission : See the values from reflector in the link:  http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spbasepermissions.aspx)

   1: if (HasRights(0x0, 0x800) &&
   2:           !currentItemIsEventsDeletedExcp) {
   3:             strImagePath = ctx.imagesPath + "edititem.gif";
   4:             menuOption = CAMOpt(m, strDisplayText, strAction, strImagePath, null, 220);
   5: 
   6:             if (ctx.listBaseType == 1)
   7:                 menuOption.id = "ID_EditProperties";
   8:             else
   9:                 menuOption.id = "ID_EditItem";
  10:         }

Wow!!! This saves you from creating a custom application page and an ECB menu item .

You could do the same for most of the OOB application pages in MOSS2007 like View Properties, View Item ( for a list)

One of the permission based requirement was to enable “Delete” only for the users with full control. So here is what I did in customcore.js for hasrights( 0x0  (—> Empty Mask),0x7fffffffffffffff ( –> Full Control Mask) )

 

   1: if (currentItemID.indexOf(".0.") < 0 && HasRights(0x0, 0x7fffffffffffffff)
   2:       && !currentItemIsEventsExcp)
   3: {
   4:     if (ctx.listBaseType==4)
   5:         strDisplayText=L_DeleteResponse_Text;
   6:     else
   7:         strDisplayText=L_DeleteItem_Text;
   8:     strAction="DeleteListItem()";
   9:     strImagePath=ctx.imagesPath+"delitem.gif";
  10:     menuOption=CAMOpt(m, strDisplayText, strAction, strImagePath, null, 300);
  11:     menuOption.id="ID_DeleteItem";
  12: }

Advertisements

Tags: , ,

No comments yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: