@@ -1,97 +1,105 | |||
|
1 | 1 | # redMine - project management software |
|
2 | 2 | # Copyright (C) 2006-2008 Jean-Philippe Lang |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
|
6 | 6 | # as published by the Free Software Foundation; either version 2 |
|
7 | 7 | # of the License, or (at your option) any later version. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software |
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | 17 | |
|
18 | 18 | class JournalsController < ApplicationController |
|
19 | 19 | before_filter :find_journal, :only => [:edit] |
|
20 | 20 | before_filter :find_issue, :only => [:new] |
|
21 | 21 | before_filter :find_optional_project, :only => [:index] |
|
22 | 22 | before_filter :authorize, :only => [:new, :edit] |
|
23 | 23 | accept_key_auth :index |
|
24 | 24 | |
|
25 | 25 | helper :issues |
|
26 | 26 | helper :queries |
|
27 | 27 | include QueriesHelper |
|
28 | 28 | helper :sort |
|
29 | 29 | include SortHelper |
|
30 | 30 | |
|
31 | 31 | def index |
|
32 | 32 | retrieve_query |
|
33 | 33 | sort_init 'id', 'desc' |
|
34 | 34 | sort_update(@query.sortable_columns) |
|
35 | 35 | |
|
36 | 36 | if @query.valid? |
|
37 | 37 | @journals = @query.journals(:order => "#{Journal.table_name}.created_on DESC", |
|
38 | 38 | :limit => 25) |
|
39 | 39 | end |
|
40 | 40 | @title = (@project ? @project.name : Setting.app_title) + ": " + (@query.new_record? ? l(:label_changes_details) : @query.name) |
|
41 | 41 | render :layout => false, :content_type => 'application/atom+xml' |
|
42 | 42 | rescue ActiveRecord::RecordNotFound |
|
43 | 43 | render_404 |
|
44 | 44 | end |
|
45 | 45 | |
|
46 | 46 | def new |
|
47 | 47 | journal = Journal.find(params[:journal_id]) if params[:journal_id] |
|
48 | 48 | if journal |
|
49 | 49 | user = journal.user |
|
50 | 50 | text = journal.notes |
|
51 | 51 | else |
|
52 | 52 | user = @issue.author |
|
53 | 53 | text = @issue.description |
|
54 | 54 | end |
|
55 | 55 | # Replaces pre blocks with [...] |
|
56 | 56 | text = text.to_s.strip.gsub(%r{<pre>((.|\s)*?)</pre>}m, '[...]') |
|
57 | 57 | content = "#{ll(Setting.default_language, :text_user_wrote, user)}\n> " |
|
58 | 58 | content << text.gsub(/(\r?\n|\r\n?)/, "\n> ") + "\n\n" |
|
59 | 59 | |
|
60 | 60 | render(:update) { |page| |
|
61 | 61 | page.<< "$('notes').value = \"#{escape_javascript content}\";" |
|
62 | 62 | page.show 'update' |
|
63 | 63 | page << "Form.Element.focus('notes');" |
|
64 | 64 | page << "Element.scrollTo('update');" |
|
65 | 65 | page << "$('notes').scrollTop = $('notes').scrollHeight - $('notes').clientHeight;" |
|
66 | 66 | } |
|
67 | 67 | end |
|
68 | 68 | |
|
69 | 69 | def edit |
|
70 | 70 | if request.post? |
|
71 | 71 | @journal.update_attributes(:notes => params[:notes]) if params[:notes] |
|
72 | 72 | @journal.destroy if @journal.details.empty? && @journal.notes.blank? |
|
73 | 73 | call_hook(:controller_journals_edit_post, { :journal => @journal, :params => params}) |
|
74 | 74 | respond_to do |format| |
|
75 | 75 | format.html { redirect_to :controller => 'issues', :action => 'show', :id => @journal.journalized_id } |
|
76 | 76 | format.js { render :action => 'update' } |
|
77 | 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 | 86 | end |
|
79 | 87 | end |
|
80 | 88 | |
|
81 | 89 | private |
|
82 | 90 | def find_journal |
|
83 | 91 | @journal = Journal.find(params[:id]) |
|
84 | 92 | (render_403; return false) unless @journal.editable_by?(User.current) |
|
85 | 93 | @project = @journal.journalized.project |
|
86 | 94 | rescue ActiveRecord::RecordNotFound |
|
87 | 95 | render_404 |
|
88 | 96 | end |
|
89 | 97 | |
|
90 | 98 | # TODO: duplicated in IssuesController |
|
91 | 99 | def find_issue |
|
92 | 100 | @issue = Issue.find(params[:id], :include => [:project, :tracker, :status, :author, :priority, :category]) |
|
93 | 101 | @project = @issue.project |
|
94 | 102 | rescue ActiveRecord::RecordNotFound |
|
95 | 103 | render_404 |
|
96 | 104 | end |
|
97 | 105 | end |
General Comments 0
You need to be logged in to leave comments.
Login now