Adds posts quoting functionality (#1825).

git-svn-id: http://redmine.rubyforge.org/svn/trunk@1772 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2008-08-28 18:56:47 +00:00
parent 8f3a04ce69
commit bfd0fb067a
33 changed files with 69 additions and 1 deletions

View File

@ -22,7 +22,9 @@ class MessagesController < ApplicationController
before_filter :authorize, :except => :preview
verify :method => :post, :only => [ :reply, :destroy ], :redirect_to => { :action => :show }
verify :xhr => true, :only => :quote
helper :attachments
include AttachmentsHelper
@ -82,6 +84,20 @@ class MessagesController < ApplicationController
{ :action => 'show', :id => @message.parent }
end
def quote
user = @message.author
text = @message.content
content = "#{ll(Setting.default_language, :text_user_wrote, user)}\\n> "
content << text.to_s.strip.gsub(%r{<pre>((.|\s)*?)</pre>}m, '[...]').gsub('"', '\"').gsub(/(\r?\n|\r\n?)/, "\\n> ") + "\\n\\n"
render(:update) { |page|
page.<< "$('message_content').value = \"#{content}\";"
page.show 'reply'
page << "Form.Element.focus('message_content');"
page << "Element.scrollTo('reply');"
page << "$('message_content').scrollTop = $('message_content').scrollHeight - $('message_content').clientHeight;"
}
end
def preview
message = @board.messages.find_by_id(params[:id])
@attachements = message.attachments if message

View File

@ -34,6 +34,12 @@ module ApplicationHelper
def link_to_if_authorized(name, options = {}, html_options = nil, *parameters_for_method_reference)
link_to(name, options, html_options, *parameters_for_method_reference) if authorize_for(options[:controller] || params[:controller], options[:action])
end
# Display a link to remote if user is authorized
def link_to_remote_if_authorized(name, options = {}, html_options = nil)
url = options[:url] || {}
link_to_remote(name, options, html_options) if authorize_for(url[:controller] || params[:controller], url[:action])
end
# Display a link to user's account page
def link_to_user(user)

View File

@ -2,6 +2,7 @@
link_to(h(@board.name), {:controller => 'boards', :action => 'show', :project_id => @project, :id => @board}) %>
<div class="contextual">
<%= link_to_remote_if_authorized l(:button_quote), { :url => {:action => 'quote', :id => @topic} }, :class => 'icon icon-comment' %>
<%= link_to_if_authorized l(:button_edit), {:action => 'edit', :id => @topic}, :class => 'icon icon-edit' %>
<%= link_to_if_authorized l(:button_delete), {:action => 'destroy', :id => @topic}, :method => :post, :confirm => l(:text_are_you_sure), :class => 'icon icon-del' %>
</div>
@ -22,6 +23,7 @@
<% @replies.each do |message| %>
<a name="<%= "message-#{message.id}" %>"></a>
<div class="contextual">
<%= link_to_remote_if_authorized image_tag('comment.png'), { :url => {:action => 'quote', :id => message} }, :title => l(:button_quote) %>
<%= link_to_if_authorized image_tag('edit.png'), {:action => 'edit', :id => message}, :title => l(:button_edit) %>
<%= link_to_if_authorized image_tag('delete.png'), {:action => 'destroy', :id => message}, :method => :post, :confirm => l(:text_are_you_sure), :title => l(:button_delete) %>
</div>

View File

@ -635,3 +635,4 @@ text_email_delivery_not_configured: "Email delivery is not configured, and notif
field_parent_title: Parent page
label_issue_watchers: Watchers
setting_commit_logs_encoding: Commit messages encoding
button_quote: Quote

View File

@ -640,3 +640,4 @@ text_email_delivery_not_configured: "Email delivery is not configured, and notif
field_parent_title: Parent page
label_issue_watchers: Watchers
setting_commit_logs_encoding: Commit messages encoding
button_quote: Quote

View File

@ -637,3 +637,4 @@ text_email_delivery_not_configured: "Email delivery is not configured, and notif
field_parent_title: Parent page
label_issue_watchers: Watchers
setting_commit_logs_encoding: Commit messages encoding
button_quote: Quote

View File

@ -636,3 +636,4 @@ text_email_delivery_not_configured: "Email delivery is not configured, and notif
field_parent_title: Parent page
label_issue_watchers: Watchers
setting_commit_logs_encoding: Commit messages encoding
button_quote: Quote

View File

@ -561,6 +561,7 @@ button_copy: Copy
button_annotate: Annotate
button_update: Update
button_configure: Configure
button_quote: Quote
status_active: active
status_registered: registered

View File

@ -638,3 +638,4 @@ text_email_delivery_not_configured: "Email delivery is not configured, and notif
field_parent_title: Parent page
label_issue_watchers: Watchers
setting_commit_logs_encoding: Commit messages encoding
button_quote: Quote

View File

@ -635,3 +635,4 @@ text_email_delivery_not_configured: "Email delivery is not configured, and notif
field_parent_title: Parent page
label_issue_watchers: Watchers
setting_commit_logs_encoding: Commit messages encoding
button_quote: Quote

View File

@ -561,6 +561,7 @@ button_copy: Copier
button_annotate: Annoter
button_update: Mettre à jour
button_configure: Configurer
button_quote: Citer
status_active: actif
status_registered: enregistré

View File

@ -635,3 +635,4 @@ text_email_delivery_not_configured: "Email delivery is not configured, and notif
field_parent_title: Parent page
label_issue_watchers: Watchers
setting_commit_logs_encoding: Commit messages encoding
button_quote: Quote

View File

@ -636,3 +636,4 @@ text_email_delivery_not_configured: "Az E-mail küldés nincs konfigurálva, és
field_parent_title: Parent page
label_issue_watchers: Watchers
setting_commit_logs_encoding: Commit messages encoding
button_quote: Quote

View File

@ -635,3 +635,4 @@ text_email_delivery_not_configured: "La consegna via e-mail non è configurata e
field_parent_title: Parent page
label_issue_watchers: Watchers
setting_commit_logs_encoding: Commit messages encoding
button_quote: Quote

View File

@ -636,3 +636,4 @@ text_email_delivery_not_configured: "Email delivery is not configured, and notif
field_parent_title: Parent page
label_issue_watchers: Watchers
setting_commit_logs_encoding: Commit messages encoding
button_quote: Quote

View File

@ -635,3 +635,4 @@ text_email_delivery_not_configured: "Email delivery is not configured, and notif
field_parent_title: Parent page
label_issue_watchers: Watchers
setting_commit_logs_encoding: Commit messages encoding
button_quote: Quote

View File

@ -638,3 +638,4 @@ text_email_delivery_not_configured: "Email delivery is not configured, and notif
field_parent_title: Parent page
label_issue_watchers: Watchers
setting_commit_logs_encoding: Commit messages encoding
button_quote: Quote

View File

@ -636,3 +636,4 @@ text_email_delivery_not_configured: "Email delivery is not configured, and notif
field_parent_title: Parent page
label_issue_watchers: Watchers
setting_commit_logs_encoding: Commit messages encoding
button_quote: Quote

View File

@ -636,3 +636,4 @@ text_email_delivery_not_configured: "Email delivery is not configured, and notif
field_parent_title: Parent page
label_issue_watchers: Watchers
setting_commit_logs_encoding: Commit messages encoding
button_quote: Quote

View File

@ -635,3 +635,4 @@ text_email_delivery_not_configured: "Email delivery is not configured, and notif
field_parent_title: Parent page
label_issue_watchers: Watchers
setting_commit_logs_encoding: Commit messages encoding
button_quote: Quote

View File

@ -635,3 +635,4 @@ text_email_delivery_not_configured: "Email delivery is not configured, and notif
field_parent_title: Parent page
label_issue_watchers: Watchers
setting_commit_logs_encoding: Commit messages encoding
button_quote: Quote

View File

@ -635,3 +635,4 @@ text_email_delivery_not_configured: "Email delivery is not configured, and notif
field_parent_title: Parent page
label_issue_watchers: Watchers
setting_commit_logs_encoding: Commit messages encoding
button_quote: Quote

View File

@ -635,3 +635,4 @@ text_email_delivery_not_configured: "Email delivery is not configured, and notif
field_parent_title: Parent page
label_issue_watchers: Watchers
setting_commit_logs_encoding: Commit messages encoding
button_quote: Quote

View File

@ -639,3 +639,4 @@ text_email_delivery_not_configured: "Параметры работы с почт
field_parent_title: Parent page
label_issue_watchers: Watchers
setting_commit_logs_encoding: Commit messages encoding
button_quote: Quote

View File

@ -636,3 +636,4 @@ text_email_delivery_not_configured: "Email delivery is not configured, and notif
field_parent_title: Parent page
label_issue_watchers: Watchers
setting_commit_logs_encoding: Commit messages encoding
button_quote: Quote

View File

@ -636,3 +636,4 @@ text_email_delivery_not_configured: "Email delivery is not configured, and notif
field_parent_title: Parent page
label_issue_watchers: Watchers
setting_commit_logs_encoding: Commit messages encoding
button_quote: Quote

View File

@ -638,3 +638,4 @@ text_email_delivery_not_configured: "Email delivery is not configured, and notif
field_parent_title: Parent page
label_issue_watchers: Watchers
setting_commit_logs_encoding: Commit messages encoding
button_quote: Quote

View File

@ -637,3 +637,4 @@ text_email_delivery_not_configured: "Email delivery is not configured, and notif
field_parent_title: Parent page
label_issue_watchers: Watchers
setting_commit_logs_encoding: Commit messages encoding
button_quote: Quote

View File

@ -636,3 +636,4 @@ enumeration_activities: 活動 (時間追蹤)
field_parent_title: Parent page
label_issue_watchers: Watchers
setting_commit_logs_encoding: Commit messages encoding
button_quote: Quote

View File

@ -636,3 +636,4 @@ default_activity_development: 开发
enumeration_issue_priorities: 问题优先级
enumeration_doc_categories: 文档类别
enumeration_activities: 活动(时间跟踪)
button_quote: Quote

View File

@ -92,7 +92,7 @@ Redmine::AccessControl.map do |map|
map.project_module :boards do |map|
map.permission :manage_boards, {:boards => [:new, :edit, :destroy]}, :require => :member
map.permission :view_messages, {:boards => [:index, :show], :messages => [:show]}, :public => true
map.permission :add_messages, {:messages => [:new, :reply]}
map.permission :add_messages, {:messages => [:new, :reply, :quote]}
map.permission :edit_messages, {:messages => :edit}, :require => :member
map.permission :delete_messages, {:messages => :destroy}, :require => :member
end

View File

@ -599,6 +599,7 @@ vertical-align: middle;
.icon-checked { background-image: url(../images/true.png); }
.icon-details { background-image: url(../images/zoom_in.png); }
.icon-report { background-image: url(../images/report.png); }
.icon-comment { background-image: url(../images/comment.png); }
.icon22-projects { background-image: url(../images/22x22/projects.png); }
.icon22-users { background-image: url(../images/22x22/users.png); }

View File

@ -40,6 +40,15 @@ class MessagesControllerTest < Test::Unit::TestCase
assert_not_nil assigns(:topic)
end
def test_show_with_reply_permission
@request.session[:user_id] = 2
get :show, :board_id => 1, :id => 1
assert_response :success
assert_template 'show'
assert_tag :div, :attributes => { :id => 'reply' },
:descendant => { :tag => 'textarea', :attributes => { :id => 'message_content' } }
end
def test_show_message_not_found
get :show, :board_id => 1, :id => 99999
assert_response 404
@ -108,4 +117,11 @@ class MessagesControllerTest < Test::Unit::TestCase
assert_redirected_to 'boards/show'
assert_nil Message.find_by_id(1)
end
def test_quote
@request.session[:user_id] = 2
xhr :get, :quote, :board_id => 1, :id => 3
assert_response :success
assert_select_rjs :show, 'reply'
end
end