Class: IshManager::LeadsController
Instance Method Summary
collapse
#basic_auth, #home, #tinymce
Instance Method Details
#bulkop ⇒ Object
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'app/controllers/ish_manager/leads_controller.rb', line 8
def bulkop
authorize! :bulkop, ::Lead
case params[:op]
when Lead::OP_ADD_TO_CAMPAIGN
c = Ish::EmailCampaign.find params[:email_campaign_id]
params[:lead_ids].each do |lead_id|
c_lead = EmailCampaignLead.new( lead_id: lead_id, email_campaign_id: c.id )
flag = c_lead.save
if !flag
puts! c_lead.errors.full_messages.join(", ")
end
end
flash[:notice] = 'Done acted; See logs.'
redirect_to action: :index
when Lead::OP_DELETE
outs = []
params[:lead_ids].each do |lead_id|
lead = Lead.find( lead_id )
outs.push lead.discard
end
flash[:notice] = "Outcomes: #{outs.inspect}."
redirect_to action: :index
else
throw "Unknown op: #{params[:op]}."
end
end
|
#create ⇒ Object
38
39
40
41
42
43
44
45
46
47
|
# File 'app/controllers/ish_manager/leads_controller.rb', line 38
def create
@lead = ::Lead.new params[:lead].permit!
authorize! :create, @lead
if @lead.save
flash[:notice] = "created lead"
else
flash[:alert] = "Cannot create lead: #{@lead.errors.messages}"
end
redirect_to :action => 'index'
end
|
#edit ⇒ Object
49
50
51
52
|
# File 'app/controllers/ish_manager/leads_controller.rb', line 49
def edit
@lead = ::Lead.find params[:id]
authorize! :edit, @lead
end
|
#import ⇒ Object
54
55
56
57
58
59
60
61
62
63
|
# File 'app/controllers/ish_manager/leads_controller.rb', line 54
def import
authorize! :import, ::Lead
file = params[:csv_file]
flags = Lead.import_v1( file )
flash[:notice] = "Result: #{flags.inspect}."
redirect_to action: 'new'
end
|
#index ⇒ Object
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
# File 'app/controllers/ish_manager/leads_controller.rb', line 65
def index
authorize! :index, ::Lead
@leads = ::Lead.kept.includes( :company )
if params[:q].present?
@leads = @leads.where(" email LIKE ? ", "%#{params[:q]}%" )
end
@leads = @leads.page( params[:leads_page ] ).per( current_profile.per_page )
end
|
#new ⇒ Object
98
99
100
101
|
# File 'app/controllers/ish_manager/leads_controller.rb', line 98
def new
@new_lead = ::Lead.new
authorize! :new, @new_lead
end
|
#show ⇒ Object
103
104
105
106
107
108
109
|
# File 'app/controllers/ish_manager/leads_controller.rb', line 103
def show
@lead = Lead.find params[:id]
authorize! :show, @lead
@schs = Sch.where( lead_id: @lead.id )
@ctxs = Ctx.where( lead_id: @lead.id )
@msgs = Msg.where( from: @lead.email )
end
|
#update ⇒ Object
111
112
113
114
115
116
117
118
119
120
121
|
# File 'app/controllers/ish_manager/leads_controller.rb', line 111
def update
@lead = ::Lead.find params[:id]
authorize! :update, @lead
if @lead.update_attributes params[:lead].permit!
flash[:notice] = 'Successfully updated lead.'
else
flash[:alert] = "Cannot update lead: #{@lead.errors.messages}"
end
redirect_to :action => 'show', id: @lead.id
end
|