annotate app/controllers/.svn/text-base/journals_controller.rb.svn-base @ 863:818ff422eece bug_168

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