Commit bfd0fb06 authored by Jean-Philippe Lang's avatar Jean-Philippe Lang

Adds posts quoting functionality (#1825).

git-svn-id: http://redmine.rubyforge.org/svn/trunk@1772 e93f8b46-1217-0410-a6f0-8f06a7374b81
parent 8f3a04ce
......@@ -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
......
......@@ -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)
......
......@@ -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>
......
......@@ -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
......@@ -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
......@@ -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
......@@ -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
......@@ -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
......
......@@ -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
......@@ -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
......@@ -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é
......
......@@ -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
......@@ -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
......@@ -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
......@@ -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
......@@ -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
......@@ -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
......@@ -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
......@@ -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
......@@ -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
......@@ -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
......@@ -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
......@@ -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
......@@ -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
......@@ -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
......@@ -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
......@@ -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
......@@ -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
......@@ -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
......@@ -636,3 +636,4 @@ default_activity_development: 开发
enumeration_issue_priorities: 问题优先级
enumeration_doc_categories: 文档类别
enumeration_activities: 活动(时间跟踪)
button_quote: Quote
......@@ -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
......
......@@ -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); }
......
......@@ -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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment