Class: Addressbook::ContactsController
Instance Method Summary
collapse
#current_addressbook_account
Instance Method Details
#create ⇒ Object
27
28
29
30
31
32
33
34
35
36
|
# File 'app/controllers/addressbook/contacts_controller.rb', line 27
def create
@contact = current_addressbook_account.contacts.new(contact_params)
store_photo
if @contact.save
redirect_to contacts_path, notice: t('addressbook.contact.create_notice')
else
render :new
end
end
|
#destroy ⇒ Object
50
51
52
|
# File 'app/controllers/addressbook/contacts_controller.rb', line 50
def destroy
@contact.destroy
end
|
#edit ⇒ Object
38
39
40
|
# File 'app/controllers/addressbook/contacts_controller.rb', line 38
def edit
end
|
#import_csv ⇒ Object
63
64
65
66
67
68
69
70
|
# File 'app/controllers/addressbook/contacts_controller.rb', line 63
def import_csv
if !params[:csv].nil? && /(.*)?\.csv/ =~ params[:csv].original_filename
contacts = Addressbook::Contact.import_csv(current_addressbook_account, params[:csv])
redirect_to contacts_path, notice: t('addressbook.contact.import_notice', count: contacts.length)
else
redirect_to contacts_path, alert: t('addressbook.contact.invalid_csv')
end
end
|
#import_vcard ⇒ Object
54
55
56
57
58
59
60
61
|
# File 'app/controllers/addressbook/contacts_controller.rb', line 54
def import_vcard
if !params[:vcard].nil? && /(.*)?\.vcf/ =~ params[:vcard].original_filename
contacts = Addressbook::Contact.import_vcard(current_addressbook_account, params[:vcard])
redirect_to contacts_path, notice: t('addressbook.contact.import_notice', count: contacts.length)
else
redirect_to contacts_path, alert: t('addressbook.contact.invalid_vcard')
end
end
|
#index ⇒ Object
9
10
11
12
13
14
15
16
17
|
# File 'app/controllers/addressbook/contacts_controller.rb', line 9
def index
contacts = Addressbook::Contact.search(params.merge(account_id: current_addressbook_account.id))
@contacts = Kaminari::PaginatableArray.new(
contacts, {
limit: contacts.http_response['X-limit'].to_i,
offset: contacts.http_response['X-offset'].to_i,
total_count: contacts.http_response['X-total'].to_i
})
end
|
#new ⇒ Object
19
20
21
22
23
24
25
|
# File 'app/controllers/addressbook/contacts_controller.rb', line 19
def new
@contact = Addressbook::Contact.new
@contact.groups = []
@contact.emails = []
@contact.addresses = []
@contact.phones = []
end
|
#update ⇒ Object
42
43
44
45
46
47
48
|
# File 'app/controllers/addressbook/contacts_controller.rb', line 42
def update
if @contact.update_attributes(contact_params)
redirect_to contacts_path, notice: t('addressbook.contact.update_notice')
else
render :edit
end
end
|