Monday, April 27, 2009

Add Custom Menu to List Item and Document Library Item

var siteUrl = GetSiteUrl();

function Custom_AddListMenuItems(m, ctx)
{
var copyCurrentItemId = currentItemID;
var titleText = null;

// Add Open Workspace menu item
var strDisplayText = "Request Home";
var strAction = "document.location.href='"+siteUrl+"/DCP/RequestPage.aspx?Request="+titleText+"&ID="+copyCurrentItemId+"'";
CAMOpt(m, strDisplayText, strAction);
CAMSep(m);


// false means that the standard menu items should also rendered

return false;
}

function me()
{
window.location = siteUrl + "/DCP/NewRequestByMgr.aspx?&Source="+GetSource();
}

function GetSiteUrl()
{
var siteUrl = window.location.href;
var copyOfSiteUrl = siteUrl;
siteUrl = siteUrl.split("/");
var isSubSite = false;
var url = null;

if(siteUrl[3] == 'sites')
{
isSubSite = true;

}
if(isSubSite)
{
copyOfSiteUrl = copyOfSiteUrl.split("sites/");
var subSiteName = copyOfSiteUrl[1].split("/");
url = copyOfSiteUrl[0] + "sites/" + subSiteName[0];
return url;
}
else
{
copyOfSiteUrl = copyOfSiteUrl.split("/");
url = copyOfSiteUrl[0] + "//" + copyOfSiteUrl[2];
return url;
}
}


For document library use
function AddDocLibMenuItems(m, ctx)
{
if (typeof(Custom_AddDocLibMenuItems) != “undefined”)
{
if (Custom_AddDocLibMenuItems(m, ctx))
return;
}
}
function instead of Custom_AddListMenuItems(m, ctx)
{
.....
}

No comments: