Class: Contact
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Contact
- Defined in:
- app/models/base/contact.rb
Overview
Schema Information
Table name: contacts
id :integer not null, primary key
user_id :integer
lead_id :integer
assigned_to :integer
reports_to :integer
first_name :string(64) default(""), not null
last_name :string(64) default(""), not null
access :string(8) default("Public")
title :string(64)
department :string(64)
source :string(32)
email :string(64)
alt_email :string(64)
phone :string(32)
mobile :string(32)
fax :string(32)
blog :string(128)
linkedin :string(128)
facebook :string(128)
twitter :string(128)
born_on :date
do_not_call :boolean default(FALSE), not null
deleted_at :datetime
created_at :datetime
updated_at :datetime
background_info :string(255)
skype :string(128)
Class Method Summary collapse
-
.create_for(model, account, opportunity, params) ⇒ Object
Class methods.
- .first_name_position ⇒ Object
- .outline ⇒ Object
-
.per_page ⇒ Object
Default values provided through class methods.
Instance Method Summary collapse
-
#attach!(attachment) ⇒ Object
Attach given attachment to the contact if it hasn’t been attached already.
-
#discard!(attachment) ⇒ Object
Discard given attachment from the contact.
-
#full_name(format = nil) ⇒ Object
(also: #name)
—————————————————————————-.
-
#save_with_account_and_permissions(params) ⇒ Object
Backend handler for [Create New Contact] form (see contact/create).
-
#update_with_account_and_permissions(params) ⇒ Object
Backend handler for [Update Contact] form (see contact/update).
Class Method Details
.create_for(model, account, opportunity, params) ⇒ Object
Class methods.
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'app/models/base/contact.rb', line 155 def self.create_for(model, account, opportunity, params) attributes = { :lead_id => model.id, :user_id => params[:account][:user_id], :assigned_to => params[:account][:assigned_to], :access => params[:access] } %w(first_name last_name title source email alt_email phone mobile blog linkedin facebook twitter skype do_not_call background_info).each do |name| attributes[name] = model.send(name.intern) end contact = Contact.new(attributes) contact.business_address = Address.new(:street1 => model.business_address.street1, :street2 => model.business_address.street2, :city => model.business_address.city, :state => model.business_address.state, :zipcode => model.business_address.zipcode, :country => model.business_address.country, :full_address => model.business_address.full_address, :address_type => "Business") unless model.business_address.nil? # Save the contact only if the account and the opportunity have no errors. if account.errors.empty? && opportunity.errors.empty? # Note: contact.account = account doesn't seem to work here. contact.account_contact = AccountContact.new(:account => account, :contact => contact) unless account.id.blank? contact.opportunities << opportunity unless opportunity.id.blank? if contact.access != "Lead" || model.nil? contact.(params[:users]) else contact.(model) end end contact end |
.first_name_position ⇒ Object
99 |
# File 'app/models/base/contact.rb', line 99 def self.first_name_position ; "before" ; end |
.outline ⇒ Object
98 |
# File 'app/models/base/contact.rb', line 98 def self.outline ; "long" ; end |
.per_page ⇒ Object
Default values provided through class methods.
97 |
# File 'app/models/base/contact.rb', line 97 def self.per_page ; 20 ; end |
Instance Method Details
#attach!(attachment) ⇒ Object
Attach given attachment to the contact if it hasn’t been attached already.
137 138 139 140 141 |
# File 'app/models/base/contact.rb', line 137 def attach!() unless self.send("#{.class.name.downcase}_ids").include?(.id) self.send(.class.name.tableize) << end end |
#discard!(attachment) ⇒ Object
Discard given attachment from the contact.
145 146 147 148 149 150 151 |
# File 'app/models/base/contact.rb', line 145 def discard!() if .is_a?(Task) .update_attribute(:asset, nil) else # Opportunities self.send(.class.name.tableize).delete() end end |
#full_name(format = nil) ⇒ Object Also known as: name
102 103 104 105 106 107 108 |
# File 'app/models/base/contact.rb', line 102 def full_name(format = nil) if format.nil? || format == "before" "#{self.first_name} #{self.last_name}" else "#{self.last_name}, #{self.first_name}" end end |
#save_with_account_and_permissions(params) ⇒ Object
Backend handler for [Create New Contact] form (see contact/create).
113 114 115 116 117 118 |
# File 'app/models/base/contact.rb', line 113 def (params) account = Account.create_or_select_for(self, params[:account], params[:users]) self.account_contact = AccountContact.new(:account => account, :contact => self) unless account.id.blank? self.opportunities << Opportunity.find(params[:opportunity]) unless params[:opportunity].blank? self.(params[:users]) end |
#update_with_account_and_permissions(params) ⇒ Object
Backend handler for [Update Contact] form (see contact/update).
122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'app/models/base/contact.rb', line 122 def (params) if params[:account][:id] == "" || params[:account][:name] == "" self.account = nil # Contact is not associated with the account anymore. else account = Account.create_or_select_for(self, params[:account], params[:users]) if self.account != account and account.id.present? self.account_contact = AccountContact.new(:account => account, :contact => self) end end self.reload self.(params[:contact], params[:users]) end |