Moderation on commented page also with ajax like on moderation view
This commit is contained in:
parent
f7ae6e49a5
commit
61545c6ef6
@ -106,13 +106,109 @@ require([
|
|||||||
/* XXX: Clean all additional form extender fields. */
|
/* XXX: Clean all additional form extender fields. */
|
||||||
};
|
};
|
||||||
|
|
||||||
//#JSCOVERAGE_IF 0
|
function init_comment_eventhandler () {
|
||||||
|
/**********************************************************************
|
||||||
|
* Transmit a single comment.
|
||||||
|
**********************************************************************/
|
||||||
|
$('input[name="form.button.TransmitComment"]').on("click", function(e) {
|
||||||
|
e.preventDefault();
|
||||||
|
var trigger = this;
|
||||||
|
var form = $(this).parents("form");
|
||||||
|
var data = $(form).serialize();
|
||||||
|
var form_url = $(form).attr("action");
|
||||||
|
var comment_id = $(this).parents(".comment").attr("id");
|
||||||
|
$.ajax({
|
||||||
|
type: "GET",
|
||||||
|
url: form_url,
|
||||||
|
data: data,
|
||||||
|
context: trigger,
|
||||||
|
success: function(msg) {
|
||||||
|
let url = location.href;
|
||||||
|
$(this).parents(".comment").load(
|
||||||
|
// loading child nodes is not enough,
|
||||||
|
// class attributes are needed for visualization of workflow_state
|
||||||
|
url + " #" + comment_id + ".comment",
|
||||||
|
function() {
|
||||||
|
$(this).find(".comment").unwrap();
|
||||||
|
init_comment_eventhandler();
|
||||||
|
$(".pat-plone-modal").patPloneModal();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
},
|
||||||
|
error: function(msg) {
|
||||||
|
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(e) {
|
||||||
|
e.preventDefault();
|
||||||
|
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;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
$(document).ready(function() {
|
||||||
|
init_comment_eventhandler();
|
||||||
|
|
||||||
/**************************************************************************
|
|
||||||
* 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
|
* 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
|
* (form was submitted with a value for the 'in_reply_to' field in the
|
||||||
@ -165,98 +261,6 @@ require([
|
|||||||
reply_to_comment_button.css("display", "inline");
|
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
|
* By default, hide the reply and the cancel button for the regular add
|
||||||
* comment form.
|
* comment form.
|
||||||
@ -276,5 +280,4 @@ require([
|
|||||||
$(".reply-to-comment-button").removeClass("hide");
|
$(".reply-to-comment-button").removeClass("hide");
|
||||||
});
|
});
|
||||||
|
|
||||||
//#JSCOVERAGE_ENDIF
|
|
||||||
});
|
});
|
||||||
|
@ -15,10 +15,10 @@ require(["jquery", "pat-registry"], function($, registry) {
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
init();
|
init_moderation_eventhandler();
|
||||||
});
|
});
|
||||||
|
|
||||||
function init() {
|
function init_moderation_eventhandler() {
|
||||||
/**********************************************************************
|
/**********************************************************************
|
||||||
* Delete a single comment.
|
* Delete a single comment.
|
||||||
**********************************************************************/
|
**********************************************************************/
|
||||||
@ -83,7 +83,7 @@ require(["jquery", "pat-registry"], function($, registry) {
|
|||||||
$("#review-comments").load(
|
$("#review-comments").load(
|
||||||
url + " #review-comments > *",
|
url + " #review-comments > *",
|
||||||
function() {
|
function() {
|
||||||
init();
|
init_moderation_eventhandler();
|
||||||
$(".pat-plone-modal").patPloneModal();
|
$(".pat-plone-modal").patPloneModal();
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@ -129,7 +129,7 @@ require(["jquery", "pat-registry"], function($, registry) {
|
|||||||
$("#review-comments").load(
|
$("#review-comments").load(
|
||||||
window.location + " #review-comments",
|
window.location + " #review-comments",
|
||||||
function() {
|
function() {
|
||||||
init();
|
init_moderation_eventhandler();
|
||||||
$(".pat-plone-modal").patPloneModal();
|
$(".pat-plone-modal").patPloneModal();
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@ -174,8 +174,8 @@ require(["jquery", "pat-registry"], function($, registry) {
|
|||||||
|
|
||||||
$("#fieldset-moderate-comments")
|
$("#fieldset-moderate-comments")
|
||||||
.parent()
|
.parent()
|
||||||
.load(url + " #fieldset-moderate-comments", function() {
|
.load(url + " #content form > *", function() {
|
||||||
init();
|
init_moderation_eventhandler();
|
||||||
$(".pat-plone-modal").patPloneModal();
|
$(".pat-plone-modal").patPloneModal();
|
||||||
let stateObj = { review_state: review_state };
|
let stateObj = { review_state: review_state };
|
||||||
history.pushState(stateObj, "moderate comments", url);
|
history.pushState(stateObj, "moderate comments", url);
|
||||||
@ -224,5 +224,5 @@ require(["jquery", "pat-registry"], function($, registry) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
} // end init
|
} // end init_moderation_eventhandler
|
||||||
});
|
});
|
||||||
|
@ -3,6 +3,7 @@ from AccessControl import getSecurityManager
|
|||||||
from AccessControl import Unauthorized
|
from AccessControl import Unauthorized
|
||||||
from Acquisition import aq_inner
|
from Acquisition import aq_inner
|
||||||
from Acquisition import aq_parent
|
from Acquisition import aq_parent
|
||||||
|
from plone import api
|
||||||
from plone.app.discussion.events import CommentPublishedEvent
|
from plone.app.discussion.events import CommentPublishedEvent
|
||||||
from plone.app.discussion.events import CommentTransitionEvent
|
from plone.app.discussion.events import CommentTransitionEvent
|
||||||
from plone.app.discussion.events import CommentDeletedEvent
|
from plone.app.discussion.events import CommentDeletedEvent
|
||||||
@ -260,16 +261,14 @@ class CommentTransition(BrowserView):
|
|||||||
"""Call CommentTransition."""
|
"""Call CommentTransition."""
|
||||||
comment = aq_inner(self.context)
|
comment = aq_inner(self.context)
|
||||||
content_object = aq_parent(aq_parent(comment))
|
content_object = aq_parent(aq_parent(comment))
|
||||||
workflowTool = getToolByName(comment, 'portal_workflow', None)
|
|
||||||
workflow_action = self.request.form.get('workflow_action', 'publish')
|
workflow_action = self.request.form.get('workflow_action', 'publish')
|
||||||
review_state = workflowTool.getInfoFor(comment, 'review_state', '')
|
api.content.transition(comment, transition=workflow_action)
|
||||||
workflowTool.doActionFor(comment, workflow_action)
|
|
||||||
comment.reindexObject()
|
comment.reindexObject()
|
||||||
content_object.reindexObject(idxs=['total_comments'])
|
content_object.reindexObject(idxs=['total_comments'])
|
||||||
notify(CommentPublishedEvent(self.context, comment))
|
notify(CommentPublishedEvent(self.context, comment))
|
||||||
# for complexer workflows:
|
# for complexer workflows:
|
||||||
notify(CommentTransitionEvent(self.context, comment))
|
notify(CommentTransitionEvent(self.context, comment))
|
||||||
review_state_new = workflowTool.getInfoFor(comment, 'review_state', '')
|
review_state_new = api.content.get_state(comment, '')
|
||||||
|
|
||||||
comment_state_translated = self.context.restrictedTraverse("translationhelper").translate_comment_review_state(review_state_new)
|
comment_state_translated = self.context.restrictedTraverse("translationhelper").translate_comment_review_state(review_state_new)
|
||||||
|
|
||||||
@ -278,8 +277,7 @@ class CommentTransition(BrowserView):
|
|||||||
default='Comment ${comment_state_translated}.',
|
default='Comment ${comment_state_translated}.',
|
||||||
mapping={"comment_state_translated": comment_state_translated})
|
mapping={"comment_state_translated": comment_state_translated})
|
||||||
translated = self.context.translate(msgid)
|
translated = self.context.translate(msgid)
|
||||||
IStatusMessage(self.context.REQUEST).addStatusMessage(
|
api.portal.show_message(translated, self.context.REQUEST)
|
||||||
translated, type='info')
|
|
||||||
|
|
||||||
came_from = self.context.REQUEST.HTTP_REFERER
|
came_from = self.context.REQUEST.HTTP_REFERER
|
||||||
# if the referrer already has a came_from in it, don't redirect back
|
# if the referrer already has a came_from in it, don't redirect back
|
||||||
|
Loading…
Reference in New Issue
Block a user