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