To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Tag: | Revision:

root / app / controllers / journals_controller.rb @ 422:19549b0c417a

History | View | Annotate | Download (3.36 KB)

1
# redMine - project management software
2
# Copyright (C) 2006-2008  Jean-Philippe Lang
3
#
4
# This program is free software; you can redistribute it and/or
5
# modify it under the terms of the GNU General Public License
6
# as published by the Free Software Foundation; either version 2
7
# of the License, or (at your option) any later version.
8
# 
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
# GNU General Public License for more details.
13
# 
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
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17

    
18
class JournalsController < ApplicationController
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
67
  
68
  def edit
69
    if request.post?
70
      @journal.update_attributes(:notes => params[:notes]) if params[:notes]
71
      @journal.destroy if @journal.details.empty? && @journal.notes.blank?
72
      call_hook(:controller_journals_edit_post, { :journal => @journal, :params => params})
73
      respond_to do |format|
74
        format.html { redirect_to :controller => 'issues', :action => 'show', :id => @journal.journalized_id }
75
        format.js { render :action => 'update' }
76
      end
77
    end
78
  end
79
  
80
private
81
  def find_journal
82
    @journal = Journal.find(params[:id])
83
    (render_403; return false) unless @journal.editable_by?(User.current)
84
    @project = @journal.journalized.project
85
  rescue ActiveRecord::RecordNotFound
86
    render_404
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
96
end