From 098929265cf3d46a7aca73189aebd428fcaa6c76 Mon Sep 17 00:00:00 2001 From: Rodrigo Souto Date: Tue, 21 Aug 2012 14:17:15 -0300 Subject: [PATCH] [tolerance-time] Edit comment infra-structure --- app/controllers/public/content_viewer_controller.rb | 23 +++++++++++++++++++++++ app/views/content_viewer/_comment_form.rhtml | 10 +++++++--- app/views/content_viewer/edit_comment.html.erb | 3 +++ app/views/content_viewer/view_page.rhtml | 2 +- config/routes.rb | 3 +++ test/factories.rb | 2 +- 6 files changed, 38 insertions(+), 5 deletions(-) create mode 100644 app/views/content_viewer/edit_comment.html.erb diff --git a/app/controllers/public/content_viewer_controller.rb b/app/controllers/public/content_viewer_controller.rb index 4679dae..061e413 100644 --- a/app/controllers/public/content_viewer_controller.rb +++ b/app/controllers/public/content_viewer_controller.rb @@ -2,6 +2,8 @@ class ContentViewerController < ApplicationController needs_profile + before_filter :comment_author, :only => :edit_comment + helper ProfileHelper helper TagsHelper @@ -106,6 +108,22 @@ class ContentViewerController < ApplicationController end end + def edit_comment + path = params[:page].join('/') + @page = profile.articles.find_by_path(path) + @form_div = 'opened' + @comment = Comment.find(params[:id]) + if request.post? + begin + @comment.update_attributes(params[:comment]) + session[:notice] = _('Comment updated.') + redirect_to :action => 'view_page', :profile => profile.identifier, :page => @comment.article.explode_path + rescue + session[:notice] = _('Comment could not be updated.') + end + end + end + protected def add_comment @@ -173,4 +191,9 @@ class ContentViewerController < ApplicationController end end + def comment_author + comment = Comment.find(params[:id]) + render_access_denied if comment.author.blank? || comment.author != user + end + end diff --git a/app/views/content_viewer/_comment_form.rhtml b/app/views/content_viewer/_comment_form.rhtml index 8ca838c..2bc4e36 100644 --- a/app/views/content_viewer/_comment_form.rhtml +++ b/app/views/content_viewer/_comment_form.rhtml @@ -39,7 +39,7 @@ function submit_comment_form(button) { d.find('input[name=comment[title]], textarea').val(''); d.find('.comment_form input[name=comment[<%= focus_on %>]]').focus(); }"> - <%= content_tag('a', '', :name => 'comment_form') + _('Post a comment') %> + <%= content_tag('a', '', :name => 'comment_form') + _('Post a comment') if display_link %> <% unless pass_without_comment_captcha? %> @@ -59,7 +59,7 @@ function submit_comment_form(button) { <% end %> -<% form_tag( url_for(@page.view_url.merge({:only_path => true})), { :class => 'comment_form' } ) do %> +<% form_tag( url, { :class => 'comment_form' } ) do %> <%= hidden_field_tag(:confirm, 'false') %> <%= required_fields_message %> @@ -84,7 +84,11 @@ function submit_comment_form(button) { <% button_bar do %> <%= submit_button('add', _('Post comment'), :onclick => "submit_comment_form(this); return false") %> - <%= button_to_function :cancel, _('Cancel'), "f=jQuery(this).parents('.post_comment_box'); f.removeClass('opened'); f.addClass('closed'); return false" %> + <% if cancel_triggers_hide %> + <%= button_to_function :cancel, _('Cancel'), "f=jQuery(this).parents('.post_comment_box'); f.removeClass('opened'); f.addClass('closed'); return false" %> + <% else %> + <%= button('cancel', _('Cancel'), {:action => 'view_page', :profile => profile.identifier, :page => @comment.article.explode_path})%> + <% end %> <% end %> <% end %> diff --git a/app/views/content_viewer/edit_comment.html.erb b/app/views/content_viewer/edit_comment.html.erb new file mode 100644 index 0000000..0dbed2d --- /dev/null +++ b/app/views/content_viewer/edit_comment.html.erb @@ -0,0 +1,3 @@ +

<%= _('Edit comment') %>

+ +<%= render :partial => 'comment_form', :locals => {:url => {:action => 'edit_comment', :profile => profile.identifier}, :display_link => false, :cancel_triggers_hide => false} %> diff --git a/app/views/content_viewer/view_page.rhtml b/app/views/content_viewer/view_page.rhtml index 7ba980a..00b7666 100644 --- a/app/views/content_viewer/view_page.rhtml +++ b/app/views/content_viewer/view_page.rhtml @@ -86,7 +86,7 @@ <% if @page.accept_comments? %> -
<%= render :partial => 'comment_form' %>
+
<%= render :partial => 'comment_form', :locals => {:url => url_for(@page.view_url.merge({:only_path => true})), :display_link => true, :cancel_triggers_hide => true}%>