Chris@909: # redMine - project management software Chris@909: # Copyright (C) 2006-2007 Jean-Philippe Lang Chris@909: # Chris@909: # This program is free software; you can redistribute it and/or Chris@909: # modify it under the terms of the GNU General Public License Chris@909: # as published by the Free Software Foundation; either version 2 Chris@909: # of the License, or (at your option) any later version. Chris@909: # Chris@909: # This program is distributed in the hope that it will be useful, Chris@909: # but WITHOUT ANY WARRANTY; without even the implied warranty of Chris@909: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Chris@909: # GNU General Public License for more details. Chris@909: # Chris@909: # You should have received a copy of the GNU General Public License Chris@909: # along with this program; if not, write to the Free Software Chris@909: # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Chris@909: Chris@909: module Redmine Chris@909: module Acts Chris@909: module Event Chris@909: def self.included(base) Chris@909: base.extend ClassMethods Chris@909: end Chris@909: Chris@909: module ClassMethods Chris@909: def acts_as_event(options = {}) Chris@909: return if self.included_modules.include?(Redmine::Acts::Event::InstanceMethods) Chris@909: default_options = { :datetime => :created_on, Chris@909: :title => :title, Chris@909: :description => :description, Chris@909: :author => :author, Chris@909: :url => {:controller => 'welcome'}, Chris@909: :type => self.name.underscore.dasherize } Chris@909: Chris@909: cattr_accessor :event_options Chris@909: self.event_options = default_options.merge(options) Chris@909: send :include, Redmine::Acts::Event::InstanceMethods Chris@909: end Chris@909: end Chris@909: Chris@909: module InstanceMethods Chris@909: def self.included(base) Chris@909: base.extend ClassMethods Chris@909: end Chris@909: Chris@909: %w(datetime title description author type).each do |attr| Chris@909: src = <<-END_SRC Chris@909: def event_#{attr} Chris@909: option = event_options[:#{attr}] Chris@909: if option.is_a?(Proc) Chris@909: option.call(self) Chris@909: elsif option.is_a?(Symbol) Chris@909: send(option) Chris@909: else Chris@909: option Chris@909: end Chris@909: end Chris@909: END_SRC Chris@909: class_eval src, __FILE__, __LINE__ Chris@909: end Chris@909: Chris@909: def event_date Chris@909: event_datetime.to_date Chris@909: end Chris@909: Chris@909: def event_url(options = {}) Chris@909: option = event_options[:url] Chris@909: if option.is_a?(Proc) Chris@909: option.call(self).merge(options) Chris@909: elsif option.is_a?(Hash) Chris@909: option.merge(options) Chris@909: elsif option.is_a?(Symbol) Chris@909: send(option).merge(options) Chris@909: else Chris@909: option Chris@909: end Chris@909: end Chris@909: Chris@909: # Returns the mail adresses of users that should be notified Chris@909: def recipients Chris@909: notified = project.notified_users Chris@909: notified.reject! {|user| !visible?(user)} Chris@909: notified.collect(&:mail) Chris@909: end Chris@909: Chris@909: module ClassMethods Chris@909: end Chris@909: end Chris@909: end Chris@909: end Chris@909: end