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();
var form = jq(this);
var target = jq(this).attr('action');
var params = jq(this).serialize();
var cell = jq(this).parent().get(0);
var row = jq(cell).parent().get(0);
var currentFilter = jq(this).find("[name='form.button.Filter']").attr("value");
var currentAction = jq(this).attr("class");
var publishButton = jq(this).find(".comment-publish-button");
jq.post(target, params, function(data) {
if (currentAction == 'background-form workflow_action' && currentFilter == '') {
// remove the publish button
jq(publishButton).fadeOut("normal", function(){
jq(form).remove();
});
} else {
// remove the entire row
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-delete-comment";
var comment_id = jq(this).attr("id");
jq.ajax({
type: "GET",
url: target,
success: function(msg){
// fade out row
jq(row).fadeOut("normal", function(){
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)
*****************************************************************/
jq('form.bulkactions').submit(function(e) {
jq("input[name='form.button.BulkAction']").click(function(e) {
e.preventDefault();
var target = jq(this).attr('action');
var params = jq(this).serialize();
var form = jq(this).parents("form")
var target = jq(form).attr('action');
var params = jq(form).serialize();
var valArray = jq('input:checkbox:checked');
var currentFilter = jq(this).find("[name='form.button.Filter']").attr("value");
var currentAction = jq(this).find("[name='form.select.BulkAction']").val();
var selectField = jq(this).find("[name='form.select.BulkAction']");
var currentFilter = jq(form).find("[name='form.button.Filter']").attr("value");
var currentAction = jq(form).find("[name='form.select.BulkAction']").val();
var selectField = jq(form).find("[name='form.select.BulkAction']");
if (valArray.length) {
jq.post(target, params, function(data) {
valArray.each(function () {

View File

@ -115,32 +115,23 @@
<td tal:content="structure python:view.cook(item.Description)" />
<td style="width: 11em;">
<form action=""
class="background-form workflow_action"
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"
<input id=""
class="context comment-publish-button"
type="submit"
value="Publish"
name="form.button.Publish"
i18n:attributes="value label_publish"
tal:attributes="id item/id"
tal:condition="python:item.review_state == 'pending'"
/>
</form>
<form action=""
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"
<input id=""
class="destructive comment-delete-button"
type="submit"
value="Delete"
name="form.button.Delete"
i18n:attributes="value label_delete;"
tal:attributes="id item/id"
/>
</form>
</td>
</tr>
</tal:block>

View File

@ -104,7 +104,8 @@ class PublishComment(BrowserView):
comment = aq_inner(self.context)
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.doActionFor(comment, workflow_action)

View File

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