Class: ContactsController

Inherits:
EntitiesController show all
Defined in:
app/controllers/entities/contacts_controller.rb

Overview

Fat Free CRM Copyright © 2008-2011 by Michael Dvorkin

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License along with this program. If not, see <www.gnu.org/licenses/>.


Instance Method Summary collapse

Methods inherited from EntitiesController

#attach, #contacts, #discard, #leads, #opportunities, #subscribe, #unsubscribe, #versions

Methods inherited from ApplicationController

#auto_complete

Instance Method Details

#createObject

POST /contacts




72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'app/controllers/entities/contacts_controller.rb', line 72

def create
  respond_with(@contact) do |format|
    if @contact.(params)
      @contacts = get_contacts if called_from_index_page?
    else
      unless params[:account][:id].blank?
        @account = Account.find(params[:account][:id])
      else
        if request.referer =~ /\/accounts\/(.+)$/
          @account = Account.find($1) # related account
        else
          @account = Account.new(:user => current_user)
        end
      end
      @opportunity = Opportunity.my.find(params[:opportunity]) unless params[:opportunity].blank?
    end
  end
end

#destroyObject

DELETE /contacts/1




108
109
110
111
112
113
114
115
# File 'app/controllers/entities/contacts_controller.rb', line 108

def destroy
  @contact.destroy

  respond_with(@contact) do |format|
    format.html { respond_to_destroy(:html) }
    format.js   { respond_to_destroy(:ajax) }
  end
end

#editObject

GET /contacts/1/edit AJAX




61
62
63
64
65
66
67
68
# File 'app/controllers/entities/contacts_controller.rb', line 61

def edit
  @account = @contact. || Account.new(:user => current_user)
  if params[:previous].to_s =~ /(\d+)\z/
    @previous = Contact.my.find_by_id($1) || $1.to_i
  end

  respond_with(@contact)
end

#indexObject

GET /contacts




24
25
26
27
# File 'app/controllers/entities/contacts_controller.rb', line 24

def index
  @contacts = get_contacts(:page => params[:page])
  respond_with(@contacts)
end

#newObject

GET /contacts/new




43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'app/controllers/entities/contacts_controller.rb', line 43

def new
  @contact.attributes = {:user => current_user, :access => Setting.default_access}
  @account = Account.new(:user => current_user)

  if params[:related]
    model, id = params[:related].split('_')
    if related = model.classify.constantize.my.find_by_id(id)
      instance_variable_set("@#{model}", related)
    else
      respond_to_related_not_found(model) and return
    end
  end

  respond_with(@contact)
end

#optionsObject

GET /contacts/options AJAX




131
132
133
134
135
136
137
138
# File 'app/controllers/entities/contacts_controller.rb', line 131

def options
  unless params[:cancel].true?
    @per_page = current_user.pref[:contacts_per_page] || Contact.per_page
    @outline  = current_user.pref[:contacts_outline]  || Contact.outline
    @sort_by  = current_user.pref[:contacts_sort_by]  || Contact.sort_by
    @naming   = current_user.pref[:contacts_naming]   || Contact.first_name_position
  end
end

#redrawObject

POST /contacts/redraw AJAX




142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'app/controllers/entities/contacts_controller.rb', line 142

def redraw
  current_user.pref[:contacts_per_page] = params[:per_page] if params[:per_page]
  current_user.pref[:contacts_outline]  = params[:outline]  if params[:outline]

  # Sorting and naming only: set the same option for Leads if the hasn't been set yet.
  if params[:sort_by]
    current_user.pref[:contacts_sort_by] = Contact::sort_by_map[params[:sort_by]]
    if Lead::sort_by_fields.include?(params[:sort_by])
      current_user.pref[:leads_sort_by] ||= Lead::sort_by_map[params[:sort_by]]
    end
  end
  if params[:naming]
    current_user.pref[:contacts_naming] = params[:naming]
    current_user.pref[:leads_naming] ||= params[:naming]
  end

  @contacts = get_contacts(:page => 1) # Start one the first page.
  render :index
end

#showObject

GET /contacts/1




31
32
33
34
35
36
37
38
39
# File 'app/controllers/entities/contacts_controller.rb', line 31

def show
  respond_with(@contact) do |format|
    format.html do
      @stage = Setting.unroll(:opportunity_stage)
      @comment = Comment.new
      @timeline = timeline(@contact)
    end
  end
end

#updateObject

PUT /contacts/1




93
94
95
96
97
98
99
100
101
102
103
104
# File 'app/controllers/entities/contacts_controller.rb', line 93

def update
  respond_with(@contact) do |format|
    unless @contact.(params)
      @users = User.except(current_user)
      if @contact.
        @account = Account.find(@contact..id)
      else
        @account = Account.new(:user => current_user)
      end
    end
  end
end