remove nested forms from moderate comments view. rewrite jquery code for comment delete and publish.

svn path=/plone.app.discussion/trunk/; revision=27750
This commit is contained in:
Timo Stollenwerk 2009-06-30 22:17:42 +00:00
parent 15b7347626
commit 2e04461162
4 changed files with 113 additions and 89 deletions

View File

@ -3,47 +3,78 @@ jq(document).ready(function() {
/***************************************************************** /*****************************************************************
* Check or uncheck all checkboxes * Check or uncheck all checkboxes
*****************************************************************/ *****************************************************************/
jq("input[name='check_all']").click(function(){ jq("input[name='check_all']").click(function(){
if(jq(this).val()==0){ if(jq(this).val()==0){
jq(this).parents("table") jq(this).parents("table")
.find("input:checkbox") .find("input:checkbox")
.attr("checked","checked"); .attr("checked","checked");
jq(this).val("1"); jq(this).val("1");
} }
else{ else{
jq(this).parents("table") jq(this).parents("table")
.find("input:checkbox") .find("input:checkbox")
.attr("checked",""); .attr("checked","");
jq(this).val("0"); jq(this).val("0");
} }
}); });
/***************************************************************** /*****************************************************************
* Comment actions (delete, publish) * Delete comment
*****************************************************************/ *****************************************************************/
jq('form.background-form').submit(function(e) { jq("input[name='form.button.Delete']").click(function(e) {
e.preventDefault(); e.preventDefault();
var form = jq(this); var button = jq(this);
var target = jq(this).attr('action'); var row = jq(this).parent().parent();
var params = jq(this).serialize(); var form = jq(row).parents("form");
var cell = jq(this).parent().get(0); var path = jq(row).find("input:checkbox").attr("value");
var row = jq(cell).parent().get(0); var target = path + "/@@moderate-delete-comment";
var currentFilter = jq(this).find("[name='form.button.Filter']").attr("value"); var comment_id = jq(this).attr("id");
var currentAction = jq(this).attr("class"); jq.ajax({
var publishButton = jq(this).find(".comment-publish-button"); type: "GET",
jq.post(target, params, function(data) { url: target,
if (currentAction == 'background-form workflow_action' && currentFilter == '') { success: function(msg){
// remove the publish button // fade out row
jq(publishButton).fadeOut("normal", function(){ jq(row).fadeOut("normal", function(){
jq(form).remove(); jq(this).remove();
}); });
} else { },
// remove the entire row error: function(msg){
jq(row).fadeOut("normal", function(){ alert("Error sending AJAX request:" + target);
jq(this).remove(); },
}); });
} });
/*****************************************************************
* Publish comment
*****************************************************************/
jq("input[name='form.button.Publish']").click(function(e) {
e.preventDefault();
var button = jq(this);
var row = jq(this).parent().parent();
var form = jq(row).parents("form");
var path = jq(row).find("input:checkbox").attr("value");
var target = path + "/@@moderate-publish-comment";
var currentFilter = jq(form).find("[name='form.button.Filter']").attr("value");
jq.ajax({
type: "GET",
url: target,
success: function(msg){
if (currentFilter == 'pending') {
// fade out row
jq(row).fadeOut("normal", function(){
jq(this).remove();
});
} else {
// fade out button
jq(button).fadeOut("normal", function(){
jq(this).remove();
});
}
},
error: function(msg){
alert("Error sending AJAX request:" + target);
},
}); });
}); });
@ -51,49 +82,50 @@ jq(document).ready(function() {
/***************************************************************** /*****************************************************************
* Bulk actions (delete, publish) * Bulk actions (delete, publish)
*****************************************************************/ *****************************************************************/
jq('form.bulkactions').submit(function(e) { jq("input[name='form.button.BulkAction']").click(function(e) {
e.preventDefault(); e.preventDefault();
var target = jq(this).attr('action'); var form = jq(this).parents("form")
var params = jq(this).serialize(); var target = jq(form).attr('action');
var valArray = jq('input:checkbox:checked'); var params = jq(form).serialize();
var currentFilter = jq(this).find("[name='form.button.Filter']").attr("value"); var valArray = jq('input:checkbox:checked');
var currentAction = jq(this).find("[name='form.select.BulkAction']").val(); var currentFilter = jq(form).find("[name='form.button.Filter']").attr("value");
var selectField = jq(this).find("[name='form.select.BulkAction']"); var currentAction = jq(form).find("[name='form.select.BulkAction']").val();
var selectField = jq(form).find("[name='form.select.BulkAction']");
if (valArray.length) { if (valArray.length) {
jq.post(target, params, function(data) { jq.post(target, params, function(data) {
valArray.each(function () { valArray.each(function () {
// if bulkaction is delete, or the current filter is // if bulkaction is delete, or the current filter is
// pending (because then publish also removes the comment), // pending (because then publish also removes the comment),
// remove all selected comments. // remove all selected comments.
if (currentAction == 'delete' || currentFilter == 'pending') { if (currentAction == 'delete' || currentFilter == 'pending') {
var row = jq(this).parent().parent(); var row = jq(this).parent().parent();
row.fadeOut("normal", function() { row.fadeOut("normal", function() {
row.remove(); row.remove();
}); });
} }
// bulkaction is publish and there is no current filter // bulkaction is publish and there is no current filter
if (currentAction == 'publish' && currentFilter == '') { if (currentAction == 'publish' && currentFilter == '') {
// remove the publish button // remove the publish button
var row = jq(this).parent().parent(); var row = jq(this).parent().parent();
var form = row.find("form.workflow_action"); var form = row.find("form.workflow_action");
var publishButton = row.find(".comment-publish-button"); var publishButton = row.find(".comment-publish-button");
var selectField = row.find("input:checkbox"); var selectField = row.find("input:checkbox");
jq(publishButton).fadeOut("normal", function(){ jq(publishButton).fadeOut("normal", function(){
jq(form).remove(); jq(form).remove();
}); });
// reset the select fields // reset the select fields
selectField.attr("checked",""); selectField.attr("checked","");
} }
}); });
}); });
} else { } else {
// The user has submitted a bulk action, but no comment // The user has submitted a bulk action, but no comment
// was selected. // was selected.
// Todo: nicer and translated message // Todo: nicer and translated message
alert("You haven't selected anything for this bulk action."); alert("You haven't selected anything for this bulk action.");
} }
// reset the bulkaction select // reset the bulkaction select
selectField.find("option[value='-1']").attr( 'selected', 'selected' ); selectField.find("option[value='-1']").attr( 'selected', 'selected' );
}); });
}); });

View File

@ -115,32 +115,23 @@
<td tal:content="structure python:view.cook(item.Description)" /> <td tal:content="structure python:view.cook(item.Description)" />
<td style="width: 11em;"> <td style="width: 11em;">
<form action="" <input id=""
class="background-form workflow_action" class="context comment-publish-button"
method="post" type="submit"
tal:attributes="action string:${item/getURL}/@@moderate-publish-comment" value="Publish"
tal:condition="python:item.review_state == 'pending'"> name="form.button.Publish"
<input type="hidden" name="comment_id" tal:attributes="value item/getId" /> i18n:attributes="value label_publish"
<input type="hidden" name="workflow_action" tal:attributes="value view/transition" /> tal:attributes="id item/id"
<input type="hidden" name="form.button.Filter" tal:attributes="value filter" value="" /> tal:condition="python:item.review_state == 'pending'"
<input class="context comment-publish-button" />
type="submit" <input id=""
value="Publish" class="destructive comment-delete-button"
i18n:attributes="value label_publish" type="submit"
/> value="Delete"
</form> name="form.button.Delete"
<form action="" i18n:attributes="value label_delete;"
method="post" tal:attributes="id item/id"
class="background-form delete" />
tal:attributes="action string:${item/getURL}/@@moderate-delete-comment">
<input type="hidden" name="comment_id" tal:attributes="value item/getId" />
<input type="hidden" name="form.button.Filter" tal:attributes="value filter" value="" />
<input class="destructive comment-delete-button"
type="submit"
value="Delete"
i18n:attributes="value label_delete;"
/>
</form>
</td> </td>
</tr> </tr>
</tal:block> </tal:block>

View File

@ -104,7 +104,8 @@ class PublishComment(BrowserView):
comment = aq_inner(self.context) comment = aq_inner(self.context)
comment_id = self.context.id comment_id = self.context.id
workflow_action = self.request.form['workflow_action'] #workflow_action = self.request.form['workflow_action']
workflow_action = 'publish'
portal_workflow = getToolByName(comment, 'portal_workflow') portal_workflow = getToolByName(comment, 'portal_workflow')
portal_workflow.doActionFor(comment, workflow_action) portal_workflow.doActionFor(comment, workflow_action)

View File

@ -79,12 +79,12 @@ ul.filter {
margin: 0.45em 0; margin: 0.45em 0;
} }
form.workflow_action { .comment-publish-button {
float: left; float: left;
} }
form.delete { .comment-delete-button {
float: right; float: right;
} }
#review-comments { #review-comments {