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