From 926e4f6b8ece0e107433f28f0d5e748ac4fd8932 Mon Sep 17 00:00:00 2001 From: Timo Stollenwerk Date: Wed, 27 Oct 2010 14:44:52 +0000 Subject: [PATCH] Integrate Denys ajax ui code. svn path=/plone.app.discussion/trunk/; revision=40852 --- .../browser/javascripts/comments.js | 95 ++++++++++++++++++- 1 file changed, 93 insertions(+), 2 deletions(-) diff --git a/plone/app/discussion/browser/javascripts/comments.js b/plone/app/discussion/browser/javascripts/comments.js index e3dd95b..eff4196 100644 --- a/plone/app/discussion/browser/javascripts/comments.js +++ b/plone/app/discussion/browser/javascripts/comments.js @@ -141,8 +141,6 @@ }); - - /********************************************************************** * By default, hide the reply and the cancel button for the regular add * comment form. @@ -159,6 +157,99 @@ * enabled. **********************************************************************/ $(".reply-to-comment-button").css("display" , "inline"); + + $("#form-buttons-comment").addClass("allowMultiSubmit"); + + + /********************************************************************** + * + **********************************************************************/ + $("[name='form.button.DeleteComment']").live('click', function() { + var trigger = this; + var form = $(this).parents("form"); + var data = $(form).serialize(); + var form_url = $(form).attr("action"); + $.ajax({ + type:'POST', + url:form_url, + context: $(trigger).parents(".comment"), + success: function(data) { + if($(".discussion .comment").length == 1) { + $(".discussion").fadeOut('fast', function() { + $(".discussion").remove(); + }); + } + else { + $(this).fadeOut('fast', function() { + $(this).remove(); + }); + } + }, + error: function(req, error) { + return true; + } + }); + return false; + }) + + $("[name='form.button.PublishComment']").live('click', function() { + alert("publish"); + var trigger = this; + var form = $(this).parents("form"); + var data = $(form).serialize(); + var form_url = $(form).attr("action"); + $.ajax({ + type: "GET", + url: form_url, + data: "workflow_action=publish", + context: trigger, + success: function (msg) { + // fade out row + $(this).parents("li").fadeOut("normal", function () { + $(this).parents("li").remove(); + }); + }, + error: function (msg) { + return true; + } + }); + return false; + }); + + $("#comment-form").submit(function(){ + var button = $("#comment-form .formControls input.submitting"); + // disable the submit button + $(button).attr('disabled', 'disabled'); + // we have to serialize the form data and append the name and value + // of the submit button, otherwise the form will not work. + var data = $("#comment-form").serialize() + '&' + $(button).attr("name") + '=' + $(button).attr("value"); + var form_url = $(this).attr("action"); + $(this).get(0).reset(); + $.ajax({ + type: 'POST', + url: form_url, + data: data, + success: function(data) { + var jqobj = $(data); + var new_comment; + if($(".discussion").length > 0) { + new_comment = $(jqobj).find(".discussion .comment:last-child"); + $(new_comment).hide(); + $(".discussion").append(new_comment); + } else { + new_comment = $(jqobj).find(".discussion"); + $(new_comment).hide(); + $(new_comment).insertBefore("#commenting"); + } + $(new_comment).fadeIn('slow'); + $(button).removeAttr('disabled'); + }, + error: function(req,error){ + return true + } + }); + return false; + }) });