Class: Addressbook::ContactsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/addressbook/contacts_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#current_addressbook_account

Instance Method Details

#createObject



27
28
29
30
31
32
33
34
35
36
# File 'app/controllers/addressbook/contacts_controller.rb', line 27

def create
  @contact = .contacts.new(contact_params)
  store_photo

  if @contact.save
    redirect_to contacts_path, notice: t('addressbook.contact.create_notice')
  else
    render :new
  end
end

#destroyObject



50
51
52
# File 'app/controllers/addressbook/contacts_controller.rb', line 50

def destroy
  @contact.destroy
end

#editObject



38
39
40
# File 'app/controllers/addressbook/contacts_controller.rb', line 38

def edit
  
end

#import_csvObject



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(, 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_vcardObject



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(, 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

#indexObject



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: .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

#newObject



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

#updateObject



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