Commit ce16e1fc authored by Kedar A.'s avatar Kedar A. 💻

Delete discussion-reply feature provided according to user policy

parent 43beb6e1
......@@ -278,48 +278,54 @@
function deleteReply(sourceObj)
{
var reply_id = $(sourceObj).closest("div.disc-replies").attr("data-reply-id");
if( user_access == "allow" && edit_policy == "allow" )
{
var reply_id = $(sourceObj).closest("div.disc-replies").attr("data-reply-id");
var nodesToDeleteArr = getChildReplies(reply_id, []);
nodesToDeleteArr.push(reply_id); // adding current node's _id
var nodesToDeleteArr = getChildReplies(reply_id, []);
nodesToDeleteArr.push(reply_id); // adding current node's _id
var deleteConfirm;
var deleteConfirm;
if(nodesToDeleteArr.length > 1)
{
deleteConfirm = confirm("Along with this reply, total of: " + nodesToDeleteArr.length + " replies would get deleted.\nClick 'OK' to delete. Else click on 'Cancel'");
}
else
{
deleteConfirm = confirm("Are you sure to delete this reply ?\nClick 'OK' to delete.");
}
if(nodesToDeleteArr.length > 1)
{
deleteConfirm = confirm("Along with this reply, total of: " + nodesToDeleteArr.length + " replies would get deleted.\nClick 'OK' to delete. Else click on 'Cancel'");
}
else
{
deleteConfirm = confirm("Are you sure to delete this reply ?\nClick 'OK' to delete.");
}
if(deleteConfirm)
{
$.ajax({
type: 'POST',
url: '{% url "discussion_delete_reply" group_id %}',
data: {
"csrfmiddlewaretoken": "{{ csrf_token }}",
"nodes_to_delete": JSON.stringify(nodesToDeleteArr)
},
success: function(data){
if(deleteConfirm)
{
$.ajax({
type: 'POST',
url: '{% url "discussion_delete_reply" group_id %}',
data: {
"csrfmiddlewaretoken": "{{ csrf_token }}",
"nodes_to_delete": JSON.stringify(nodesToDeleteArr)
},
success: function(data){
data = typeof(data) == "string" ? JSON.parse(data): data;
data = typeof(data) == "string" ? JSON.parse(data): data;
data.forEach(function(reply){
$("[data-reply-id="+ reply +"]").detach().fadeOut();
})
data.forEach(function(reply){
$("[data-reply-id="+ reply +"]").detach().fadeOut();
})
// updating tab-text
updateDiscussionTabText();
}
// updating tab-text
updateDiscussionTabText();
}
})
//end of ajax
})
//end of ajax
}
}
else
{
alert("To delete this reply you need to be login and be the member of this group.");
}
}
// recursive function to get child replies
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment