annotate .svn/pristine/ed/ed57efbc247183b288b943a718082419611a4686.svn-base @ 1327:287f201c2802 redmine-2.2-integration

Add italic
author Chris Cannam <chris.cannam@soundsoftware.ac.uk>
date Wed, 19 Jun 2013 20:56:22 +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 Journal < ActiveRecord::Base
Chris@909 19 belongs_to :journalized, :polymorphic => true
Chris@909 20 # added as a quick fix to allow eager loading of the polymorphic association
Chris@909 21 # since always associated to an issue, for now
Chris@909 22 belongs_to :issue, :foreign_key => :journalized_id
Chris@909 23
Chris@909 24 belongs_to :user
Chris@909 25 has_many :details, :class_name => "JournalDetail", :dependent => :delete_all
Chris@909 26 attr_accessor :indice
Chris@909 27
Chris@909 28 acts_as_event :title => Proc.new {|o| status = ((s = o.new_status) ? " (#{s})" : nil); "#{o.issue.tracker} ##{o.issue.id}#{status}: #{o.issue.subject}" },
Chris@909 29 :description => :notes,
Chris@909 30 :author => :user,
Chris@909 31 :type => Proc.new {|o| (s = o.new_status) ? (s.is_closed? ? 'issue-closed' : 'issue-edit') : 'issue-note' },
Chris@909 32 :url => Proc.new {|o| {:controller => 'issues', :action => 'show', :id => o.issue.id, :anchor => "change-#{o.id}"}}
Chris@909 33
Chris@909 34 acts_as_activity_provider :type => 'issues',
Chris@909 35 :author_key => :user_id,
Chris@909 36 :find_options => {:include => [{:issue => :project}, :details, :user],
Chris@909 37 :conditions => "#{Journal.table_name}.journalized_type = 'Issue' AND" +
Chris@909 38 " (#{JournalDetail.table_name}.prop_key = 'status_id' OR #{Journal.table_name}.notes <> '')"}
Chris@909 39
Chris@909 40 named_scope :visible, lambda {|*args| {
Chris@909 41 :include => {:issue => :project},
Chris@909 42 :conditions => Issue.visible_condition(args.shift || User.current, *args)
Chris@909 43 }}
Chris@909 44
Chris@909 45 def save(*args)
Chris@909 46 # Do not save an empty journal
Chris@909 47 (details.empty? && notes.blank?) ? false : super
Chris@909 48 end
Chris@909 49
Chris@909 50 # Returns the new status if the journal contains a status change, otherwise nil
Chris@909 51 def new_status
Chris@909 52 c = details.detect {|detail| detail.prop_key == 'status_id'}
Chris@909 53 (c && c.value) ? IssueStatus.find_by_id(c.value.to_i) : nil
Chris@909 54 end
Chris@909 55
Chris@909 56 def new_value_for(prop)
Chris@909 57 c = details.detect {|detail| detail.prop_key == prop}
Chris@909 58 c ? c.value : nil
Chris@909 59 end
Chris@909 60
Chris@909 61 def editable_by?(usr)
Chris@909 62 usr && usr.logged? && (usr.allowed_to?(:edit_issue_notes, project) || (self.user == usr && usr.allowed_to?(:edit_own_issue_notes, project)))
Chris@909 63 end
Chris@909 64
Chris@909 65 def project
Chris@909 66 journalized.respond_to?(:project) ? journalized.project : nil
Chris@909 67 end
Chris@909 68
Chris@909 69 def attachments
Chris@909 70 journalized.respond_to?(:attachments) ? journalized.attachments : nil
Chris@909 71 end
Chris@909 72
Chris@909 73 # Returns a string of css classes
Chris@909 74 def css_classes
Chris@909 75 s = 'journal'
Chris@909 76 s << ' has-notes' unless notes.blank?
Chris@909 77 s << ' has-details' unless details.blank?
Chris@909 78 s
Chris@909 79 end
Chris@909 80
Chris@909 81 def notify?
Chris@909 82 @notify != false
Chris@909 83 end
Chris@909 84
Chris@909 85 def notify=(arg)
Chris@909 86 @notify = arg
Chris@909 87 end
Chris@909 88 end