@@ -1,119 +1,119 | |||||
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 JournalsController < ApplicationController |
|
18 | class JournalsController < ApplicationController | |
19 | before_filter :find_journal, :only => [:edit, :diff] |
|
19 | before_filter :find_journal, :only => [:edit, :diff] | |
20 | before_filter :find_issue, :only => [:new] |
|
20 | before_filter :find_issue, :only => [:new] | |
21 | before_filter :find_optional_project, :only => [:index] |
|
21 | before_filter :find_optional_project, :only => [:index] | |
22 | before_filter :authorize, :only => [:new, :edit, :diff] |
|
22 | before_filter :authorize, :only => [:new, :edit, :diff] | |
23 | accept_rss_auth :index |
|
23 | accept_rss_auth :index | |
24 | menu_item :issues |
|
24 | menu_item :issues | |
25 |
|
25 | |||
26 | helper :issues |
|
26 | helper :issues | |
27 | helper :custom_fields |
|
27 | helper :custom_fields | |
28 | helper :queries |
|
28 | helper :queries | |
29 | include QueriesHelper |
|
29 | include QueriesHelper | |
30 | helper :sort |
|
30 | helper :sort | |
31 | include SortHelper |
|
31 | include SortHelper | |
32 |
|
32 | |||
33 | def index |
|
33 | def index | |
34 | retrieve_query |
|
34 | retrieve_query | |
35 | sort_init 'id', 'desc' |
|
35 | sort_init 'id', 'desc' | |
36 | sort_update(@query.sortable_columns) |
|
36 | sort_update(@query.sortable_columns) | |
37 |
|
37 | |||
38 | if @query.valid? |
|
38 | if @query.valid? | |
39 |
@journals = @query.journals(:order => "#{Journal.table_name}.created_on DESC", |
|
39 | @journals = @query.journals(:order => "#{Journal.table_name}.created_on DESC", | |
40 | :limit => 25) |
|
40 | :limit => 25) | |
41 | end |
|
41 | end | |
42 | @title = (@project ? @project.name : Setting.app_title) + ": " + (@query.new_record? ? l(:label_changes_details) : @query.name) |
|
42 | @title = (@project ? @project.name : Setting.app_title) + ": " + (@query.new_record? ? l(:label_changes_details) : @query.name) | |
43 | render :layout => false, :content_type => 'application/atom+xml' |
|
43 | render :layout => false, :content_type => 'application/atom+xml' | |
44 | rescue ActiveRecord::RecordNotFound |
|
44 | rescue ActiveRecord::RecordNotFound | |
45 | render_404 |
|
45 | render_404 | |
46 | end |
|
46 | end | |
47 |
|
47 | |||
48 | def diff |
|
48 | def diff | |
49 | @issue = @journal.issue |
|
49 | @issue = @journal.issue | |
50 | if params[:detail_id].present? |
|
50 | if params[:detail_id].present? | |
51 | @detail = @journal.details.find_by_id(params[:detail_id]) |
|
51 | @detail = @journal.details.find_by_id(params[:detail_id]) | |
52 | else |
|
52 | else | |
53 | @detail = @journal.details.detect {|d| d.prop_key == 'description'} |
|
53 | @detail = @journal.details.detect {|d| d.prop_key == 'description'} | |
54 | end |
|
54 | end | |
55 | (render_404; return false) unless @issue && @detail |
|
55 | (render_404; return false) unless @issue && @detail | |
56 | @diff = Redmine::Helpers::Diff.new(@detail.value, @detail.old_value) |
|
56 | @diff = Redmine::Helpers::Diff.new(@detail.value, @detail.old_value) | |
57 | end |
|
57 | end | |
58 |
|
58 | |||
59 | def new |
|
59 | def new | |
60 | journal = Journal.find(params[:journal_id]) if params[:journal_id] |
|
60 | journal = Journal.find(params[:journal_id]) if params[:journal_id] | |
61 | if journal |
|
61 | if journal | |
62 | user = journal.user |
|
62 | user = journal.user | |
63 | text = journal.notes |
|
63 | text = journal.notes | |
64 | else |
|
64 | else | |
65 | user = @issue.author |
|
65 | user = @issue.author | |
66 | text = @issue.description |
|
66 | text = @issue.description | |
67 | end |
|
67 | end | |
68 | # Replaces pre blocks with [...] |
|
68 | # Replaces pre blocks with [...] | |
69 | text = text.to_s.strip.gsub(%r{<pre>((.|\s)*?)</pre>}m, '[...]') |
|
69 | text = text.to_s.strip.gsub(%r{<pre>((.|\s)*?)</pre>}m, '[...]') | |
70 | content = "#{ll(Setting.default_language, :text_user_wrote, user)}\n> " |
|
70 | content = "#{ll(Setting.default_language, :text_user_wrote, user)}\n> " | |
71 | content << text.gsub(/(\r?\n|\r\n?)/, "\n> ") + "\n\n" |
|
71 | content << text.gsub(/(\r?\n|\r\n?)/, "\n> ") + "\n\n" | |
72 |
|
72 | |||
73 | render(:update) { |page| |
|
73 | render(:update) { |page| | |
74 | page.<< "$('notes').value = \"#{escape_javascript content}\";" |
|
74 | page.<< "$('notes').value = \"#{escape_javascript content}\";" | |
75 | page.show 'update' |
|
75 | page.show 'update' | |
76 | page << "Form.Element.focus('notes');" |
|
76 | page << "Form.Element.focus('notes');" | |
77 | page << "Element.scrollTo('update');" |
|
77 | page << "Element.scrollTo('update');" | |
78 | page << "$('notes').scrollTop = $('notes').scrollHeight - $('notes').clientHeight;" |
|
78 | page << "$('notes').scrollTop = $('notes').scrollHeight - $('notes').clientHeight;" | |
79 | } |
|
79 | } | |
80 | end |
|
80 | end | |
81 |
|
81 | |||
82 | def edit |
|
82 | def edit | |
83 | (render_403; return false) unless @journal.editable_by?(User.current) |
|
83 | (render_403; return false) unless @journal.editable_by?(User.current) | |
84 | if request.post? |
|
84 | if request.post? | |
85 | @journal.update_attributes(:notes => params[:notes]) if params[:notes] |
|
85 | @journal.update_attributes(:notes => params[:notes]) if params[:notes] | |
86 | @journal.destroy if @journal.details.empty? && @journal.notes.blank? |
|
86 | @journal.destroy if @journal.details.empty? && @journal.notes.blank? | |
87 | call_hook(:controller_journals_edit_post, { :journal => @journal, :params => params}) |
|
87 | call_hook(:controller_journals_edit_post, { :journal => @journal, :params => params}) | |
88 | respond_to do |format| |
|
88 | respond_to do |format| | |
89 | format.html { redirect_to :controller => 'issues', :action => 'show', :id => @journal.journalized_id } |
|
89 | format.html { redirect_to :controller => 'issues', :action => 'show', :id => @journal.journalized_id } | |
90 | format.js { render :action => 'update' } |
|
90 | format.js { render :action => 'update' } | |
91 | end |
|
91 | end | |
92 | else |
|
92 | else | |
93 | respond_to do |format| |
|
93 | respond_to do |format| | |
94 | format.html { |
|
94 | format.html { | |
95 | # TODO: implement non-JS journal update |
|
95 | # TODO: implement non-JS journal update | |
96 |
render :nothing => true |
|
96 | render :nothing => true | |
97 | } |
|
97 | } | |
98 | format.js |
|
98 | format.js | |
99 | end |
|
99 | end | |
100 | end |
|
100 | end | |
101 | end |
|
101 | end | |
102 |
|
102 | |||
103 | private |
|
103 | private | |
104 |
|
104 | |||
105 | def find_journal |
|
105 | def find_journal | |
106 | @journal = Journal.find(params[:id]) |
|
106 | @journal = Journal.find(params[:id]) | |
107 | @project = @journal.journalized.project |
|
107 | @project = @journal.journalized.project | |
108 | rescue ActiveRecord::RecordNotFound |
|
108 | rescue ActiveRecord::RecordNotFound | |
109 | render_404 |
|
109 | render_404 | |
110 | end |
|
110 | end | |
111 |
|
111 | |||
112 | # TODO: duplicated in IssuesController |
|
112 | # TODO: duplicated in IssuesController | |
113 | def find_issue |
|
113 | def find_issue | |
114 | @issue = Issue.find(params[:id], :include => [:project, :tracker, :status, :author, :priority, :category]) |
|
114 | @issue = Issue.find(params[:id], :include => [:project, :tracker, :status, :author, :priority, :category]) | |
115 | @project = @issue.project |
|
115 | @project = @issue.project | |
116 | rescue ActiveRecord::RecordNotFound |
|
116 | rescue ActiveRecord::RecordNotFound | |
117 | render_404 |
|
117 | render_404 | |
118 | end |
|
118 | end | |
119 | end |
|
119 | end |
General Comments 0
You need to be logged in to leave comments.
Login now