Dev Qeuestion
cgdynamic2010 says:
Hello All,
Can anyone give me an example on how to delete a comment on another page.
I have created a page that loads all recent comments on all pages. each comment has a delete button. (to delete the comment on the page it resides on) below is my code
I understand that the code is server-side.
I am wondering if I am going to have to post data then reload the page and run a pre script to delete the comment.
Is there an easier way? Or would this even work at all?
If someone has tried this before, please throw me a bone...
Thank you in advance
cgdynamic
<span>
<script type="text/vnd.editme.js">
function gPage(pg){
return site.getPage(pg).comments;
}
function deleteComment(pg, commentId){
site.getPage(pg).Comments[commentId].destroy();
}
</script>
<div class="Page-Block" editme="foreach pg site.getAllPages(0)">
<div editme="if gPage(pg).length != 0">
<a editme="attr href pg.name" style="margin-bottom:0px;"><h1 editme="parse" style="margin-bottom:0px;">{pg.title}</h1></a><hr style="margin-top:0px; margin-bottom:15px"/>
<div class="Comment-Block" editme="foreach comment gPage(pg)" style=" background:#FFFFD6; border:#8DB9EB solid 1px; margin-bottom:10px; margin-left:20px;">
<div class="Comment-Head" style="background:#FFFFEE; border-bottom:#8DB9EB solid 1px; overflow:auto; width:100%;">
<div class="Comment-User" editme="parse" style="display:block; width:98%; float:left;">
<h2 style="color:#000000; font-size:14px;">On {comment.date} user <span style="color:#ff0000">{comment.user}</span> Posted</h2>
</div>
<div class="Comment-Delete" style="color:#FF0000; display:block; width:2%; float:right;">
<a editme="attr href page.name"><b>X</b></a> //////////Here is where i am lost////////////////////
</div>
</div>
<div class="Comment-Text" editme="parse"><![CDATA[{comment.comment}]]></div>
</div>
</div>
</div>
</span>
Posted at 1:48 AM on July 27, 2011
Nevermind, I got it figured out
Posted at 3:06 AM on July 27, 2011
In case someone else sees this, the problem with the above code is that its using a comment ID instead of an array index on this line:
site.getPage(pg).comments[commentId].destroy();
Instead, this should loop through the comments array until comment[index].id==commentId, then it should comment[index].destroy()
Posted at 12:58 AM on July 27, 2011
Sorry, Here is what I did. though it has some issues minor issues.
(will return and error every now and then on a delete)
maybe you can shed some light. code is below
Thank you in advance.
<span>
<script type="text/vnd.editme.js.pre"><![CDATA[
var params = server.requestParameters;
if (params.length != 0){
var pg = server.request(params[0]);
var cid = server.request(params[1]);
var spg = site.getPage(pg);
var comment = spg.getComment(parseInt(cid));
comment.destroy();
}
]]></script>
<script type="text/vnd.editme.js">
function gPage(pg){
return site.getPage(pg).comments;
}
</script>
<div class="Page-Block" editme="foreach pg site.getAllPages(0)">
<div editme="if gPage(pg).length != 0">
<a editme="attr href pg.name" style="margin-bottom:0px;"><h1 editme="parse" style="margin-bottom:0px;">{pg.title}</h1></a><hr style="margin-top:0px; margin-bottom:15px"/>
<div class="Comment-Block" editme="foreach comment gPage(pg)" style=" background:#FFFFD6; border:#8DB9EB solid 1px; margin-bottom:10px; margin-left:20px;">
<div class="Comment-Head" style="background:#FFFFEE; border-bottom:#8DB9EB solid 1px; overflow:auto; width:100%;">
<div class="Comment-User" editme="parse" style="display:block; width:98%; float:left;">
<h2 style="color:#000000; font-size:14px;">On {comment.date} user <span style="color:#ff0000">{comment.user}</span> Posted</h2>
</div>
<div class="Comment-Delete" style="color:#FF0000; display:block; width:2%; float:right;">
<a editme="attr href page.name +'?page=' + pg.name + '&cId=' + comment.id"><b>X</b></a>
</div>
</div>
<div class="Comment-Text" editme="parse"><![CDATA[{comment.comment}]]></div>
</div>
</div>
</div>
</span>
Posted at 7:26 PM on August 2, 2011