Class: Fakecrm::Activity

Inherits:
Object
  • Object
show all
Includes:
DataMapper::Resource, Kinds
Defined in:
lib/fakecrm/resource/activity.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Kinds

included, #one_of_a_kind?

Class Method Details

.transform_comment_params(params) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/fakecrm/resource/activity.rb', line 59

def self.transform_comment_params( params )
  if params["comment_notes"]
    if params["comment_contact_id"]
      contact = Contact.get!( params["comment_contact_id"].to_i )
    else
      contact = Contact.search(:params => {:login => 'root'}).first
    end
    new_comment = {
      :contact_id => contact.id,
      :updated_by => 'root',
      :notes => params["comment_notes"].to_s,
      :published => !!params["comment_published"],
      :updated_at => Time.now
    }
    params["comments"] = (Activity.get!(params["id"].to_i).comments || []) rescue []
    params["comments"] << new_comment
  end
  params.delete("comment_notes")
  params.delete("comment_contact_id")
  params.delete("comment_published")

  return params
rescue ::DataMapper::ObjectNotFoundError
  status 404
end

Instance Method Details

#check_stateObject



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/fakecrm/resource/activity.rb', line 43

def check_state
  custom_type = self.custom_type
  if !custom_type.nil? && !custom_type.states.nil? && !custom_type.states.empty?
    if self.state.nil? || !custom_type.states.include?(self.state)
      # FIXME: localization
      return [false, 'ist kein gültiger Wert']
    end
  end

  return true
end

#custom_typeObject



39
40
41
# File 'lib/fakecrm/resource/activity.rb', line 39

def custom_type
  CustomType.get!(self.kind) unless self.kind.nil?
end