From f7ae6e49a5f146bfcb95d1f0d8e91786f2d05ea0 Mon Sep 17 00:00:00 2001 From: Katja Suess Date: Thu, 16 Jan 2020 15:32:46 +0100 Subject: [PATCH] unique css ids and bug fix test: editing comment: button label "save" instead of "edit comment" --- news/164.feature | 2 +- plone/app/discussion/browser/comments.pt | 17 +- .../browser/javascripts/comments.js | 477 +++++++++--------- .../tests/functional_test_comments.txt | 2 +- 4 files changed, 258 insertions(+), 240 deletions(-) diff --git a/news/164.feature b/news/164.feature index 0810d8f..c582a84 100644 --- a/news/164.feature +++ b/news/164.feature @@ -1,3 +1,3 @@ Extended existing review workflow by stati ``rejected`` and ``spam`` Moderation view extended to handle four workflow states. -[ksuess] +[ksuess and precious input of agitator] diff --git a/plone/app/discussion/browser/comments.pt b/plone/app/discussion/browser/comments.pt index 1dd26b6..6635bcc 100644 --- a/plone/app/discussion/browser/comments.pt +++ b/plone/app/discussion/browser/comments.pt @@ -32,6 +32,7 @@
@@ -95,7 +96,8 @@ class="commentactionsform" tal:condition="python:not canDelete and isDeleteOwnCommentAllowed and view.could_delete_own(reply)" tal:attributes="action string:${reply/absolute_url}/@@delete-own-comment; - style python:view.can_delete_own(reply) and 'display: inline' or 'display: none'"> + style python:view.can_delete_own(reply) and 'display: inline' or 'display: none'; + id string:delete-${comment_id}"> + tal:attributes="action string:${reply/absolute_url}/@@moderate-delete-comment; + id string:delete-${comment_id}"> - Edit @@ -129,7 +132,8 @@ method="get" class="commentactionsform" tal:condition="not: auth_token" - tal:attributes="action string:${reply/absolute_url}/@@edit-comment"> + tal:attributes="action string:${reply/absolute_url}/@@edit-comment; + id string:edit-${comment_id}"> + name action/id; + id string:${action/id}-${comment_id}"> *' - }); - } - - /********************************************************************** - * Delete a comment and its answers. - **********************************************************************/ - $('input[name="form.button.DeleteCommentComment"]').on('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, - data: data, - context: $(trigger).parents('.comment'), - success: function (data) { // jshint ignore:line - 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(); - }); - }); - // Add delete button to the parent - var parent = comment.prev('[class*="replyTreeLevel' + (treelevel - 1) + '"]'); - parent.find('form[name="delete"]').css('display', 'inline'); - // remove comment - $(this).fadeOut('fast', function () { - $(this).remove(); - }); - }, - error: function (req, error) { // jshint ignore:line - return true; - } - }); - return false; - }); - - - /********************************************************************** - * By default, hide the reply and the cancel button for the regular add - * comment form. - **********************************************************************/ - $('.reply').find('input[name="form.buttons.reply"]') - .css('display', 'none'); - $('.reply').find('input[name="form.buttons.cancel"]') - .css('display', 'none'); - - - /********************************************************************** - * By default, show the reply button only when Javascript is enabled. - * Otherwise hide it, since the reply functions only work with JS - * enabled. - **********************************************************************/ - $('.reply-to-comment-button').removeClass('hide'); + /************************************************************************** + * Window Load Function: Executes when complete page is fully loaded, + * including all frames, + **************************************************************************/ + $(window).load(function() { + /********************************************************************** + * If the user has hit the reply button of a reply-to-comment form + * (form was submitted with a value for the 'in_reply_to' field in the + * request), create a reply-to-comment form right under this comment. + **********************************************************************/ + var post_comment_div = $("#commenting"); + var in_reply_to_field = post_comment_div.find( + 'input[name="form.widgets.in_reply_to"]' + ); + if (in_reply_to_field.length !== 0 && in_reply_to_field.val() !== "") { + var current_reply_id = "#" + in_reply_to_field.val(); + var current_reply_to_div = $(".discussion").find(current_reply_id); + $.createReplyForm(current_reply_to_div); + $.clearForm(post_comment_div); + } + /********************************************************************** + * If the user hits the 'reply' button of an existing comment, create a + * reply form right beneath this comment. + **********************************************************************/ + $(".reply-to-comment-button").bind("click", function(e) { + // jshint ignore:line + var comment_div = $(this) + .parents() + .filter(".comment"); + $.createReplyForm(comment_div); + $.clearForm(comment_div); }); + /********************************************************************** + * If the user hits the 'clear' button of an open reply-to-comment form, + * remove the form and show the 'reply' button again. + **********************************************************************/ + $("#commenting #form-buttons-cancel").bind("click", function(e) { + e.preventDefault(); + var reply_to_comment_button = $(this) + .parents() + .filter(".comment") + .find(".reply-to-comment-button"); - //#JSCOVERAGE_ENDIF + /* 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() { + $(this).remove(); + }); + /* Show the reply-to-comment button again. */ + reply_to_comment_button.css("display", "inline"); + }); + + /********************************************************************** + * Transmit a single comment. + **********************************************************************/ + $('input[name="form.button.TransmitComment"]').on("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: data, + context: trigger, + success: function(msg) { + // jshint ignore:line + // remove button (trigger object can't be directly removed) + form.find('input[name="form.button.TransmitComment"]').remove(); + form + .parents(".state-pending") + .toggleClass("state-pending") + .toggleClass("state-published"); + }, + error: function(msg) { + // jshint ignore:line + return true; + } + }); + return false; + }); + + /********************************************************************** + * Edit a comment + **********************************************************************/ + if ($.fn.prepOverlay) { + $('form[name="edit"]').prepOverlay({ + cssclass: "overlay-edit-comment", + width: "60%", + subtype: "ajax", + filter: "#content>*" + }); + } + + /********************************************************************** + * Delete a comment and its answers. + **********************************************************************/ + $('input[name="form.button.DeleteComment"]').on("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, + data: data, + context: $(trigger).parents(".comment"), + success: function(data) { + // jshint ignore:line + 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(); + }); + }); + // Add delete button to the parent + var parent = comment.prev( + '[class*="replyTreeLevel' + (treelevel - 1) + '"]' + ); + parent.find('form[name="delete"]').css("display", "inline"); + // remove comment + $(this).fadeOut("fast", function() { + $(this).remove(); + }); + }, + error: function(req, error) { + // jshint ignore:line + return true; + } + }); + return false; + }); + + /********************************************************************** + * By default, hide the reply and the cancel button for the regular add + * comment form. + **********************************************************************/ + $(".reply") + .find('input[name="form.buttons.reply"]') + .css("display", "none"); + $(".reply") + .find('input[name="form.buttons.cancel"]') + .css("display", "none"); + + /********************************************************************** + * By default, show the reply button only when Javascript is enabled. + * Otherwise hide it, since the reply functions only work with JS + * enabled. + **********************************************************************/ + $(".reply-to-comment-button").removeClass("hide"); + }); + + //#JSCOVERAGE_ENDIF }); diff --git a/plone/app/discussion/tests/functional_test_comments.txt b/plone/app/discussion/tests/functional_test_comments.txt index 89bdecc..c78d4b8 100644 --- a/plone/app/discussion/tests/functional_test_comments.txt +++ b/plone/app/discussion/tests/functional_test_comments.txt @@ -285,7 +285,7 @@ Open the edit comment view Change and save the comment >>> ctrl.value = 'Comment from admin / was edited' - >>> browser.getControl('Edit comment').click() + >>> browser.getControl('Save').click() This used to trigger permissions problems in some portlet configurations. Check it ain't so.