annotate .svn/pristine/b6/b612d779ff3fef92dfc91fea6eed6b0e5e922b26.svn-base @ 1519:afce8026aaeb redmine-2.4-integration

Merge from branch "live"
author Chris Cannam
date Tue, 09 Sep 2014 09:34:53 +0100
parents cbb26bc654de
children
rev   line source
Chris@909 1 # Redmine - project management software
Chris@909 2 # Copyright (C) 2006-2011 Jean-Philippe Lang
Chris@909 3 #
Chris@909 4 # This program is free software; you can redistribute it and/or
Chris@909 5 # modify it under the terms of the GNU General Public License
Chris@909 6 # as published by the Free Software Foundation; either version 2
Chris@909 7 # of the License, or (at your option) any later version.
Chris@909 8 #
Chris@909 9 # This program is distributed in the hope that it will be useful,
Chris@909 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@909 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@909 12 # GNU General Public License for more details.
Chris@909 13 #
Chris@909 14 # You should have received a copy of the GNU General Public License
Chris@909 15 # along with this program; if not, write to the Free Software
Chris@909 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@909 17
Chris@909 18 class JournalsController < ApplicationController
Chris@909 19 before_filter :find_journal, :only => [:edit, :diff]
Chris@909 20 before_filter :find_issue, :only => [:new]
Chris@909 21 before_filter :find_optional_project, :only => [:index]
Chris@909 22 before_filter :authorize, :only => [:new, :edit, :diff]
Chris@909 23 accept_rss_auth :index
Chris@909 24 menu_item :issues
Chris@909 25
Chris@909 26 helper :issues
Chris@909 27 helper :custom_fields
Chris@909 28 helper :queries
Chris@909 29 include QueriesHelper
Chris@909 30 helper :sort
Chris@909 31 include SortHelper
Chris@909 32
Chris@909 33 def index
Chris@909 34 retrieve_query
Chris@909 35 sort_init 'id', 'desc'
Chris@909 36 sort_update(@query.sortable_columns)
Chris@909 37
Chris@909 38 if @query.valid?
Chris@909 39 @journals = @query.journals(:order => "#{Journal.table_name}.created_on DESC",
Chris@909 40 :limit => 25)
Chris@909 41 end
Chris@909 42 @title = (@project ? @project.name : Setting.app_title) + ": " + (@query.new_record? ? l(:label_changes_details) : @query.name)
Chris@909 43 render :layout => false, :content_type => 'application/atom+xml'
Chris@909 44 rescue ActiveRecord::RecordNotFound
Chris@909 45 render_404
Chris@909 46 end
Chris@909 47
Chris@909 48 def diff
Chris@909 49 @issue = @journal.issue
Chris@909 50 if params[:detail_id].present?
Chris@909 51 @detail = @journal.details.find_by_id(params[:detail_id])
Chris@909 52 else
Chris@909 53 @detail = @journal.details.detect {|d| d.prop_key == 'description'}
Chris@909 54 end
Chris@909 55 (render_404; return false) unless @issue && @detail
Chris@909 56 @diff = Redmine::Helpers::Diff.new(@detail.value, @detail.old_value)
Chris@909 57 end
Chris@909 58
Chris@909 59 def new
Chris@909 60 journal = Journal.find(params[:journal_id]) if params[:journal_id]
Chris@909 61 if journal
Chris@909 62 user = journal.user
Chris@909 63 text = journal.notes
Chris@909 64 else
Chris@909 65 user = @issue.author
Chris@909 66 text = @issue.description
Chris@909 67 end
Chris@909 68 # Replaces pre blocks with [...]
Chris@909 69 text = text.to_s.strip.gsub(%r{<pre>((.|\s)*?)</pre>}m, '[...]')
Chris@909 70 content = "#{ll(Setting.default_language, :text_user_wrote, user)}\n> "
Chris@909 71 content << text.gsub(/(\r?\n|\r\n?)/, "\n> ") + "\n\n"
Chris@909 72
Chris@909 73 render(:update) { |page|
Chris@909 74 page.<< "$('notes').value = \"#{escape_javascript content}\";"
Chris@909 75 page.show 'update'
Chris@909 76 page << "Form.Element.focus('notes');"
Chris@909 77 page << "Element.scrollTo('update');"
Chris@909 78 page << "$('notes').scrollTop = $('notes').scrollHeight - $('notes').clientHeight;"
Chris@909 79 }
Chris@909 80 end
Chris@909 81
Chris@909 82 def edit
Chris@909 83 (render_403; return false) unless @journal.editable_by?(User.current)
Chris@909 84 if request.post?
Chris@909 85 @journal.update_attributes(:notes => params[:notes]) if params[:notes]
Chris@909 86 @journal.destroy if @journal.details.empty? && @journal.notes.blank?
Chris@909 87 call_hook(:controller_journals_edit_post, { :journal => @journal, :params => params})
Chris@909 88 respond_to do |format|
Chris@909 89 format.html { redirect_to :controller => 'issues', :action => 'show', :id => @journal.journalized_id }
Chris@909 90 format.js { render :action => 'update' }
Chris@909 91 end
Chris@909 92 else
Chris@909 93 respond_to do |format|
Chris@909 94 format.html {
Chris@909 95 # TODO: implement non-JS journal update
Chris@909 96 render :nothing => true
Chris@909 97 }
Chris@909 98 format.js
Chris@909 99 end
Chris@909 100 end
Chris@909 101 end
Chris@909 102
Chris@909 103 private
Chris@909 104
Chris@909 105 def find_journal
Chris@909 106 @journal = Journal.find(params[:id])
Chris@909 107 @project = @journal.journalized.project
Chris@909 108 rescue ActiveRecord::RecordNotFound
Chris@909 109 render_404
Chris@909 110 end
Chris@909 111
Chris@909 112 # TODO: duplicated in IssuesController
Chris@909 113 def find_issue
Chris@909 114 @issue = Issue.find(params[:id], :include => [:project, :tracker, :status, :author, :priority, :category])
Chris@909 115 @project = @issue.project
Chris@909 116 rescue ActiveRecord::RecordNotFound
Chris@909 117 render_404
Chris@909 118 end
Chris@909 119 end