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