Monday, February 22, 2010

Add “Edit Item” link or remove “View Properties” link on SharePoint Discussion board Flat/Threaded views

One of my clients had a requirement to add "Edit Item" link on SharePoint Discussion Board Flat/Threaded View like this…

I had searched a lot on the Google to find an answer, but wasn't able to find one. Finally I had decided to dig through SharePoint file system and find how it works.

As we all know all the lists in SharePoint are features so I went in to this location "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\TEMPLATE\FEATURES\DiscussionsList\Discuss" to open the schema.xml file for Discussion boards. I went through all the code but was not able to exactly find where this "View Properties" link is getting generated. After spending lot of time swimming through the code finally I got a code block which generates "View Properties" link. The code which generates "View Properties" is the field with the name "StatusBar" as shown below.


Now in the "StatusBar" you have something called "DisplayPattern" which contains the code for displaying "View Properties". So I have decided to add "Edit Item" link before "View Properties" link.

Below is the code to add "Edit Item" link before "
View Properties"

I you want to remove "View Properties" link then simply comment the code highlighted in blue.

Note: Making Changes to the Schema file of Discussion Board will affect all the lists of type Discussion Board across the SharePoint farm. So I suggest to create a Custom Discussion Board list definition and implement in that.

You can also add "Edit Item" link like below, without modifying the SharePoint Custom Discussion Board list definition using jQuery Like this…

<script type="text/javascript" src="../../Shared Documents/jquery-1.4.2.js"></script>
<script type="text/javascript">
$(document).ready(function(){
//debugger;
//To display edit link after reply
$("a:contains('Reply')").each(function(index) {
//debugger;
var dispFormID = $(this).closest('td').siblings().find("a:contains('View Properties')")[0].search;
dispFormID = dispFormID.substring(0,(dispFormID.indexOf('&', 0)+1));
var itemID = dispFormID.substring((dispFormID.indexOf('=', 0)+1),(dispFormID.length)-1);
var parentID = "&amp;DiscussionParentID="+itemID;
var editformWithID = "EditForm.aspx"+dispFormID;
var editLink = $(this).closest('td')[0].outerHTML;
editLink = replaceAll(editLink,"reply.gif", "edititem.gif");
editLink = replaceAll(editLink,"Reply", "Edit");
editLink = ReplaceAll(editLink,"&amp;ContentTypeId=0x0107", "");
editLink = ReplaceAll(editLink,"NewForm.aspx?", editformWithID);
editLink = ReplaceAll(editLink,parentID, "");
editLink = "<td class=ms-separator><img src='/_layouts/images/blank.gif' alt=''></td>"+editLink;
$(this).closest('td').parent().append($(editLink));
});
});

function replaceAll(txt, replace, with_this)
{
return txt.replace(new RegExp(replace, 'g'),with_this);
}

function ReplaceAll(Source,stringToFind,stringToReplace)
{
var temp = Source;
var index = temp.indexOf(stringToFind);
while(index != -1){
temp = temp.replace(stringToFind,stringToReplace);
index = temp.indexOf(stringToFind);
}
return temp;
}
</script>

1 comment:

  1. This comment has been removed by a blog administrator.

    ReplyDelete