To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / vendor / plugins / acts_as_event / lib / acts_as_event.rb @ 442:753f1380d6bc
History | View | Annotate | Download (2.9 KB)
| 1 |
# redMine - project management software
|
|---|---|
| 2 |
# Copyright (C) 2006-2007 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_url(options = {}) |
| 67 |
option = event_options[:url]
|
| 68 |
if option.is_a?(Proc) |
| 69 |
option.call(self).merge(options)
|
| 70 |
elsif option.is_a?(Hash) |
| 71 |
option.merge(options) |
| 72 |
elsif option.is_a?(Symbol) |
| 73 |
send(option).merge(options) |
| 74 |
else
|
| 75 |
option |
| 76 |
end
|
| 77 |
end
|
| 78 |
|
| 79 |
# Returns the mail adresses of users that should be notified
|
| 80 |
def recipients |
| 81 |
notified = project.notified_users |
| 82 |
notified.reject! {|user| !visible?(user)}
|
| 83 |
notified.collect(&:mail)
|
| 84 |
end
|
| 85 |
|
| 86 |
module ClassMethods |
| 87 |
end
|
| 88 |
end
|
| 89 |
end
|
| 90 |
end
|
| 91 |
end
|