Fix JS comment deletion

If the comment tree had just one top level comment the whole tree was
removed by the JS code if just one comment in the tree was deleted.
These comments were (correctly) not removed from the ZODB.
This commit is contained in:
Gaudenz Steinlin 2012-05-07 11:11:19 +02:00
parent 1b0ba3c0b0
commit 4e0bf9f25e
2 changed files with 17 additions and 21 deletions

View File

@ -4,6 +4,9 @@ Changelog
2.1.6 (unreleased)
------------------
- Fix excessive JS comment deletion.
[gaudenz]
- No longer depend on zope.app packages.
[hannosch]

View File

@ -179,31 +179,24 @@
url: form_url,
context: $(trigger).parents(".comment"),
success: function (data) {
if ($(".discussion .replyTreeLevel0").length === 1) {
$(".discussion").fadeOut('fast', function () {
$(".discussion").remove();
});
var comment = $(this);
var clss = comment.attr('class');
// remove replies
var treelevel = parseInt(clss[clss.indexOf('replyTreeLevel') + 'replyTreeLevel'.length], 10);
// selector for all the following elements of lower level
var selector = ".replyTreeLevel" + treelevel;
for (var i = 0; i < treelevel; i++) {
selector += ", .replyTreeLevel" + i;
}
else {
var comment = $(this);
var clss = comment.attr('class');
// remove replies
var treelevel = parseInt(clss[clss.indexOf('replyTreeLevel') + 'replyTreeLevel'.length], 10);
// 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
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;