Ajaxify comment deletion and approval. thanks thomasdesvenain!

svn path=/plone.app.discussion/trunk/; revision=40984
This commit is contained in:
Timo Stollenwerk 2010-10-30 17:32:31 +00:00
parent 18d7aadd0e
commit cc96acb50a
2 changed files with 119 additions and 48 deletions

View File

@ -4,6 +4,9 @@ Changelog
1.0b11 (unreleased)
-------------------
- Ajaxify comment deletion and approval.
[thomasdesvenain]
- New feature: As a logged-in user, I can enable/disable email notification of
additional comments on this content object.
[timo]

View File

@ -3,13 +3,10 @@
* jQuery functions for the plone.app.discussion comment viewlet and form.
*
******************************************************************************/
(function ($) {
// This unnamed function allows us to use $ inside of a block of code
// without permanently overwriting $.
// http://docs.jquery.com/Using_jQuery_with_Other_Libraries
/**************************************************************************
* Create a reply-to-comment form right beneath the form that is passed to
* the function. We do this by copying the regular comment form and
@ -69,7 +66,7 @@
/* Show the cancel button in the reply-to-comment form */
cancel_reply_button.css("display", "inline");
}
};
/**************************************************************************
@ -82,7 +79,7 @@
form_div.find("input[type='text']").attr("value", "");
form_div.find("textarea").attr("value", "");
/* XXX: Clean all additional form extender fields. */
}
};
//#JSCOVERAGE_IF 0
@ -131,8 +128,8 @@
find(".reply-to-comment-button");
/* Find the reply-to-comment form and hide and remove it again. */
reply_to_comment_form = $(this).parents().filter(".reply");
reply_to_comment_form.slideUp("slow", function () {
$.reply_to_comment_form = $(this).parents().filter(".reply");
$.reply_to_comment_form.slideUp("slow", function () {
$(this).remove();
});
@ -142,6 +139,77 @@
});
/**********************************************************************
* Publish a single comment.
**********************************************************************/
$("input[name='form.button.PublishComment']").live('click', function () {
var trigger = this;
var form = $(this).parents("form");
var data = $(form).serialize();
var form_url = $(form).attr("action");
$.ajax({
type: "GET",
url: form_url,
data: "workflow_action=publish",
context: trigger,
success: function (msg) {
// remove button (trigger object can't be directly removed)
form.find("input[name='form.button.PublishComment']").remove();
form.parents(".state-pending").toggleClass('state-pending').toggleClass('state-published');
},
error: function (msg) {
return true;
}
});
return false;
});
/**********************************************************************
* Delete a comment and its answers.
**********************************************************************/
$("input[name='form.button.DeleteComment']").live('click', function () {
var trigger = this;
var form = $(this).parents("form");
var data = $(form).serialize();
var form_url = $(form).attr("action");
$.ajax({
type: 'POST',
url: form_url,
context: $(trigger).parents(".comment"),
success: function (data) {
if ($(".discussion .comment .replyTreeLevel0").length === 1) {
$(".discussion").fadeOut('fast', function () {
$(".discussion").remove();
});
}
else {
var comment = $(this);
var clss = comment.attr('class');
// remove replies
var treelevel = parseInt(clss[clss.indexOf('replyTreeLevel') + 'replyTreeLevel'.length]);
// selector for all the following elements of lower level
var selector = ".replyTreeLevel" + treelevel;
for (var i = 0; i < treelevel; i++) {
selector += ", .replyTreeLevel" + i;
}
comment.nextUntil(selector).each(function () {
$(this).fadeOut('fast', function () {
$(this).remove();
});
});
// remove comment
$(this).fadeOut('fast', function () {
$(this).remove();
});
}
},
error: function (req, error) {
return true;
}
});
return false;
});
/**********************************************************************
* By default, hide the reply and the cancel button for the regular add
@ -162,7 +230,7 @@
});
//#JSCOVERAGE_ENDIF
}(jQuery));