annotate app/models/.svn/text-base/journal.rb.svn-base @ 904:0a8317a50fa0 redmine-1.1

Close obsolete branch redmine-1.1
author Chris Cannam
date Fri, 14 Jan 2011 12:53:21 +0000
parents 40f7cfd4df19
children cbce1fd3b1b7
rev   line source
Chris@0 1 # redMine - project management software
Chris@0 2 # Copyright (C) 2006 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 Journal < ActiveRecord::Base
Chris@0 19 belongs_to :journalized, :polymorphic => true
Chris@0 20 # added as a quick fix to allow eager loading of the polymorphic association
Chris@0 21 # since always associated to an issue, for now
Chris@0 22 belongs_to :issue, :foreign_key => :journalized_id
Chris@0 23
Chris@0 24 belongs_to :user
Chris@0 25 has_many :details, :class_name => "JournalDetail", :dependent => :delete_all
Chris@0 26 attr_accessor :indice
Chris@0 27
Chris@0 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@0 29 :description => :notes,
Chris@0 30 :author => :user,
Chris@0 31 :type => Proc.new {|o| (s = o.new_status) ? (s.is_closed? ? 'issue-closed' : 'issue-edit') : 'issue-note' },
Chris@0 32 :url => Proc.new {|o| {:controller => 'issues', :action => 'show', :id => o.issue.id, :anchor => "change-#{o.id}"}}
Chris@0 33
Chris@0 34 acts_as_activity_provider :type => 'issues',
Chris@0 35 :permission => :view_issues,
Chris@0 36 :author_key => :user_id,
Chris@0 37 :find_options => {:include => [{:issue => :project}, :details, :user],
Chris@0 38 :conditions => "#{Journal.table_name}.journalized_type = 'Issue' AND" +
Chris@0 39 " (#{JournalDetail.table_name}.prop_key = 'status_id' OR #{Journal.table_name}.notes <> '')"}
Chris@0 40
Chris@0 41 def save(*args)
Chris@0 42 # Do not save an empty journal
Chris@0 43 (details.empty? && notes.blank?) ? false : super
Chris@0 44 end
Chris@0 45
Chris@0 46 # Returns the new status if the journal contains a status change, otherwise nil
Chris@0 47 def new_status
Chris@0 48 c = details.detect {|detail| detail.prop_key == 'status_id'}
Chris@0 49 (c && c.value) ? IssueStatus.find_by_id(c.value.to_i) : nil
Chris@0 50 end
Chris@0 51
Chris@0 52 def new_value_for(prop)
Chris@0 53 c = details.detect {|detail| detail.prop_key == prop}
Chris@0 54 c ? c.value : nil
Chris@0 55 end
Chris@0 56
Chris@0 57 def editable_by?(usr)
Chris@0 58 usr && usr.logged? && (usr.allowed_to?(:edit_issue_notes, project) || (self.user == usr && usr.allowed_to?(:edit_own_issue_notes, project)))
Chris@0 59 end
Chris@0 60
Chris@0 61 def project
Chris@0 62 journalized.respond_to?(:project) ? journalized.project : nil
Chris@0 63 end
Chris@0 64
Chris@0 65 def attachments
Chris@0 66 journalized.respond_to?(:attachments) ? journalized.attachments : nil
Chris@0 67 end
chris@22 68
chris@22 69 # Returns a string of css classes
chris@22 70 def css_classes
chris@22 71 s = 'journal'
chris@22 72 s << ' has-notes' unless notes.blank?
chris@22 73 s << ' has-details' unless details.blank?
chris@22 74 s
chris@22 75 end
Chris@0 76 end