annotate .svn/pristine/2a/2ad19a5d216db9900f8c479e9b99d1592793dd37.svn-base @ 1298:4f746d8966dd redmine_2.3_integration

Merge from redmine-2.3 branch to create new branch redmine-2.3-integration
author Chris Cannam
date Fri, 14 Jun 2013 09:28:30 +0100
parents 622f24f53b42
children
rev   line source
Chris@1295 1 # Redmine - project management software
Chris@1295 2 # Copyright (C) 2006-2012 Jean-Philippe Lang
Chris@1295 3 #
Chris@1295 4 # This program is free software; you can redistribute it and/or
Chris@1295 5 # modify it under the terms of the GNU General Public License
Chris@1295 6 # as published by the Free Software Foundation; either version 2
Chris@1295 7 # of the License, or (at your option) any later version.
Chris@1295 8 #
Chris@1295 9 # This program is distributed in the hope that it will be useful,
Chris@1295 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@1295 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@1295 12 # GNU General Public License for more details.
Chris@1295 13 #
Chris@1295 14 # You should have received a copy of the GNU General Public License
Chris@1295 15 # along with this program; if not, write to the Free Software
Chris@1295 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@1295 17
Chris@1295 18 module Redmine
Chris@1295 19 module Acts
Chris@1295 20 module Event
Chris@1295 21 def self.included(base)
Chris@1295 22 base.extend ClassMethods
Chris@1295 23 end
Chris@1295 24
Chris@1295 25 module ClassMethods
Chris@1295 26 def acts_as_event(options = {})
Chris@1295 27 return if self.included_modules.include?(Redmine::Acts::Event::InstanceMethods)
Chris@1295 28 default_options = { :datetime => :created_on,
Chris@1295 29 :title => :title,
Chris@1295 30 :description => :description,
Chris@1295 31 :author => :author,
Chris@1295 32 :url => {:controller => 'welcome'},
Chris@1295 33 :type => self.name.underscore.dasherize }
Chris@1295 34
Chris@1295 35 cattr_accessor :event_options
Chris@1295 36 self.event_options = default_options.merge(options)
Chris@1295 37 send :include, Redmine::Acts::Event::InstanceMethods
Chris@1295 38 end
Chris@1295 39 end
Chris@1295 40
Chris@1295 41 module InstanceMethods
Chris@1295 42 def self.included(base)
Chris@1295 43 base.extend ClassMethods
Chris@1295 44 end
Chris@1295 45
Chris@1295 46 %w(datetime title description author type).each do |attr|
Chris@1295 47 src = <<-END_SRC
Chris@1295 48 def event_#{attr}
Chris@1295 49 option = event_options[:#{attr}]
Chris@1295 50 if option.is_a?(Proc)
Chris@1295 51 option.call(self)
Chris@1295 52 elsif option.is_a?(Symbol)
Chris@1295 53 send(option)
Chris@1295 54 else
Chris@1295 55 option
Chris@1295 56 end
Chris@1295 57 end
Chris@1295 58 END_SRC
Chris@1295 59 class_eval src, __FILE__, __LINE__
Chris@1295 60 end
Chris@1295 61
Chris@1295 62 def event_date
Chris@1295 63 event_datetime.to_date
Chris@1295 64 end
Chris@1295 65
Chris@1295 66 def event_url(options = {})
Chris@1295 67 option = event_options[:url]
Chris@1295 68 if option.is_a?(Proc)
Chris@1295 69 option.call(self).merge(options)
Chris@1295 70 elsif option.is_a?(Hash)
Chris@1295 71 option.merge(options)
Chris@1295 72 elsif option.is_a?(Symbol)
Chris@1295 73 send(option).merge(options)
Chris@1295 74 else
Chris@1295 75 option
Chris@1295 76 end
Chris@1295 77 end
Chris@1295 78
Chris@1295 79 # Returns the mail adresses of users that should be notified
Chris@1295 80 def recipients
Chris@1295 81 notified = project.notified_users
Chris@1295 82 notified.reject! {|user| !visible?(user)}
Chris@1295 83 notified.collect(&:mail)
Chris@1295 84 end
Chris@1295 85
Chris@1295 86 module ClassMethods
Chris@1295 87 end
Chris@1295 88 end
Chris@1295 89 end
Chris@1295 90 end
Chris@1295 91 end