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