annotate vendor/plugins/acts_as_event/lib/acts_as_event.rb @ 971:b80f97c892bc cannam

Merge from branch "get_statistics"
author Chris Cannam
date Fri, 19 Oct 2012 14:47:14 +0100
parents 513646585e45
children
rev   line source
Chris@0 1 # redMine - project management software
Chris@0 2 # Copyright (C) 2006-2007 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 module Redmine
Chris@0 19 module Acts
Chris@0 20 module Event
Chris@0 21 def self.included(base)
Chris@0 22 base.extend ClassMethods
Chris@0 23 end
Chris@0 24
Chris@0 25 module ClassMethods
Chris@0 26 def acts_as_event(options = {})
Chris@0 27 return if self.included_modules.include?(Redmine::Acts::Event::InstanceMethods)
Chris@0 28 default_options = { :datetime => :created_on,
Chris@0 29 :title => :title,
Chris@0 30 :description => :description,
Chris@0 31 :author => :author,
Chris@0 32 :url => {:controller => 'welcome'},
Chris@0 33 :type => self.name.underscore.dasherize }
Chris@0 34
Chris@0 35 cattr_accessor :event_options
Chris@0 36 self.event_options = default_options.merge(options)
Chris@0 37 send :include, Redmine::Acts::Event::InstanceMethods
Chris@0 38 end
Chris@0 39 end
Chris@0 40
Chris@0 41 module InstanceMethods
Chris@0 42 def self.included(base)
Chris@0 43 base.extend ClassMethods
Chris@0 44 end
Chris@0 45
Chris@0 46 %w(datetime title description author type).each do |attr|
Chris@0 47 src = <<-END_SRC
Chris@0 48 def event_#{attr}
Chris@0 49 option = event_options[:#{attr}]
Chris@0 50 if option.is_a?(Proc)
Chris@0 51 option.call(self)
Chris@0 52 elsif option.is_a?(Symbol)
Chris@0 53 send(option)
Chris@0 54 else
Chris@0 55 option
Chris@0 56 end
Chris@0 57 end
Chris@0 58 END_SRC
Chris@0 59 class_eval src, __FILE__, __LINE__
Chris@0 60 end
Chris@0 61
Chris@0 62 def event_date
Chris@0 63 event_datetime.to_date
Chris@0 64 end
Chris@0 65
Chris@0 66 def event_url(options = {})
Chris@0 67 option = event_options[:url]
Chris@0 68 if option.is_a?(Proc)
Chris@0 69 option.call(self).merge(options)
Chris@0 70 elsif option.is_a?(Hash)
Chris@0 71 option.merge(options)
Chris@0 72 elsif option.is_a?(Symbol)
Chris@0 73 send(option).merge(options)
Chris@0 74 else
Chris@0 75 option
Chris@0 76 end
Chris@0 77 end
Chris@0 78
Chris@0 79 # Returns the mail adresses of users that should be notified
Chris@0 80 def recipients
Chris@0 81 notified = project.notified_users
Chris@0 82 notified.reject! {|user| !visible?(user)}
Chris@0 83 notified.collect(&:mail)
Chris@0 84 end
Chris@0 85
Chris@0 86 module ClassMethods
Chris@0 87 end
Chris@0 88 end
Chris@0 89 end
Chris@0 90 end
Chris@0 91 end