Class: AlchemyCrm::Admin::ContactsController
- Inherits:
-
BaseController
- Object
- Alchemy::Admin::ResourcesController
- BaseController
- AlchemyCrm::Admin::ContactsController
show all
- Includes:
- CSVMagic::ControllerActions
- Defined in:
- app/controllers/alchemy_crm/admin/contacts_controller.rb
Instance Method Summary
collapse
#alchemy_crm_t, #i18n_t, included, #translate_model_attribute
Instance Method Details
#autocomplete_tag_list ⇒ Object
82
83
84
85
|
# File 'app/controllers/alchemy_crm/admin/contacts_controller.rb', line 82
def autocomplete_tag_list
items = ActsAsTaggableOn::Tag.where(['LOWER(name) LIKE ?', "#{params[:term].downcase}%"])
render :json => json_for_autocomplete(items, :name)
end
|
#export ⇒ Object
72
73
74
75
76
77
78
79
80
|
# File 'app/controllers/alchemy_crm/admin/contacts_controller.rb', line 72
def export
if params[:id].present?
@contact = Contact.find(params[:id])
@contact.to_vcard
send_file("#{Rails.root.to_s}/tmp/#{@contact.fullname}.vcf")
else
render :layout => false
end
end
|
#import ⇒ Object
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
# File 'app/controllers/alchemy_crm/admin/contacts_controller.rb', line 56
def import
if request.post?
if params[:verified] == "1"
if params[:fields] || (params[:file] && !is_vcard_file?(params[:file]))
handle_csv_post_request
else
handle_vcf_post_request
end
else
@error = build_error_message(alchemy_crm_t(:imported_contacts_not_verified))
end
else
render :layout => !request.xhr?
end
end
|
#index ⇒ Object
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
# File 'app/controllers/alchemy_crm/admin/contacts_controller.rb', line 29
def index
if params[:query].blank?
@contacts = Contact.scoped
else
search_terms = ActiveRecord::Base.sanitize("%#{params[:query]}%")
@contacts = Contact.where(Contact::SEARCHABLE_ATTRIBUTES.map { |attribute|
"#{Contact.table_name}.#{attribute} LIKE #{search_terms}"
}.join(" OR "))
end
respond_to do |format|
format.html {
@contacts = @contacts.page(params[:page] || 1).per(per_page_value_for_screen_size)
}
format.csv {
export_file_as(:csv)
}
format.xls {
export_file_as(:xls)
}
end
end
|
#new ⇒ Object
51
52
53
54
|
# File 'app/controllers/alchemy_crm/admin/contacts_controller.rb', line 51
def new
@contact = Contact.new(:country => ::I18n.locale.to_s.upcase)
render :layout => false
end
|