comparison app/controllers/.svn/text-base/journals_controller.rb.svn-base @ 14:1d32c0a0efbf

* Update to SVN trunk (revisions 3892-4040)
author Chris Cannam
date Wed, 25 Aug 2010 16:30:24 +0100
parents 513646585e45
children af80e5618e9b
comparison
equal deleted inserted replaced
4:9cc62779c13a 14:1d32c0a0efbf
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 19 before_filter :find_journal, :only => [:edit]
20 before_filter :find_issue, :only => [:new]
21 before_filter :find_optional_project, :only => [:index]
22 accept_key_auth :index
23
24 helper :issues
25 helper :queries
26 include QueriesHelper
27 helper :sort
28 include SortHelper
29
30 def index
31 retrieve_query
32 sort_init 'id', 'desc'
33 sort_update(@query.sortable_columns)
34
35 if @query.valid?
36 @journals = @query.journals(:order => "#{Journal.table_name}.created_on DESC",
37 :limit => 25)
38 end
39 @title = (@project ? @project.name : Setting.app_title) + ": " + (@query.new_record? ? l(:label_changes_details) : @query.name)
40 render :layout => false, :content_type => 'application/atom+xml'
41 rescue ActiveRecord::RecordNotFound
42 render_404
43 end
44
45 def new
46 journal = Journal.find(params[:journal_id]) if params[:journal_id]
47 if journal
48 user = journal.user
49 text = journal.notes
50 else
51 user = @issue.author
52 text = @issue.description
53 end
54 # Replaces pre blocks with [...]
55 text = text.to_s.strip.gsub(%r{<pre>((.|\s)*?)</pre>}m, '[...]')
56 content = "#{ll(Setting.default_language, :text_user_wrote, user)}\n> "
57 content << text.gsub(/(\r?\n|\r\n?)/, "\n> ") + "\n\n"
58
59 render(:update) { |page|
60 page.<< "$('notes').value = \"#{escape_javascript content}\";"
61 page.show 'update'
62 page << "Form.Element.focus('notes');"
63 page << "Element.scrollTo('update');"
64 page << "$('notes').scrollTop = $('notes').scrollHeight - $('notes').clientHeight;"
65 }
66 end
20 67
21 def edit 68 def edit
22 if request.post? 69 if request.post?
23 @journal.update_attributes(:notes => params[:notes]) if params[:notes] 70 @journal.update_attributes(:notes => params[:notes]) if params[:notes]
24 @journal.destroy if @journal.details.empty? && @journal.notes.blank? 71 @journal.destroy if @journal.details.empty? && @journal.notes.blank?
36 (render_403; return false) unless @journal.editable_by?(User.current) 83 (render_403; return false) unless @journal.editable_by?(User.current)
37 @project = @journal.journalized.project 84 @project = @journal.journalized.project
38 rescue ActiveRecord::RecordNotFound 85 rescue ActiveRecord::RecordNotFound
39 render_404 86 render_404
40 end 87 end
88
89 # TODO: duplicated in IssuesController
90 def find_issue
91 @issue = Issue.find(params[:id], :include => [:project, :tracker, :status, :author, :priority, :category])
92 @project = @issue.project
93 rescue ActiveRecord::RecordNotFound
94 render_404
95 end
41 end 96 end