You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

acts_as_event.rb 2.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. module Redmine
  18. module Acts
  19. module Event
  20. def self.included(base)
  21. base.extend ClassMethods
  22. end
  23. module ClassMethods
  24. def acts_as_event(options = {})
  25. return if self.included_modules.include?(Redmine::Acts::Event::InstanceMethods)
  26. default_options = { :datetime => :created_on,
  27. :title => :title,
  28. :description => :description,
  29. :author => :author,
  30. :url => {:controller => 'welcome'},
  31. :type => self.name.underscore.dasherize }
  32. cattr_accessor :event_options
  33. self.event_options = default_options.merge(options)
  34. send :include, Redmine::Acts::Event::InstanceMethods
  35. end
  36. end
  37. module InstanceMethods
  38. def self.included(base)
  39. base.extend ClassMethods
  40. end
  41. %w(datetime title description author type).each do |attr|
  42. src = <<-END_SRC
  43. def event_#{attr}
  44. option = event_options[:#{attr}]
  45. if option.is_a?(Proc)
  46. option.call(self)
  47. elsif option.is_a?(Symbol)
  48. send(option)
  49. else
  50. option
  51. end
  52. end
  53. END_SRC
  54. class_eval src, __FILE__, __LINE__
  55. end
  56. def event_date
  57. event_datetime.to_date
  58. end
  59. def event_url(options = {})
  60. option = event_options[:url]
  61. if option.is_a?(Proc)
  62. option.call(self).merge(options)
  63. elsif option.is_a?(Hash)
  64. option.merge(options)
  65. elsif option.is_a?(Symbol)
  66. send(option).merge(options)
  67. else
  68. option
  69. end
  70. end
  71. # Returns the mail adresses of users that should be notified
  72. def recipients
  73. notified = project.notified_users
  74. notified.reject! {|user| !visible?(user)}
  75. notified.collect(&:mail)
  76. end
  77. module ClassMethods
  78. end
  79. end
  80. end
  81. end
  82. end