annotate .svn/pristine/94/949d37a80713cf7b887931fe593651de0edde20c.svn-base @ 1519:afce8026aaeb redmine-2.4-integration

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