Sha256: 75760fe158a5e6c8c37e3a4df355c0ba6d9a5f67d7e02e2912d59d961279bc97

Contents?: true

Size: 1.01 KB

Versions: 15

Compression:

Stored size: 1.01 KB

Contents

# Copyright (c) 2008-2013 Michael Dvorkin and contributors.
#
# Fat Free CRM is freely distributable under the terms of MIT license.
# See MIT-LICENSE file or http://www.opensource.org/licenses/mit-license.php
#------------------------------------------------------------------------------
class TaskObserver < ActiveRecord::Observer
  observe :task

  @@tasks = {}

  def before_update(item)
    @@tasks[item.id] = Task.find(item.id).freeze
  end

  def after_update(item)
    original = @@tasks.delete(item.id)
    if original
      return log_activity(item, :complete)   if item.completed_at && original.completed_at.nil?
      return log_activity(item, :reassign)   if item.assigned_to != original.assigned_to
      return log_activity(item, :reschedule) if item.bucket != original.bucket
    end
  end

  private

  def log_activity(item, event)
    item.send(item.class.versions_association_name).create(event: event, whodunnit: PaperTrail.whodunnit)
  end

  ActiveSupport.run_load_hooks(:fat_free_crm_task_observer, self)
end

Version data entries

15 entries across 15 versions & 2 rubygems

Version Path
fat_free_crm-0.14.2 app/models/observers/task_observer.rb
fat_free_crm-0.15.2 app/models/observers/task_observer.rb
fat_free_crm-0.16.4 app/models/observers/task_observer.rb
fat_free_crm-0.14.1 app/models/observers/task_observer.rb
fat_free_crm-0.15.1 app/models/observers/task_observer.rb
fat_free_crm-0.16.3 app/models/observers/task_observer.rb
fat_free_crm-0.16.2 app/models/observers/task_observer.rb
fat_free_crm-0.16.1 app/models/observers/task_observer.rb
fat_free_crm-0.16.0 app/models/observers/task_observer.rb
fat_free_crm-0.15.0 app/models/observers/task_observer.rb
fat_free_crm-0.15.0.beta.2 app/models/observers/task_observer.rb
fat_free_crm-0.15.0.beta app/models/observers/task_observer.rb
fat_free_crm-0.14.0 app/models/observers/task_observer.rb
reduced_fat_crm-0.15.0.beta app/models/observers/task_observer.rb
reduced_fat_crm-0.14.0 app/models/observers/task_observer.rb