Make sure the moderation JS functions are executed after the page is fully loaded.

svn path=/plone.app.discussion/trunk/; revision=40215
This commit is contained in:
Timo Stollenwerk 2010-09-24 14:57:19 +00:00
parent 399bba5eca
commit 2ff95fe847
2 changed files with 140 additions and 122 deletions

View File

@ -4,7 +4,6 @@
* *
******************************************************************************/ ******************************************************************************/
(function ($) { (function ($) {
// This unnamed function allows us to use $ inside of a block of code // This unnamed function allows us to use $ inside of a block of code
// without permanently overwriting $. // without permanently overwriting $.

View File

@ -1,131 +1,150 @@
/******************************************************************************
*
* jQuery functions for the plone.app.discussion bulk moderation.
*
******************************************************************************/
(function ($) { (function ($) {
// 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
//#JSCOVERAGE_IF 0
/************************************************************************** /**************************************************************************
* Delete a single comment. * Window Load Function: Executes when complete page is fully loaded,
**************************************************************************/ * including all frames,
$("input[name='form.button.Delete']").click(function (e) { **************************************************************************/
e.preventDefault(); $(window).load(function () {
var button = $(this);
var row = $(this).parent().parent();
var form = $(row).parents("form");
var path = $(row).find("input:checkbox").attr("value");
var target = path + "/@@moderate-delete-comment";
var comment_id = $(this).attr("id");
$.ajax({
type: "GET",
url: target,
success: function (msg) {
// fade out row
$(row).fadeOut("normal", function () {
$(this).remove();
});
},
error: function (msg) {
alert("Error sending AJAX request:" + target);
}
});
});
/**********************************************************************
/************************************************************************** * Delete a single comment.
* Publish a single comment. **********************************************************************/
**************************************************************************/ $("input[name='form.button.Delete']").click(function (e) {
$("input[name='form.button.Publish']").click(function (e) { e.preventDefault();
e.preventDefault(); var button = $(this);
var button = $(this); var row = $(this).parent().parent();
var row = $(this).parent().parent(); var form = $(row).parents("form");
var form = $(row).parents("form"); var path = $(row).find("input:checkbox").attr("value");
var path = $(row).find("input:checkbox").attr("value"); var target = path + "/@@moderate-delete-comment";
var target = path + "/@@moderate-publish-comment"; var comment_id = $(this).attr("id");
$.ajax({ $.ajax({
type: "GET", type: "GET",
url: target, url: target,
data: "workflow_action=publish", success: function (msg) {
success: function (msg) { // fade out row
// fade out row $(row).fadeOut("normal", function () {
$(row).fadeOut("normal", function () { $(this).remove();
$(this).remove(); });
}); },
}, error: function (msg) {
error: function (msg) { alert("Error sending AJAX request:" + target);
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) {
valArray.each(function () {
/* Remove all selected lines. */
var row = $(this).parent().parent();
row.fadeOut("normal", function () {
row.remove();
});
});
});
// reset the bulkaction select
selectField.find("option[value='-1']").attr('selected', 'selected');
}
});
/************************************************************************** /**********************************************************************
* Check or uncheck all checkboxes from the batch moderation page. * Publish a single comment.
**************************************************************************/ **********************************************************************/
$("input[name='check_all']").click(function () { $("input[name='form.button.Publish']").click(function (e) {
if ($(this).val() === 0) { e.preventDefault();
$(this).parents("table") var button = $(this);
.find("input:checkbox") var row = $(this).parent().parent();
.attr("checked", "checked"); var form = $(row).parents("form");
$(this).val("1"); var path = $(row).find("input:checkbox").attr("value");
} else { var target = path + "/@@moderate-publish-comment";
$(this).parents("table") $.ajax({
.find("input:checkbox") type: "GET",
.attr("checked", ""); url: target,
$(this).val("0"); data: "workflow_action=publish",
} success: function (msg) {
}); // fade out row
$(row).fadeOut("normal", function () {
$(this).remove();
});
},
error: function (msg) {
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) {
valArray.each(function () {
/* Remove all selected lines. */
var row = $(this).parent().parent();
row.fadeOut("normal", function () {
row.remove();
});
});
});
// reset the bulkaction select
selectField.find("option[value='-1']").attr('selected', 'selected');
}
});
/************************************************************************** /**********************************************************************
* Show full text of a comment in the batch moderation page. * Check or uncheck all checkboxes from the batch moderation page.
**************************************************************************/ **********************************************************************/
$(".show-full-comment-text").click(function (e) { $("input[name='check_all']").click(function () {
e.preventDefault(); if ($(this).val() === 0) {
var target = $(this).attr("href"); $(this).parents("table")
var td = $(this).parent(); .find("input:checkbox")
$.ajax({ .attr("checked", "checked");
type: "GET", $(this).val("1");
url: target, } else {
data: "", $(this).parents("table")
success: function (data) { .find("input:checkbox")
// show full text .attr("checked", "");
td.replaceWith("<td>" + data + "</td>"); $(this).val("0");
}, }
error: function (msg) { });
alert("Error getting full comment text:" + target);
}
}); /**********************************************************************
* 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) {
alert("Error getting full comment text:" + target);
}
});
});
}); });
//#JSCOVERAGE_ENDIF
}(jQuery)); }(jQuery));