diff --git a/app/controllers/meetings_controller.rb b/app/controllers/meetings_controller.rb index 5153d95980..a81a28bbf6 100644 --- a/app/controllers/meetings_controller.rb +++ b/app/controllers/meetings_controller.rb @@ -5,6 +5,9 @@ class MeetingsController < ApplicationController before_filter :find_meeting, :except => [:index, :new, :create] before_filter :convert_params, :only => [:create, :update] before_filter :authorize + + helper :watchers + include WatchersHelper def index # Wo sollen Meetings ohne Termin hin? diff --git a/app/models/meeting.rb b/app/models/meeting.rb index 13d40fa2fa..4d2838f605 100644 --- a/app/models/meeting.rb +++ b/app/models/meeting.rb @@ -7,10 +7,14 @@ class Meeting < ActiveRecord::Base has_one :minutes, :dependent => :destroy, :class_name => 'MeetingMinutes' has_many :participants, :dependent => :destroy, :class_name => 'MeetingParticipant' - accepts_nested_attributes_for :participants + acts_as_watchable + + accepts_nested_attributes_for :participants, :reject_if => proc {|attrs| !(attrs['attended'] || attrs['invited'])} validates_presence_of :title, :start_time + after_create :add_author_as_watcher + def self.find_time_sorted(*args) by_start_year_month_date = ActiveSupport::OrderedHash.new self.find(*args).group_by(&:start_year).each do |year,objs| @@ -57,4 +61,10 @@ class Meeting < ActiveRecord::Base self.start_time ||= Date.tomorrow + 10.hours self.duration ||= 1 end + + private + + def add_author_as_watcher + add_watcher(author) + end end diff --git a/app/models/meeting_participant.rb b/app/models/meeting_participant.rb index d6d789fa68..e20f3e90ab 100644 --- a/app/models/meeting_participant.rb +++ b/app/models/meeting_participant.rb @@ -7,6 +7,8 @@ class MeetingParticipant < ActiveRecord::Base named_scope :invited, :conditions => {:invited => true} named_scope :attended, :conditions => {:attended => true} + after_create :add_participant_as_watcher + def name user.present? ? user.name : self.name end @@ -20,4 +22,10 @@ class MeetingParticipant < ActiveRecord::Base end alias :to_s :name + + private + + def add_participant_as_watcher + meeting.add_watcher(user) + end end diff --git a/app/views/meetings/show.html.erb b/app/views/meetings/show.html.erb index d20c14a45b..6a28106be6 100644 --- a/app/views/meetings/show.html.erb +++ b/app/views/meetings/show.html.erb @@ -1,4 +1,5 @@