annotate app/controllers/journals_controller.rb @ 904:0a8317a50fa0 redmine-1.1

Close obsolete branch redmine-1.1
author Chris Cannam
date Fri, 14 Jan 2011 12:53:21 +0000
parents af80e5618e9b
children 051f544170fe
rev   line source
Chris@0 1 # redMine - project management software
Chris@0 2 # Copyright (C) 2006-2008 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@14 19 before_filter :find_journal, :only => [:edit]
Chris@14 20 before_filter :find_issue, :only => [:new]
Chris@14 21 before_filter :find_optional_project, :only => [:index]
Chris@117 22 before_filter :authorize, :only => [:new, :edit]
Chris@14 23 accept_key_auth :index
Chris@14 24
Chris@14 25 helper :issues
Chris@14 26 helper :queries
Chris@14 27 include QueriesHelper
Chris@14 28 helper :sort
Chris@14 29 include SortHelper
Chris@14 30
Chris@14 31 def index
Chris@14 32 retrieve_query
Chris@14 33 sort_init 'id', 'desc'
Chris@14 34 sort_update(@query.sortable_columns)
Chris@14 35
Chris@14 36 if @query.valid?
Chris@14 37 @journals = @query.journals(:order => "#{Journal.table_name}.created_on DESC",
Chris@14 38 :limit => 25)
Chris@14 39 end
Chris@14 40 @title = (@project ? @project.name : Setting.app_title) + ": " + (@query.new_record? ? l(:label_changes_details) : @query.name)
Chris@14 41 render :layout => false, :content_type => 'application/atom+xml'
Chris@14 42 rescue ActiveRecord::RecordNotFound
Chris@14 43 render_404
Chris@14 44 end
Chris@14 45
Chris@14 46 def new
Chris@14 47 journal = Journal.find(params[:journal_id]) if params[:journal_id]
Chris@14 48 if journal
Chris@14 49 user = journal.user
Chris@14 50 text = journal.notes
Chris@14 51 else
Chris@14 52 user = @issue.author
Chris@14 53 text = @issue.description
Chris@14 54 end
Chris@14 55 # Replaces pre blocks with [...]
Chris@14 56 text = text.to_s.strip.gsub(%r{<pre>((.|\s)*?)</pre>}m, '[...]')
Chris@14 57 content = "#{ll(Setting.default_language, :text_user_wrote, user)}\n> "
Chris@14 58 content << text.gsub(/(\r?\n|\r\n?)/, "\n> ") + "\n\n"
Chris@14 59
Chris@14 60 render(:update) { |page|
Chris@14 61 page.<< "$('notes').value = \"#{escape_javascript content}\";"
Chris@14 62 page.show 'update'
Chris@14 63 page << "Form.Element.focus('notes');"
Chris@14 64 page << "Element.scrollTo('update');"
Chris@14 65 page << "$('notes').scrollTop = $('notes').scrollHeight - $('notes').clientHeight;"
Chris@14 66 }
Chris@14 67 end
Chris@0 68
Chris@0 69 def edit
Chris@0 70 if request.post?
Chris@0 71 @journal.update_attributes(:notes => params[:notes]) if params[:notes]
Chris@0 72 @journal.destroy if @journal.details.empty? && @journal.notes.blank?
Chris@0 73 call_hook(:controller_journals_edit_post, { :journal => @journal, :params => params})
Chris@0 74 respond_to do |format|
Chris@0 75 format.html { redirect_to :controller => 'issues', :action => 'show', :id => @journal.journalized_id }
Chris@0 76 format.js { render :action => 'update' }
Chris@0 77 end
Chris@0 78 end
Chris@0 79 end
Chris@0 80
Chris@0 81 private
Chris@0 82 def find_journal
Chris@0 83 @journal = Journal.find(params[:id])
Chris@0 84 (render_403; return false) unless @journal.editable_by?(User.current)
Chris@0 85 @project = @journal.journalized.project
Chris@0 86 rescue ActiveRecord::RecordNotFound
Chris@0 87 render_404
Chris@0 88 end
Chris@14 89
Chris@14 90 # TODO: duplicated in IssuesController
Chris@14 91 def find_issue
Chris@14 92 @issue = Issue.find(params[:id], :include => [:project, :tracker, :status, :author, :priority, :category])
Chris@14 93 @project = @issue.project
Chris@14 94 rescue ActiveRecord::RecordNotFound
Chris@14 95 render_404
Chris@14 96 end
Chris@0 97 end