comparison app/controllers/journals_controller.rb @ 511:107d36338b70 live

Merge from branch "cannam"
author Chris Cannam
date Thu, 14 Jul 2011 10:43:07 +0100
parents 0c939c159af4
children cbb26bc654de
comparison
equal deleted inserted replaced
451:a9f6345cb43d 511:107d36338b70
1 # redMine - project management software 1 # Redmine - project management software
2 # Copyright (C) 2006-2008 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.
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, :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 accept_key_auth :index 22 before_filter :authorize, :only => [:new, :edit, :diff]
23 23 accept_rss_auth :index
24 menu_item :issues
25
24 helper :issues 26 helper :issues
27 helper :custom_fields
25 helper :queries 28 helper :queries
26 include QueriesHelper 29 include QueriesHelper
27 helper :sort 30 helper :sort
28 include SortHelper 31 include SortHelper
29 32
38 end 41 end
39 @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)
40 render :layout => false, :content_type => 'application/atom+xml' 43 render :layout => false, :content_type => 'application/atom+xml'
41 rescue ActiveRecord::RecordNotFound 44 rescue ActiveRecord::RecordNotFound
42 render_404 45 render_404
46 end
47
48 def diff
49 @issue = @journal.issue
50 if params[:detail_id].present?
51 @detail = @journal.details.find_by_id(params[:detail_id])
52 else
53 @detail = @journal.details.detect {|d| d.prop_key == 'description'}
54 end
55 (render_404; return false) unless @issue && @detail
56 @diff = Redmine::Helpers::Diff.new(@detail.value, @detail.old_value)
43 end 57 end
44 58
45 def new 59 def new
46 journal = Journal.find(params[:journal_id]) if params[:journal_id] 60 journal = Journal.find(params[:journal_id]) if params[:journal_id]
47 if journal 61 if journal
64 page << "$('notes').scrollTop = $('notes').scrollHeight - $('notes').clientHeight;" 78 page << "$('notes').scrollTop = $('notes').scrollHeight - $('notes').clientHeight;"
65 } 79 }
66 end 80 end
67 81
68 def edit 82 def edit
83 (render_403; return false) unless @journal.editable_by?(User.current)
69 if request.post? 84 if request.post?
70 @journal.update_attributes(:notes => params[:notes]) if params[:notes] 85 @journal.update_attributes(:notes => params[:notes]) if params[:notes]
71 @journal.destroy if @journal.details.empty? && @journal.notes.blank? 86 @journal.destroy if @journal.details.empty? && @journal.notes.blank?
72 call_hook(:controller_journals_edit_post, { :journal => @journal, :params => params}) 87 call_hook(:controller_journals_edit_post, { :journal => @journal, :params => params})
73 respond_to do |format| 88 respond_to do |format|
74 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 }
75 format.js { render :action => 'update' } 90 format.js { render :action => 'update' }
76 end 91 end
92 else
93 respond_to do |format|
94 format.html {
95 # TODO: implement non-JS journal update
96 render :nothing => true
97 }
98 format.js
99 end
77 end 100 end
78 end 101 end
79 102
80 private 103 private
104
81 def find_journal 105 def find_journal
82 @journal = Journal.find(params[:id]) 106 @journal = Journal.find(params[:id])
83 (render_403; return false) unless @journal.editable_by?(User.current)
84 @project = @journal.journalized.project 107 @project = @journal.journalized.project
85 rescue ActiveRecord::RecordNotFound 108 rescue ActiveRecord::RecordNotFound
86 render_404 109 render_404
87 end 110 end
88 111