Friday, August 7, 2009

SPCustomContextMenu

Hi Guys!

Recently I have got some free time, so I thought of utilizing that time as technically, so I have designed and developed a reusable component for SharePoint list and library, this component will be very useful when you customizing context menu of list , document library and developing workflows

I have seen so many people using below code for customizing SharePoint list context menus. But just think about maintenance

function Custom_AddListMenuItems(m, ctx)
{
Return true;
}

If any changes come in future we need edit the page and modify the javascript and once again we need test that functionality, here we are wasting our valuable time

SPCustomContextMenu

So I have created a feature which will read the xml file and convert into custom context menu the main advantage of this is whenever you change xml file the changes will be automatically reflected in to your custom context menu

This will be very useful when you developing workflows because based on the status of workflow the context menu will change, the administrator will have full control on this no developer interaction

The XML schema looks like this


<?xml version="1.0" encoding="utf-8" ?>
<nodes>
<node>
<sourcefield>
<fieldname>status</fieldname>
<ifeq>open</ifeq>
</sourcefield>
<destfield>
<shownode>
<Name>Assign issue</Name>
<ImageUrl>/SiteCollectionImages/ppubicon.gif</ImageUrl>
<ActionLink>/Pages/TestPage.aspx</ActionLink>
</shownode>
</destfield>
</node>
<node>
<sourcefield>
<fieldname>status</fieldname>
<ifeq>assigned</ifeq>
</sourcefield>
<destfield>
<shownode>
<Name>In Progress</Name>
<ImageUrl>/SiteCollectionImages/ppubicon.gif</ImageUrl>
<ActionLink>/Pages/TestPage.aspx</ActionLink>
</shownode>
</destfield>
<destfield>
<shownode>
<Name>Paused</Name>
<ImageUrl>/SiteCollectionImages/ppubicon.gif</ImageUrl>
<ActionLink>/Pages/TestPage.aspx</ActionLink>
</shownode>
</destfield>
<destfield>
<shownode>
<Name>Set In Progress</Name>
<ImageUrl>/SiteCollectionImages/ppubicon.gif</ImageUrl>
<ActionLink>/Pages/TestPage.aspx</ActionLink>
</shownode>
</destfield>
</node>
<node>
<sourcefield>
<fieldname>status</fieldname>
<ifeq>in progress</ifeq>
</sourcefield>
<destfield>
<shownode>
<Name>Paused</Name>
<ImageUrl>/SiteCollectionImages/ppubicon.gif</ImageUrl>
<ActionLink>/Pages/TestPage.aspx</ActionLink>
</shownode>
</destfield>
<destfield>
<shownode>
<Name>Resolved</Name>
<ImageUrl>/SiteCollectionImages/ppubicon.gif</ImageUrl>
<ActionLink>/Pages/TestPage.aspx</ActionLink>
</shownode>
</destfield>
</node>
<node>
<sourcefield>
<fieldname>status</fieldname>
<ifeq>resolved</ifeq>
</sourcefield>
<destfield>
<shownode>
<Name>Re-Opened</Name>
<ImageUrl>/SiteCollectionImages/ppubicon.gif</ImageUrl>
<ActionLink>/Pages/TestPage.aspx</ActionLink>
</shownode>
</destfield>
<destfield>
<shownode>
<Name>Closed</Name>
<ImageUrl>/SiteCollectionImages/ppubicon.gif</ImageUrl>
<ActionLink>/Pages/TestPage.aspx</ActionLink>
</shownode>
</destfield>
</node>
<node>
<sourcefield>
<fieldname>status</fieldname>
<ifeq>re-opened</ifeq>
</sourcefield>
<destfield>
<shownode>
<Name>Assign issue</Name>
<ImageUrl>/SiteCollectionImages/ppubicon.gif</ImageUrl>
<ActionLink>/Pages/TestPage.aspx</ActionLink>
</shownode>
</destfield>
</node>
<node>
<sourcefield>
<fieldname>status</fieldname>
<ifeq>paused</ifeq>
</sourcefield>
<destfield>
<shownode>
<Name>Set in progress</Name>
<ImageUrl>/SiteCollectionImages/ppubicon.gif</ImageUrl>
<ActionLink>/Pages/TestPage.aspx</ActionLink>
</shownode>
</destfield>
</node>

</nodes>

Here the <sourcefield> tag talks about workflow status and <destfield> talks about what to display in custom context menu

I have a issue tracking list as shown in fig





After installing and activating the feature the issue tracking list looks like below see it displays custom context menu based on status of workflow




Using this feature you can modify your custom context menu in minutes

Please mail me for source code raja.mandalapu@gmail.com

Happy coding...

0 comments:

Post a Comment