Commit 098929265cf3d46a7aca73189aebd428fcaa6c76
1 parent
a53aaa49
Exists in
master
and in
23 other branches
[tolerance-time] Edit comment infra-structure
Showing
6 changed files
with
38 additions
and
5 deletions
Show diff stats
app/controllers/public/content_viewer_controller.rb
| @@ -2,6 +2,8 @@ class ContentViewerController < ApplicationController | @@ -2,6 +2,8 @@ class ContentViewerController < ApplicationController | ||
| 2 | 2 | ||
| 3 | needs_profile | 3 | needs_profile |
| 4 | 4 | ||
| 5 | + before_filter :comment_author, :only => :edit_comment | ||
| 6 | + | ||
| 5 | helper ProfileHelper | 7 | helper ProfileHelper |
| 6 | helper TagsHelper | 8 | helper TagsHelper |
| 7 | 9 | ||
| @@ -106,6 +108,22 @@ class ContentViewerController < ApplicationController | @@ -106,6 +108,22 @@ class ContentViewerController < ApplicationController | ||
| 106 | end | 108 | end |
| 107 | end | 109 | end |
| 108 | 110 | ||
| 111 | + def edit_comment | ||
| 112 | + path = params[:page].join('/') | ||
| 113 | + @page = profile.articles.find_by_path(path) | ||
| 114 | + @form_div = 'opened' | ||
| 115 | + @comment = Comment.find(params[:id]) | ||
| 116 | + if request.post? | ||
| 117 | + begin | ||
| 118 | + @comment.update_attributes(params[:comment]) | ||
| 119 | + session[:notice] = _('Comment updated.') | ||
| 120 | + redirect_to :action => 'view_page', :profile => profile.identifier, :page => @comment.article.explode_path | ||
| 121 | + rescue | ||
| 122 | + session[:notice] = _('Comment could not be updated.') | ||
| 123 | + end | ||
| 124 | + end | ||
| 125 | + end | ||
| 126 | + | ||
| 109 | protected | 127 | protected |
| 110 | 128 | ||
| 111 | def add_comment | 129 | def add_comment |
| @@ -173,4 +191,9 @@ class ContentViewerController < ApplicationController | @@ -173,4 +191,9 @@ class ContentViewerController < ApplicationController | ||
| 173 | end | 191 | end |
| 174 | end | 192 | end |
| 175 | 193 | ||
| 194 | + def comment_author | ||
| 195 | + comment = Comment.find(params[:id]) | ||
| 196 | + render_access_denied if comment.author.blank? || comment.author != user | ||
| 197 | + end | ||
| 198 | + | ||
| 176 | end | 199 | end |
app/views/content_viewer/_comment_form.rhtml
| @@ -39,7 +39,7 @@ function submit_comment_form(button) { | @@ -39,7 +39,7 @@ function submit_comment_form(button) { | ||
| 39 | d.find('input[name=comment[title]], textarea').val(''); | 39 | d.find('input[name=comment[title]], textarea').val(''); |
| 40 | d.find('.comment_form input[name=comment[<%= focus_on %>]]').focus(); | 40 | d.find('.comment_form input[name=comment[<%= focus_on %>]]').focus(); |
| 41 | }"> | 41 | }"> |
| 42 | - <%= content_tag('a', '', :name => 'comment_form') + _('Post a comment') %> | 42 | + <%= content_tag('a', '', :name => 'comment_form') + _('Post a comment') if display_link %> |
| 43 | </h4> | 43 | </h4> |
| 44 | 44 | ||
| 45 | <% unless pass_without_comment_captcha? %> | 45 | <% unless pass_without_comment_captcha? %> |
| @@ -59,7 +59,7 @@ function submit_comment_form(button) { | @@ -59,7 +59,7 @@ function submit_comment_form(button) { | ||
| 59 | </script> | 59 | </script> |
| 60 | <% end %> | 60 | <% end %> |
| 61 | 61 | ||
| 62 | -<% form_tag( url_for(@page.view_url.merge({:only_path => true})), { :class => 'comment_form' } ) do %> | 62 | +<% form_tag( url, { :class => 'comment_form' } ) do %> |
| 63 | <%= hidden_field_tag(:confirm, 'false') %> | 63 | <%= hidden_field_tag(:confirm, 'false') %> |
| 64 | 64 | ||
| 65 | <%= required_fields_message %> | 65 | <%= required_fields_message %> |
| @@ -84,7 +84,11 @@ function submit_comment_form(button) { | @@ -84,7 +84,11 @@ function submit_comment_form(button) { | ||
| 84 | 84 | ||
| 85 | <% button_bar do %> | 85 | <% button_bar do %> |
| 86 | <%= submit_button('add', _('Post comment'), :onclick => "submit_comment_form(this); return false") %> | 86 | <%= submit_button('add', _('Post comment'), :onclick => "submit_comment_form(this); return false") %> |
| 87 | - <%= button_to_function :cancel, _('Cancel'), "f=jQuery(this).parents('.post_comment_box'); f.removeClass('opened'); f.addClass('closed'); return false" %> | 87 | + <% if cancel_triggers_hide %> |
| 88 | + <%= button_to_function :cancel, _('Cancel'), "f=jQuery(this).parents('.post_comment_box'); f.removeClass('opened'); f.addClass('closed'); return false" %> | ||
| 89 | + <% else %> | ||
| 90 | + <%= button('cancel', _('Cancel'), {:action => 'view_page', :profile => profile.identifier, :page => @comment.article.explode_path})%> | ||
| 91 | + <% end %> | ||
| 88 | <% end %> | 92 | <% end %> |
| 89 | <% end %> | 93 | <% end %> |
| 90 | 94 |
app/views/content_viewer/view_page.rhtml
| @@ -86,7 +86,7 @@ | @@ -86,7 +86,7 @@ | ||
| 86 | </ul> | 86 | </ul> |
| 87 | 87 | ||
| 88 | <% if @page.accept_comments? %> | 88 | <% if @page.accept_comments? %> |
| 89 | - <div id="page-comment-form"><%= render :partial => 'comment_form' %></div> | 89 | + <div id="page-comment-form"><%= render :partial => 'comment_form', :locals => {:url => url_for(@page.view_url.merge({:only_path => true})), :display_link => true, :cancel_triggers_hide => true}%></div> |
| 90 | <script type="text/javascript"> | 90 | <script type="text/javascript"> |
| 91 | jQuery( function() { | 91 | jQuery( function() { |
| 92 | jQuery('.article-comment').live('mouseover', function() { jQuery(this).find('.icon-delete:first').show(); }); | 92 | jQuery('.article-comment').live('mouseover', function() { jQuery(this).find('.icon-delete:first').show(); }); |
config/routes.rb
| @@ -121,9 +121,12 @@ ActionController::Routing::Routes.draw do |map| | @@ -121,9 +121,12 @@ ActionController::Routing::Routes.draw do |map| | ||
| 121 | # cache stuff - hack | 121 | # cache stuff - hack |
| 122 | map.cache 'public/:action/:id', :controller => 'public' | 122 | map.cache 'public/:action/:id', :controller => 'public' |
| 123 | 123 | ||
| 124 | + map.connect ':profile/edit_comment/:id/*page', :controller => 'content_viewer', :action => 'edit_comment', :profile => /#{Noosfero.identifier_format}/ | ||
| 125 | + | ||
| 124 | # match requests for profiles that don't have a custom domain | 126 | # match requests for profiles that don't have a custom domain |
| 125 | map.homepage ':profile/*page', :controller => 'content_viewer', :action => 'view_page', :profile => /#{Noosfero.identifier_format}/, :conditions => { :if => lambda { |env| !Domain.hosting_profile_at(env[:host]) } } | 127 | map.homepage ':profile/*page', :controller => 'content_viewer', :action => 'view_page', :profile => /#{Noosfero.identifier_format}/, :conditions => { :if => lambda { |env| !Domain.hosting_profile_at(env[:host]) } } |
| 126 | 128 | ||
| 129 | + | ||
| 127 | # match requests for content in domains hosted for profiles | 130 | # match requests for content in domains hosted for profiles |
| 128 | map.connect '*page', :controller => 'content_viewer', :action => 'view_page' | 131 | map.connect '*page', :controller => 'content_viewer', :action => 'view_page' |
| 129 | 132 |
test/factories.rb
| @@ -442,7 +442,7 @@ module Noosfero::Factory | @@ -442,7 +442,7 @@ module Noosfero::Factory | ||
| 442 | 442 | ||
| 443 | def defaults_for_comment(params = {}) | 443 | def defaults_for_comment(params = {}) |
| 444 | name = "comment_#{rand(1000)}" | 444 | name = "comment_#{rand(1000)}" |
| 445 | - { :title => name, :body => "my own comment", :source_id => 1 }.merge(params) | 445 | + { :title => name, :body => "my own comment", :source_id => 1, :source_type => 'Article' }.merge(params) |
| 446 | end | 446 | end |
| 447 | 447 | ||
| 448 | ############################################### | 448 | ############################################### |