2010-09-24 16:57:19 +02:00
|
|
|
/******************************************************************************
|
2012-11-04 17:25:25 +01:00
|
|
|
*
|
2010-09-24 16:57:19 +02:00
|
|
|
* jQuery functions for the plone.app.discussion bulk moderation.
|
2012-11-04 17:25:25 +01:00
|
|
|
*
|
2010-09-24 16:57:19 +02:00
|
|
|
******************************************************************************/
|
2015-02-10 23:41:00 +01:00
|
|
|
/* global require, alert */
|
|
|
|
/* jshint quotmark: false */
|
2010-08-27 12:34:42 +02:00
|
|
|
|
2015-02-10 23:41:00 +01:00
|
|
|
if(require === undefined){
|
|
|
|
require = function(reqs, torun){ // jshint ignore:line
|
|
|
|
'use strict';
|
|
|
|
return torun(window.jQuery);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
require([ // jshint ignore:line
|
|
|
|
'jquery'
|
|
|
|
], function ($) {
|
|
|
|
'use strict';
|
2012-11-04 17:25:25 +01:00
|
|
|
// This unnamed function allows us to use $ inside of a block of code
|
2010-09-24 16:57:19 +02:00
|
|
|
// without permanently overwriting $.
|
|
|
|
// http://docs.jquery.com/Using_jQuery_with_Other_Libraries
|
2012-11-04 17:25:25 +01:00
|
|
|
|
2010-09-24 16:57:19 +02:00
|
|
|
//#JSCOVERAGE_IF 0
|
2012-11-04 17:25:25 +01:00
|
|
|
|
2010-06-04 11:25:47 +02:00
|
|
|
/**************************************************************************
|
2018-10-25 23:34:21 +02:00
|
|
|
* Document Ready Function: Executes when DOM is ready.
|
2012-11-04 17:25:25 +01:00
|
|
|
**************************************************************************/
|
2018-10-25 23:34:21 +02:00
|
|
|
$(document).ready(function () {
|
2012-11-04 17:25:25 +01:00
|
|
|
|
2011-04-22 17:43:58 +02:00
|
|
|
/**********************************************************************
|
|
|
|
* 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");
|
2015-09-19 14:58:53 +02:00
|
|
|
var auth_key = $('input[name="_authenticator"]').val();
|
|
|
|
var target = path + "/@@moderate-delete-comment?_authenticator=" + auth_key;
|
2011-04-22 17:43:58 +02:00
|
|
|
$.ajax({
|
|
|
|
type: "GET",
|
|
|
|
url: target,
|
2015-02-10 23:41:00 +01:00
|
|
|
success: function (msg) { // jshint ignore:line
|
2011-04-22 17:43:58 +02:00
|
|
|
// fade out row
|
|
|
|
$(row).fadeOut("normal", function () {
|
|
|
|
$(this).remove();
|
|
|
|
});
|
2011-07-15 19:29:29 +02:00
|
|
|
// reload page if all comments have been removed
|
|
|
|
var comments = $("table#review-comments > tbody > tr");
|
|
|
|
if (comments.length === 1) {
|
|
|
|
location.reload();
|
|
|
|
}
|
2011-04-22 17:43:58 +02:00
|
|
|
},
|
2015-02-10 23:41:00 +01:00
|
|
|
error: function (msg) { // jshint ignore:line
|
2011-04-22 17:43:58 +02:00
|
|
|
alert("Error sending AJAX request:" + target);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2012-11-04 17:25:25 +01:00
|
|
|
|
|
|
|
|
2011-04-22 17:43:58 +02:00
|
|
|
/**********************************************************************
|
|
|
|
* 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");
|
2015-09-19 14:58:53 +02:00
|
|
|
var auth_key = $('input[name="_authenticator"]').val();
|
|
|
|
var target = path + "/@@moderate-publish-comment?_authenticator=" + auth_key;
|
2011-04-22 17:43:58 +02:00
|
|
|
$.ajax({
|
|
|
|
type: "GET",
|
|
|
|
url: target,
|
2015-02-10 23:41:00 +01:00
|
|
|
success: function (msg) { // jshint ignore:line
|
2011-04-22 17:43:58 +02:00
|
|
|
// fade out row
|
|
|
|
$(row).fadeOut("normal", function () {
|
|
|
|
$(this).remove();
|
|
|
|
});
|
2011-07-15 19:29:29 +02:00
|
|
|
// reload page if all comments have been removed
|
|
|
|
var comments = $("table#review-comments > tbody > tr");
|
|
|
|
if (comments.length === 1) {
|
|
|
|
location.reload();
|
|
|
|
}
|
2011-04-22 17:43:58 +02:00
|
|
|
},
|
2015-02-10 23:41:00 +01:00
|
|
|
error: function (msg) { // jshint ignore:line
|
2011-04-22 17:43:58 +02:00
|
|
|
alert("Error sending AJAX request:" + target);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2012-11-04 17:25:25 +01:00
|
|
|
|
|
|
|
|
2011-04-22 17:43:58 +02:00
|
|
|
/**********************************************************************
|
|
|
|
* 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 {
|
2015-02-10 23:41:00 +01:00
|
|
|
$.post(target, params, function (data) { // jshint ignore:line
|
2011-04-22 17:43:58 +02:00
|
|
|
valArray.each(function () {
|
|
|
|
/* Remove all selected lines. */
|
|
|
|
var row = $(this).parent().parent();
|
|
|
|
row.fadeOut("normal", function () {
|
|
|
|
row.remove();
|
|
|
|
});
|
|
|
|
});
|
2011-07-15 19:29:29 +02:00
|
|
|
// reload page if all comments have been removed
|
|
|
|
var comments = $("table#review-comments > tbody > tr");
|
|
|
|
if (comments.length <= valArray.length) {
|
|
|
|
location.reload();
|
|
|
|
}
|
2011-04-22 17:43:58 +02:00
|
|
|
});
|
|
|
|
// reset the bulkaction select
|
|
|
|
selectField.find("option[value='-1']").attr('selected', 'selected');
|
|
|
|
}
|
|
|
|
});
|
2012-11-04 17:25:25 +01:00
|
|
|
|
|
|
|
|
2011-04-22 17:43:58 +02:00
|
|
|
/**********************************************************************
|
|
|
|
* 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");
|
|
|
|
}
|
|
|
|
});
|
2012-11-04 17:25:25 +01:00
|
|
|
|
|
|
|
|
2011-04-22 17:43:58 +02:00
|
|
|
/**********************************************************************
|
|
|
|
* Show full text of a comment in the batch moderation page.
|
|
|
|
**********************************************************************/
|
2012-11-04 17:25:25 +01:00
|
|
|
$(".show-full-comment-text").click(function (e) {
|
2011-04-22 17:43:58 +02:00
|
|
|
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>");
|
|
|
|
},
|
2015-02-10 23:41:00 +01:00
|
|
|
error: function (msg) { // jshint ignore:line
|
2011-04-22 17:43:58 +02:00
|
|
|
alert("Error getting full comment text:" + target);
|
|
|
|
}
|
2011-07-15 19:29:29 +02:00
|
|
|
});
|
2011-04-22 17:43:58 +02:00
|
|
|
});
|
2012-11-04 17:25:25 +01:00
|
|
|
|
2019-09-07 11:31:53 +02:00
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* Comments approved: Load history for approved date.
|
|
|
|
**********************************************************************/
|
|
|
|
$(".last-history-entry").each(function() {
|
|
|
|
$(this).load($(this).attr("data-href") + " .historyByLine", function() {
|
|
|
|
$(this).children(".historyByLine").last().remove();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2010-01-25 12:43:29 +01:00
|
|
|
});
|
2012-11-04 17:25:25 +01:00
|
|
|
|
2010-09-24 16:57:19 +02:00
|
|
|
//#JSCOVERAGE_ENDIF
|
2012-11-04 17:25:25 +01:00
|
|
|
|
2015-02-10 23:41:00 +01:00
|
|
|
});
|