Additional (optional) workflow: "Comment Multiple State Review Workflow"
Moderator is not forced to delete a comment or to let it pending: Workflow has two more states "rejected" and "spam" to existing review workflow. Moderation view extended showing all states. Filter by state.
This commit is contained in:
@@ -162,9 +162,9 @@ require([ // jshint ignore:line
|
||||
|
||||
|
||||
/**********************************************************************
|
||||
* Publish a single comment.
|
||||
* Transmit a single comment.
|
||||
**********************************************************************/
|
||||
$('input[name="form.button.PublishComment"]').on('click', function () {
|
||||
$('input[name="form.button.TransmitComment"]').on('click', function () {
|
||||
var trigger = this;
|
||||
var form = $(this).parents('form');
|
||||
var data = $(form).serialize();
|
||||
@@ -176,7 +176,7 @@ require([ // jshint ignore:line
|
||||
context: trigger,
|
||||
success: function (msg) { // jshint ignore:line
|
||||
// remove button (trigger object can't be directly removed)
|
||||
form.find('input[name="form.button.PublishComment"]').remove();
|
||||
form.find('input[name="form.button.TransmitComment"]').remove();
|
||||
form.parents('.state-pending').toggleClass('state-pending').toggleClass('state-published');
|
||||
},
|
||||
error: function (msg) { // jshint ignore:line
|
||||
@@ -201,7 +201,7 @@ require([ // jshint ignore:line
|
||||
/**********************************************************************
|
||||
* Delete a comment and its answers.
|
||||
**********************************************************************/
|
||||
$('input[name="form.button.DeleteComment"]').on('click', function () {
|
||||
$('input[name="form.button.DeleteCommentComment"]').on('click', function () {
|
||||
var trigger = this;
|
||||
var form = $(this).parents('form');
|
||||
var data = $(form).serialize();
|
||||
|
||||
@@ -3,221 +3,230 @@
|
||||
* jQuery functions for the plone.app.discussion bulk moderation.
|
||||
*
|
||||
******************************************************************************/
|
||||
/* global require, alert */
|
||||
/* jshint quotmark: false */
|
||||
|
||||
if(require === undefined){
|
||||
require = function(reqs, torun){ // jshint ignore:line
|
||||
'use strict';
|
||||
return torun(window.jQuery);
|
||||
};
|
||||
if (require === undefined) {
|
||||
require = function(reqs, torun) {
|
||||
"use strict";
|
||||
return torun(window.jQuery);
|
||||
};
|
||||
}
|
||||
|
||||
require([ // jshint ignore:line
|
||||
'jquery'
|
||||
], function ($) {
|
||||
'use strict';
|
||||
// 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
|
||||
require(["jquery", "pat-registry"], function($, registry) {
|
||||
"use strict";
|
||||
|
||||
//#JSCOVERAGE_IF 0
|
||||
|
||||
/**************************************************************************
|
||||
* Document Ready Function: Executes when DOM is ready.
|
||||
**************************************************************************/
|
||||
$(document).ready(function () {
|
||||
|
||||
/**********************************************************************
|
||||
* Delete a single comment.
|
||||
**********************************************************************/
|
||||
$("input[name='form.button.Delete']").click(function (e) {
|
||||
e.preventDefault();
|
||||
var row = $(this).parent().parent();
|
||||
var path = $(row).find("[name='selected_obj_paths:list']").attr("value");
|
||||
var auth_key = $('input[name="_authenticator"]').val();
|
||||
var target = path + "/@@moderate-delete-comment?_authenticator=" + auth_key;
|
||||
$.ajax({
|
||||
type: "GET",
|
||||
url: target,
|
||||
success: function (msg) { // jshint ignore:line
|
||||
// fade out row
|
||||
$(row).fadeOut("normal", function () {
|
||||
$(this).remove();
|
||||
});
|
||||
// reload page if all comments have been removed
|
||||
var comments = $("table#review-comments > tbody > tr");
|
||||
if (comments.length === 1) {
|
||||
location.reload();
|
||||
}
|
||||
},
|
||||
error: function (msg) { // jshint ignore:line
|
||||
alert("Error sending AJAX request:" + target);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
/**********************************************************************
|
||||
* Publish a single comment.
|
||||
**********************************************************************/
|
||||
$("input[name='form.button.Publish']").click(function (e) {
|
||||
e.preventDefault();
|
||||
var row = $(this).parent().parent();
|
||||
var path = $(row).find("[name='selected_obj_paths:list']").attr("value");
|
||||
var auth_key = $('input[name="_authenticator"]').val();
|
||||
var target = path + "/@@moderate-publish-comment?_authenticator=" + auth_key;
|
||||
var moderate = $(this).closest("fieldset").attr("id") == "fieldset-moderate-comments";
|
||||
$.ajax({
|
||||
type: "GET",
|
||||
url: target,
|
||||
success: function (msg) { // jshint ignore:line
|
||||
if (moderate) {
|
||||
// fade out row
|
||||
$(row).fadeOut("normal", function () {
|
||||
$(this).remove();
|
||||
});
|
||||
// reload page if all comments have been removed
|
||||
var comments = $("table#review-comments > tbody > tr");
|
||||
if (comments.length === 1) {
|
||||
location.reload();
|
||||
}
|
||||
} else {
|
||||
location.reload();
|
||||
}
|
||||
},
|
||||
error: function (msg) { // jshint ignore:line
|
||||
alert("Error sending AJAX request:" + target);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
/**********************************************************************
|
||||
* Reject a single comment.
|
||||
**********************************************************************/
|
||||
$("input[name='form.button.Reject']").click(function (e) {
|
||||
e.preventDefault();
|
||||
var row = $(this).parent().parent();
|
||||
var path = $(row).find("[name='selected_obj_paths:list']").attr("value");
|
||||
var auth_key = $('input[name="_authenticator"]').val();
|
||||
var target = path + "/@@moderate-reject-comment?_authenticator=" + auth_key;
|
||||
var moderate = $(this).closest("fieldset").attr("id") == "fieldset-moderate-comments";
|
||||
$.ajax({
|
||||
type: "GET",
|
||||
url: target,
|
||||
success: function (msg) { // jshint ignore:line
|
||||
if (moderate) {
|
||||
// fade out row
|
||||
$(row).fadeOut("normal", function () {
|
||||
$(this).remove();
|
||||
});
|
||||
// reload page if all comments have been removed
|
||||
var comments = $("table#review-comments > tbody > tr");
|
||||
if (comments.length === 1) {
|
||||
location.reload();
|
||||
}
|
||||
} else {
|
||||
location.reload();
|
||||
}
|
||||
},
|
||||
error: function (msg) { // jshint ignore:line
|
||||
alert("Error sending AJAX request:" + target);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
/**********************************************************************
|
||||
* Bulk actions for comments (delete, publish)
|
||||
**********************************************************************/
|
||||
$("input[name='form.button.BulkAction']").click(function (e) {
|
||||
e.preventDefault();
|
||||
var form = $(this).parents("form");
|
||||
var target = $(form).attr('action');
|
||||
var params = $(form).serialize();
|
||||
var valArray = $('input:checkbox:checked');
|
||||
var selectField = $(form).find("[name='form.select.BulkAction']");
|
||||
if (selectField.val() === '-1') {
|
||||
// XXX: translate message
|
||||
alert("You haven't selected a bulk action. Please select one.");
|
||||
} else if (valArray.length === 0) {
|
||||
// XXX: translate message
|
||||
alert("You haven't selected any comment for this bulk action." +
|
||||
"Please select at least one comment.");
|
||||
} else {
|
||||
$.post(target, params, function (data) { // jshint ignore:line
|
||||
valArray.each(function () {
|
||||
/* Remove all selected lines. */
|
||||
var row = $(this).parent().parent();
|
||||
row.fadeOut("normal", function () {
|
||||
row.remove();
|
||||
});
|
||||
});
|
||||
// reload page if all comments have been removed
|
||||
var comments = $("table#review-comments > tbody > tr");
|
||||
if (comments.length <= valArray.length) {
|
||||
location.reload();
|
||||
}
|
||||
});
|
||||
// reset the bulkaction select
|
||||
selectField.find("option[value='-1']").attr('selected', 'selected');
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
/**********************************************************************
|
||||
* Check or uncheck all checkboxes from the batch moderation page.
|
||||
**********************************************************************/
|
||||
$("input[name='check_all']").click(function () {
|
||||
if ($(this).val() === '0') {
|
||||
$(this).parents("table")
|
||||
.find("input:checkbox")
|
||||
.attr("checked", "checked");
|
||||
$(this).val("1");
|
||||
} else {
|
||||
$(this).parents("table")
|
||||
.find("input:checkbox")
|
||||
.attr("checked", "");
|
||||
$(this).val("0");
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
/**********************************************************************
|
||||
* Show full text of a comment in the batch moderation page.
|
||||
**********************************************************************/
|
||||
$(".show-full-comment-text").click(function (e) {
|
||||
e.preventDefault();
|
||||
var target = $(this).attr("href");
|
||||
var td = $(this).parent();
|
||||
$.ajax({
|
||||
type: "GET",
|
||||
url: target,
|
||||
data: "",
|
||||
success: function (data) {
|
||||
// show full text
|
||||
td.replaceWith("<td>" + data + "</td>");
|
||||
},
|
||||
error: function (msg) { // jshint ignore:line
|
||||
alert("Error getting full comment text:" + target);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
/**********************************************************************
|
||||
* Comments approved: Load history for approved date.
|
||||
**********************************************************************/
|
||||
$(".last-history-entry").each(function() {
|
||||
$(this).load($(this).attr("data-href") + " .historyByLine", function() {
|
||||
let currententry = $(this).children(".historyByLine").first();
|
||||
$(this).html(currententry);
|
||||
});
|
||||
});
|
||||
$(document).ready(function() {
|
||||
init();
|
||||
});
|
||||
|
||||
function init() {
|
||||
/**********************************************************************
|
||||
* Delete a single comment.
|
||||
**********************************************************************/
|
||||
$("input[name='form.button.moderation.DeleteComment']").click(function(e) {
|
||||
e.preventDefault();
|
||||
var row = $(this).closest("tr");
|
||||
var path = row.find("[name='selected_obj_paths:list']").attr("value");
|
||||
var auth_key = $('input[name="_authenticator"]').val();
|
||||
var target =
|
||||
path + "/@@moderate-delete-comment?_authenticator=" + auth_key;
|
||||
$.ajax({
|
||||
type: "GET",
|
||||
url: target,
|
||||
success: function(msg) {
|
||||
// fade out row
|
||||
row.fadeOut(250).fadeIn(250, function() {
|
||||
row.remove();
|
||||
});
|
||||
// reload page if all comments have been removed
|
||||
var comments = $("table#review-comments > tbody > tr");
|
||||
if (comments.length === 1) {
|
||||
location.reload();
|
||||
}
|
||||
},
|
||||
error: function(msg) {
|
||||
alert("Error sending AJAX request:" + target);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
//#JSCOVERAGE_ENDIF
|
||||
/**********************************************************************
|
||||
* Transmit a single comment.
|
||||
**********************************************************************/
|
||||
$('input[name="form.button.moderation.TransmitComment"]').click(function(
|
||||
e
|
||||
) {
|
||||
e.preventDefault();
|
||||
let button = $(this);
|
||||
var row = $(this).closest("tr");
|
||||
var path = $(row)
|
||||
.find("[name='selected_obj_paths:list']")
|
||||
.attr("value");
|
||||
var workflow_action = $(this).attr("data-transition");
|
||||
var auth_key = $('input[name="_authenticator"]').val();
|
||||
// distinction of workflow_action
|
||||
var target =
|
||||
path +
|
||||
"/@@transmit-comment?_authenticator=" +
|
||||
auth_key +
|
||||
"&workflow_action=" +
|
||||
workflow_action;
|
||||
var moderate =
|
||||
$(this)
|
||||
.closest("fieldset")
|
||||
.attr("id") == "fieldset-moderate-comments";
|
||||
$.ajax({
|
||||
type: "GET",
|
||||
url: target,
|
||||
success: function(msg) {
|
||||
if (moderate) {
|
||||
let url = location.href;
|
||||
$("#review-comments").load(url + " #review-comments", function() {
|
||||
init();
|
||||
$(".pat-plone-modal").patPloneModal();
|
||||
});
|
||||
} else {
|
||||
location.reload();
|
||||
}
|
||||
},
|
||||
error: function(msg) {
|
||||
alert(
|
||||
"Error transmitting comment. (Error sending AJAX request:" +
|
||||
target +
|
||||
")"
|
||||
);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
/**********************************************************************
|
||||
* Bulk actions for comments (delete, publish)
|
||||
**********************************************************************/
|
||||
$("input[name='form.button.BulkAction']").click(function(e) {
|
||||
e.preventDefault();
|
||||
var form = $(this).parents("form");
|
||||
var target = $(form).attr("action");
|
||||
var params = $(form).serialize();
|
||||
var valArray = $("input:checkbox:checked");
|
||||
var selectField = $(form).find("[name='form.select.BulkAction']");
|
||||
if (selectField.val() === "-1") {
|
||||
// XXX: translate message
|
||||
alert("You haven't selected a bulk action. Please select one.");
|
||||
} else if (valArray.length === 0) {
|
||||
// XXX: translate message
|
||||
alert(
|
||||
"You haven't selected any comment for this bulk action." +
|
||||
"Please select at least one comment."
|
||||
);
|
||||
} else {
|
||||
$.post(target, params, function(data) {
|
||||
valArray.each(function() {
|
||||
/* Remove all selected lines. */
|
||||
var row = $(this)
|
||||
.parent()
|
||||
.parent();
|
||||
row.fadeOut("normal", function() {
|
||||
row.remove();
|
||||
});
|
||||
});
|
||||
// reload page if all comments have been removed
|
||||
var comments = $("table#review-comments > tbody > tr");
|
||||
if (comments.length <= valArray.length) {
|
||||
location.reload();
|
||||
}
|
||||
});
|
||||
// reset the bulkaction select
|
||||
selectField.find("option[value='-1']").attr("selected", "selected");
|
||||
}
|
||||
});
|
||||
|
||||
/**********************************************************************
|
||||
* Check or uncheck all checkboxes from the batch moderation page.
|
||||
**********************************************************************/
|
||||
$("input[name='check_all']").click(function() {
|
||||
if ($(this).val() === "0") {
|
||||
$(this)
|
||||
.parents("table")
|
||||
.find("input:checkbox")
|
||||
.prop("checked", true);
|
||||
$(this).val("1");
|
||||
} else {
|
||||
$(this)
|
||||
.parents("table")
|
||||
.find("input:checkbox")
|
||||
.prop("checked", false);
|
||||
$(this).val("0");
|
||||
}
|
||||
});
|
||||
|
||||
/**********************************************************************
|
||||
* select comments with review_state
|
||||
**********************************************************************/
|
||||
|
||||
$("input[name='review_state']").click(function() {
|
||||
// location.search = 'review_state=' + $(this).val();
|
||||
let review_state = $(this).val();
|
||||
let url = location.href;
|
||||
if (location.search) {
|
||||
url = location.href.replace(
|
||||
location.search,
|
||||
"?review_state=" + review_state
|
||||
);
|
||||
} else {
|
||||
url = location.href + "?review_state=" + review_state;
|
||||
}
|
||||
|
||||
$("#review-comments").load(url + " #review-comments", function() {
|
||||
init();
|
||||
$(".pat-plone-modal").patPloneModal();
|
||||
let stateObj = { review_state: review_state };
|
||||
history.pushState(stateObj, "moderate comments", url);
|
||||
});
|
||||
});
|
||||
|
||||
/**********************************************************************
|
||||
* Show full text of a comment in the batch moderation page.
|
||||
**********************************************************************/
|
||||
$(".show-full-comment-text").click(function(e) {
|
||||
e.preventDefault();
|
||||
var target = $(this).attr("href");
|
||||
var parent = $(this).parent();
|
||||
$.ajax({
|
||||
type: "GET",
|
||||
url: target,
|
||||
data: "",
|
||||
success: function(data) {
|
||||
// show full text
|
||||
parent.html(data);
|
||||
},
|
||||
error: function(msg) {
|
||||
alert("Error getting full comment text:" + target);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
/**********************************************************************
|
||||
* Comments approved: Load history for approved date.
|
||||
**********************************************************************/
|
||||
$(".last-history-entry").each(function() {
|
||||
var me = $(this);
|
||||
$.ajax({
|
||||
url: me.attr("data-href"),
|
||||
success: function(data) {
|
||||
let first_history_entry = $(data)
|
||||
.find(".historyByLine")
|
||||
.first();
|
||||
me.html("");
|
||||
first_history_entry.children().each(function() {
|
||||
me.append($(this));
|
||||
me.append("<br/>");
|
||||
});
|
||||
// format date
|
||||
registry.scan(me);
|
||||
},
|
||||
error: function(msg) {
|
||||
alert("Error getting history.");
|
||||
}
|
||||
});
|
||||
});
|
||||
} // end init
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user