@@ -1,149 +1,151 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2011 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2011 Jean-Philippe Lang | |
3 | # |
|
3 | # | |
4 | # This program is free software; you can redistribute it and/or |
|
4 | # This program is free software; you can redistribute it and/or | |
5 | # modify it under the terms of the GNU General Public License |
|
5 | # modify it under the terms of the GNU General Public License | |
6 | # as published by the Free Software Foundation; either version 2 |
|
6 | # as published by the Free Software Foundation; either version 2 | |
7 | # of the License, or (at your option) any later version. |
|
7 | # of the License, or (at your option) any later version. | |
8 | # |
|
8 | # | |
9 | # This program is distributed in the hope that it will be useful, |
|
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. |
|
12 | # GNU General Public License for more details. | |
13 | # |
|
13 | # | |
14 | # You should have received a copy of the GNU General Public License |
|
14 | # You should have received a copy of the GNU General Public License | |
15 | # along with this program; if not, write to the Free Software |
|
15 | # along with this program; if not, write to the Free Software | |
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 |
|
17 | |||
18 | class MessagesController < ApplicationController |
|
18 | class MessagesController < ApplicationController | |
19 | menu_item :boards |
|
19 | menu_item :boards | |
20 | default_search_scope :messages |
|
20 | default_search_scope :messages | |
21 | before_filter :find_board, :only => [:new, :preview] |
|
21 | before_filter :find_board, :only => [:new, :preview] | |
22 | before_filter :find_message, :except => [:new, :preview] |
|
22 | before_filter :find_message, :except => [:new, :preview] | |
23 | before_filter :authorize, :except => [:preview, :edit, :destroy] |
|
23 | before_filter :authorize, :except => [:preview, :edit, :destroy] | |
24 |
|
24 | |||
25 | verify :method => :post, :only => [ :reply, :destroy ], :redirect_to => { :action => :show } |
|
25 | verify :method => :post, :only => [ :reply, :destroy ], :redirect_to => { :action => :show } | |
26 | verify :xhr => true, :only => :quote |
|
26 | verify :xhr => true, :only => :quote | |
27 |
|
27 | |||
28 | helper :watchers |
|
28 | helper :watchers | |
29 | helper :attachments |
|
29 | helper :attachments | |
30 | include AttachmentsHelper |
|
30 | include AttachmentsHelper | |
31 |
|
31 | |||
32 | REPLIES_PER_PAGE = 25 unless const_defined?(:REPLIES_PER_PAGE) |
|
32 | REPLIES_PER_PAGE = 25 unless const_defined?(:REPLIES_PER_PAGE) | |
33 |
|
33 | |||
34 | # Show a topic and its replies |
|
34 | # Show a topic and its replies | |
35 | def show |
|
35 | def show | |
36 | page = params[:page] |
|
36 | page = params[:page] | |
37 | # Find the page of the requested reply |
|
37 | # Find the page of the requested reply | |
38 | if params[:r] && page.nil? |
|
38 | if params[:r] && page.nil? | |
39 | offset = @topic.children.count(:conditions => ["#{Message.table_name}.id < ?", params[:r].to_i]) |
|
39 | offset = @topic.children.count(:conditions => ["#{Message.table_name}.id < ?", params[:r].to_i]) | |
40 | page = 1 + offset / REPLIES_PER_PAGE |
|
40 | page = 1 + offset / REPLIES_PER_PAGE | |
41 | end |
|
41 | end | |
42 |
|
42 | |||
43 | @reply_count = @topic.children.count |
|
43 | @reply_count = @topic.children.count | |
44 | @reply_pages = Paginator.new self, @reply_count, REPLIES_PER_PAGE, page |
|
44 | @reply_pages = Paginator.new self, @reply_count, REPLIES_PER_PAGE, page | |
45 | @replies = @topic.children.find(:all, :include => [:author, :attachments, {:board => :project}], |
|
45 | @replies = @topic.children.find(:all, :include => [:author, :attachments, {:board => :project}], | |
46 | :order => "#{Message.table_name}.created_on ASC", |
|
46 | :order => "#{Message.table_name}.created_on ASC", | |
47 | :limit => @reply_pages.items_per_page, |
|
47 | :limit => @reply_pages.items_per_page, | |
48 | :offset => @reply_pages.current.offset) |
|
48 | :offset => @reply_pages.current.offset) | |
49 |
|
49 | |||
50 | @reply = Message.new(:subject => "RE: #{@message.subject}") |
|
50 | @reply = Message.new(:subject => "RE: #{@message.subject}") | |
51 | render :action => "show", :layout => false if request.xhr? |
|
51 | render :action => "show", :layout => false if request.xhr? | |
52 | end |
|
52 | end | |
53 |
|
53 | |||
54 | # Create a new topic |
|
54 | # Create a new topic | |
55 | def new |
|
55 | def new | |
56 | @message = Message.new(params[:message]) |
|
56 | @message = Message.new(params[:message]) | |
57 | @message.author = User.current |
|
57 | @message.author = User.current | |
58 | @message.board = @board |
|
58 | @message.board = @board | |
59 | if params[:message] && User.current.allowed_to?(:edit_messages, @project) |
|
59 | if params[:message] && User.current.allowed_to?(:edit_messages, @project) | |
60 | @message.locked = params[:message]['locked'] |
|
60 | @message.locked = params[:message]['locked'] | |
61 | @message.sticky = params[:message]['sticky'] |
|
61 | @message.sticky = params[:message]['sticky'] | |
62 | end |
|
62 | end | |
63 |
if request.post? |
|
63 | if request.post? | |
|
64 | @message.save_attachments(params[:attachments]) | |||
|
65 | if @message.save | |||
64 | call_hook(:controller_messages_new_after_save, { :params => params, :message => @message}) |
|
66 | call_hook(:controller_messages_new_after_save, { :params => params, :message => @message}) | |
65 | attachments = Attachment.attach_files(@message, params[:attachments]) |
|
|||
66 | render_attachment_warning_if_needed(@message) |
|
67 | render_attachment_warning_if_needed(@message) | |
67 | redirect_to :action => 'show', :id => @message |
|
68 | redirect_to :action => 'show', :id => @message | |
68 | end |
|
69 | end | |
69 | end |
|
70 | end | |
|
71 | end | |||
70 |
|
72 | |||
71 | # Reply to a topic |
|
73 | # Reply to a topic | |
72 | def reply |
|
74 | def reply | |
73 | @reply = Message.new(params[:reply]) |
|
75 | @reply = Message.new(params[:reply]) | |
74 | @reply.author = User.current |
|
76 | @reply.author = User.current | |
75 | @reply.board = @board |
|
77 | @reply.board = @board | |
76 | @topic.children << @reply |
|
78 | @topic.children << @reply | |
77 | if !@reply.new_record? |
|
79 | if !@reply.new_record? | |
78 | call_hook(:controller_messages_reply_after_save, { :params => params, :message => @reply}) |
|
80 | call_hook(:controller_messages_reply_after_save, { :params => params, :message => @reply}) | |
79 | attachments = Attachment.attach_files(@reply, params[:attachments]) |
|
81 | attachments = Attachment.attach_files(@reply, params[:attachments]) | |
80 | render_attachment_warning_if_needed(@reply) |
|
82 | render_attachment_warning_if_needed(@reply) | |
81 | end |
|
83 | end | |
82 | redirect_to :action => 'show', :id => @topic, :r => @reply |
|
84 | redirect_to :action => 'show', :id => @topic, :r => @reply | |
83 | end |
|
85 | end | |
84 |
|
86 | |||
85 | # Edit a message |
|
87 | # Edit a message | |
86 | def edit |
|
88 | def edit | |
87 | (render_403; return false) unless @message.editable_by?(User.current) |
|
89 | (render_403; return false) unless @message.editable_by?(User.current) | |
88 | if params[:message] |
|
90 | if params[:message] | |
89 | @message.locked = params[:message]['locked'] |
|
91 | @message.locked = params[:message]['locked'] | |
90 | @message.sticky = params[:message]['sticky'] |
|
92 | @message.sticky = params[:message]['sticky'] | |
91 | end |
|
93 | end | |
92 | if request.post? && @message.update_attributes(params[:message]) |
|
94 | if request.post? && @message.update_attributes(params[:message]) | |
93 | attachments = Attachment.attach_files(@message, params[:attachments]) |
|
95 | attachments = Attachment.attach_files(@message, params[:attachments]) | |
94 | render_attachment_warning_if_needed(@message) |
|
96 | render_attachment_warning_if_needed(@message) | |
95 | flash[:notice] = l(:notice_successful_update) |
|
97 | flash[:notice] = l(:notice_successful_update) | |
96 | @message.reload |
|
98 | @message.reload | |
97 | redirect_to :action => 'show', :board_id => @message.board, :id => @message.root, :r => (@message.parent_id && @message.id) |
|
99 | redirect_to :action => 'show', :board_id => @message.board, :id => @message.root, :r => (@message.parent_id && @message.id) | |
98 | end |
|
100 | end | |
99 | end |
|
101 | end | |
100 |
|
102 | |||
101 | # Delete a messages |
|
103 | # Delete a messages | |
102 | def destroy |
|
104 | def destroy | |
103 | (render_403; return false) unless @message.destroyable_by?(User.current) |
|
105 | (render_403; return false) unless @message.destroyable_by?(User.current) | |
104 | @message.destroy |
|
106 | @message.destroy | |
105 | redirect_to @message.parent.nil? ? |
|
107 | redirect_to @message.parent.nil? ? | |
106 | { :controller => 'boards', :action => 'show', :project_id => @project, :id => @board } : |
|
108 | { :controller => 'boards', :action => 'show', :project_id => @project, :id => @board } : | |
107 | { :action => 'show', :id => @message.parent, :r => @message } |
|
109 | { :action => 'show', :id => @message.parent, :r => @message } | |
108 | end |
|
110 | end | |
109 |
|
111 | |||
110 | def quote |
|
112 | def quote | |
111 | user = @message.author |
|
113 | user = @message.author | |
112 | text = @message.content |
|
114 | text = @message.content | |
113 | subject = @message.subject.gsub('"', '\"') |
|
115 | subject = @message.subject.gsub('"', '\"') | |
114 | subject = "RE: #{subject}" unless subject.starts_with?('RE:') |
|
116 | subject = "RE: #{subject}" unless subject.starts_with?('RE:') | |
115 | content = "#{ll(Setting.default_language, :text_user_wrote, user)}\\n> " |
|
117 | content = "#{ll(Setting.default_language, :text_user_wrote, user)}\\n> " | |
116 | content << text.to_s.strip.gsub(%r{<pre>((.|\s)*?)</pre>}m, '[...]').gsub('"', '\"').gsub(/(\r?\n|\r\n?)/, "\\n> ") + "\\n\\n" |
|
118 | content << text.to_s.strip.gsub(%r{<pre>((.|\s)*?)</pre>}m, '[...]').gsub('"', '\"').gsub(/(\r?\n|\r\n?)/, "\\n> ") + "\\n\\n" | |
117 | render(:update) { |page| |
|
119 | render(:update) { |page| | |
118 | page << "$('message_subject').value = \"#{subject}\";" |
|
120 | page << "$('message_subject').value = \"#{subject}\";" | |
119 | page.<< "$('message_content').value = \"#{content}\";" |
|
121 | page.<< "$('message_content').value = \"#{content}\";" | |
120 | page.show 'reply' |
|
122 | page.show 'reply' | |
121 | page << "Form.Element.focus('message_content');" |
|
123 | page << "Form.Element.focus('message_content');" | |
122 | page << "Element.scrollTo('reply');" |
|
124 | page << "Element.scrollTo('reply');" | |
123 | page << "$('message_content').scrollTop = $('message_content').scrollHeight - $('message_content').clientHeight;" |
|
125 | page << "$('message_content').scrollTop = $('message_content').scrollHeight - $('message_content').clientHeight;" | |
124 | } |
|
126 | } | |
125 | end |
|
127 | end | |
126 |
|
128 | |||
127 | def preview |
|
129 | def preview | |
128 | message = @board.messages.find_by_id(params[:id]) |
|
130 | message = @board.messages.find_by_id(params[:id]) | |
129 | @attachements = message.attachments if message |
|
131 | @attachements = message.attachments if message | |
130 | @text = (params[:message] || params[:reply])[:content] |
|
132 | @text = (params[:message] || params[:reply])[:content] | |
131 | render :partial => 'common/preview' |
|
133 | render :partial => 'common/preview' | |
132 | end |
|
134 | end | |
133 |
|
135 | |||
134 | private |
|
136 | private | |
135 | def find_message |
|
137 | def find_message | |
136 | find_board |
|
138 | find_board | |
137 | @message = @board.messages.find(params[:id], :include => :parent) |
|
139 | @message = @board.messages.find(params[:id], :include => :parent) | |
138 | @topic = @message.root |
|
140 | @topic = @message.root | |
139 | rescue ActiveRecord::RecordNotFound |
|
141 | rescue ActiveRecord::RecordNotFound | |
140 | render_404 |
|
142 | render_404 | |
141 | end |
|
143 | end | |
142 |
|
144 | |||
143 | def find_board |
|
145 | def find_board | |
144 | @board = Board.find(params[:board_id], :include => :project) |
|
146 | @board = Board.find(params[:board_id], :include => :project) | |
145 | @project = @board.project |
|
147 | @project = @board.project | |
146 | rescue ActiveRecord::RecordNotFound |
|
148 | rescue ActiveRecord::RecordNotFound | |
147 | render_404 |
|
149 | render_404 | |
148 | end |
|
150 | end | |
149 | end |
|
151 | end |
@@ -1,28 +1,28 | |||||
1 | <%= error_messages_for 'message' %> |
|
1 | <%= error_messages_for 'message' %> | |
2 | <% replying ||= false %> |
|
2 | <% replying ||= false %> | |
3 |
|
3 | |||
4 | <div class="box"> |
|
4 | <div class="box"> | |
5 | <!--[form:message]--> |
|
5 | <!--[form:message]--> | |
6 | <p><label for="message_subject"><%= l(:field_subject) %></label><br /> |
|
6 | <p><label for="message_subject"><%= l(:field_subject) %></label><br /> | |
7 | <%= f.text_field :subject, :size => 120, :id => "message_subject" %> |
|
7 | <%= f.text_field :subject, :size => 120, :id => "message_subject" %> | |
8 |
|
8 | |||
9 | <% if !replying && User.current.allowed_to?(:edit_messages, @project) %> |
|
9 | <% if !replying && User.current.allowed_to?(:edit_messages, @project) %> | |
10 | <label><%= f.check_box :sticky %><%= l(:label_board_sticky) %></label> |
|
10 | <label><%= f.check_box :sticky %><%= l(:label_board_sticky) %></label> | |
11 | <label><%= f.check_box :locked %><%= l(:label_board_locked) %></label> |
|
11 | <label><%= f.check_box :locked %><%= l(:label_board_locked) %></label> | |
12 | <% end %> |
|
12 | <% end %> | |
13 | </p> |
|
13 | </p> | |
14 |
|
14 | |||
15 | <% if !replying && !@message.new_record? && User.current.allowed_to?(:edit_messages, @project) %> |
|
15 | <% if !replying && !@message.new_record? && User.current.allowed_to?(:edit_messages, @project) %> | |
16 | <p><label><%= l(:label_board) %></label><br /> |
|
16 | <p><label><%= l(:label_board) %></label><br /> | |
17 | <%= f.select :board_id, @project.boards.collect {|b| [b.name, b.id]} %></p> |
|
17 | <%= f.select :board_id, @project.boards.collect {|b| [b.name, b.id]} %></p> | |
18 | <% end %> |
|
18 | <% end %> | |
19 |
|
19 | |||
20 | <p> |
|
20 | <p> | |
21 | <%= label_tag "message_content", l(:description_message_content), :class => "hidden-for-sighted" %> |
|
21 | <%= label_tag "message_content", l(:description_message_content), :class => "hidden-for-sighted" %> | |
22 | <%= f.text_area :content, :cols => 80, :rows => 15, :class => 'wiki-edit', :id => 'message_content' %></p> |
|
22 | <%= f.text_area :content, :cols => 80, :rows => 15, :class => 'wiki-edit', :id => 'message_content' %></p> | |
23 | <%= wikitoolbar_for 'message_content' %> |
|
23 | <%= wikitoolbar_for 'message_content' %> | |
24 | <!--[eoform:message]--> |
|
24 | <!--[eoform:message]--> | |
25 |
|
25 | |||
26 | <p><%= l(:label_attachment_plural) %><br /> |
|
26 | <p><%= l(:label_attachment_plural) %><br /> | |
27 | <%= render :partial => 'attachments/form' %></p> |
|
27 | <%= render :partial => 'attachments/form', :locals => {:container => @message} %></p> | |
28 | </div> |
|
28 | </div> |
General Comments 0
You need to be logged in to leave comments.
Login now