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

@ -20,30 +20,61 @@ jq(document).ready(function() {
/***************************************************************** /*****************************************************************
* 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(form).remove();
});
} else {
// remove the entire row
jq(row).fadeOut("normal", function(){ jq(row).fadeOut("normal", function(){
jq(this).remove(); jq(this).remove();
}); });
},
error: function(msg){
alert("Error sending AJAX request:" + target);
},
});
});
/*****************************************************************
* 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,14 +82,15 @@ 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 params = jq(form).serialize();
var valArray = jq('input:checkbox:checked'); var valArray = jq('input:checkbox:checked');
var currentFilter = jq(this).find("[name='form.button.Filter']").attr("value"); var currentFilter = jq(form).find("[name='form.button.Filter']").attr("value");
var currentAction = jq(this).find("[name='form.select.BulkAction']").val(); var currentAction = jq(form).find("[name='form.select.BulkAction']").val();
var selectField = jq(this).find("[name='form.select.BulkAction']"); 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 () {

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"
tal:attributes="action string:${item/getURL}/@@moderate-publish-comment"
tal:condition="python:item.review_state == 'pending'">
<input type="hidden" name="comment_id" tal:attributes="value item/getId" />
<input type="hidden" name="workflow_action" tal:attributes="value view/transition" />
<input type="hidden" name="form.button.Filter" tal:attributes="value filter" value="" />
<input class="context comment-publish-button"
type="submit" type="submit"
value="Publish" value="Publish"
name="form.button.Publish"
i18n:attributes="value label_publish" i18n:attributes="value label_publish"
tal:attributes="id item/id"
tal:condition="python:item.review_state == 'pending'"
/> />
</form> <input id=""
<form action="" class="destructive comment-delete-button"
method="post"
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" type="submit"
value="Delete" value="Delete"
name="form.button.Delete"
i18n:attributes="value label_delete;" i18n:attributes="value label_delete;"
tal:attributes="id item/id"
/> />
</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,11 +79,11 @@ 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;
} }