Tuesday, November 20, 2012

SharePoint Discussion Board - Hide (View/Edit) Link

How do you conditionally hide (View Item) Link on the threaded view?
It is not the best way, in which the discussion board has the link displayed on the UI. Technically, there is a setting that you can set where a user who creates the post is only allowed to edit. However, that check only occurs when you click on Edit Item and SP will either display the edit page or will give access denied.

This is the JQuery I wrote to hide the link for each post comparing signed in user to the user who posted. If the 2 names are different, I hide the link and if they are same I replace the display value with "View/Edit".

$("a[href*='_layouts/userdisp.aspx']").each(function (index) {
            if ($(this).text().length > 0) {
                if ($(this).text().toLowerCase() != jQuery.trim(thisUserAccount.toLowerCase())) {
                    // Work $(this).parent().parent().parent().parent().parent()[0].firstChild.nextSibling.innerText = '';
                    $(this).parent().parent().parent().parent().parent()[0].firstChild.nextSibling.firstChild.firstChild.innerHTML = ''
                }
                else {
                    $(this).parent().parent().parent().parent().parent()[0].firstChild.nextSibling.firstChild.firstChild.innerHTML = '<NOBR>Edit/Delete</NOBR>';
                }
            }
        });

No comments:

Post a Comment