Udostępnij za pośrednictwem


How to: Enable Edit option for non anonymous comments in blogs

We have implemented an internal blog site using the MOSS 2007 blog template. One of the requirements was to support anonymous comments.

Since this is not an out-of-the-box feature, we searched and found a solution on the Microsoft SharePoint Team Blog site, https://blogs.msdn.com/sharepoint/archive/2007/08/06/anonymous-comment-feature-for-sharepoint-blog-now-available-on-codeplex.aspx

We implemented the custom web part, which is working out great. Unfortunately, there is one feature that the custom web part does not have, that the original New Comment web part does. This is the ability for the users to edit their own comments, once the comment has been posted. When the comment is posted anonymously, it makes sense that the user should not be able to edit the comment, since any association with the user is broken. However, if the user decides not to post the comment anonymously, then the requirement is to allow them to edit any of their previous comments.

 

Resolution 

Modify the JavaScript in the webpart as below.

var divElements = document.getElementsByTagName("div");
var accountNameDiv = null;
var annncount = "";
var cnt = 0;

for (var i = 0; i < divElements.length; i++) {
    var currentDivClassName = divElements[i].className.toLowerCase();
    accountNameDiv = divElements[i];
    // remove account name
    if (currentDivClassName.indexOf('ms-commentfooter') != -1) {
        cnt++;
        if (accountNameDiv.innerText.toLowerCase().indexOf('system account') != -1) {
            var innerHTMLField = accountNameDiv.innerHTML;
            var firstIndex = innerHTMLField.indexOf('</NOBR> at ');
            var secondIndex = innerHTMLField.length;
            var htmlDate = innerHTMLField.substring(firstIndex + 11, secondIndex);
            accountNameDiv.innerHTML = "Anonymous at " + htmlDate;
            annncount = annncount + " ," + cnt;
        }
        else if (accountNameDiv.innerText.toLowerCase().indexOf('chris stetkiewicz (alt)') != -1) {
            var aElements = accountNameDiv.getElementsByTagName("a");
            aElements[0].innerText = "Editor";
            aElements[0].href = "<https://my/Person.aspx?accountname=REDMOND%5Ccstek>";
        }
    }
}

var count = 0;
var tableElements = document.getElementsByTagName("table");
for (var k = 0; k < tableElements.length; k++) {
    if (tableElements[k].className.toLowerCase().indexOf('ms-commenttable') != -1) {      //alert('ss');
        var tdElements = tableElements[k].getElementsByTagName("td");
        for (var m = 0; m < tdElements.length; m++) {
            if (tdElements[m].className.toLowerCase().indexOf('ms-blogedit') != -1) {
                count++;
                if (annncount.indexOf("," + count) != -1)
                    tdElements[m].innerHTML = "";
            }
        }
    }
}