comparison .svn/pristine/e4/e4897735528df3f63a14478e29488229fe020925.svn-base @ 1295:622f24f53b42 redmine-2.3

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