Class: CampaignsController

Inherits:
EntitiesController show all
Defined in:
app/controllers/entities/campaigns_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 /campaigns




73
74
75
76
77
78
79
80
81
82
# File 'app/controllers/entities/campaigns_controller.rb', line 73

def create
  @users = User.except(@current_user)

  respond_with(@campaign) do |format|
    if @campaign.save_with_permissions(params[:users])
      @campaigns = get_campaigns
      get_data_for_sidebar
    end
  end
end

#destroyObject

DELETE /campaigns/1




98
99
100
101
102
103
104
105
# File 'app/controllers/entities/campaigns_controller.rb', line 98

def destroy
  @campaign.destroy

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

#editObject

GET /campaigns/1/edit AJAX




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

def edit
  @users = User.except(@current_user)
  if params[:previous].to_s =~ /(\d+)\z/
    @previous = Campaign.my.find_by_id($1) || $1.to_i
  end

  respond_with(@campaign)
end

#filterObject

POST /campaigns/filter AJAX




141
142
143
144
145
# File 'app/controllers/entities/campaigns_controller.rb', line 141

def filter
  session[:campaigns_filter] = params[:status]
  @campaigns = get_campaigns(:page => 1)
  render :index
end

#indexObject

GET /campaigns




23
24
25
26
# File 'app/controllers/entities/campaigns_controller.rb', line 23

def index
  @campaigns = get_campaigns(:page => params[:page])
  respond_with(@campaigns)
end

#newObject

GET /campaigns/new GET /campaigns/new.json GET /campaigns/new.xml AJAX




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

def new
  @campaign.attributes = {:user => @current_user, :access => Setting.default_access}
  @users = User.except(@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(@campaign)
end

#optionsObject

GET /campaigns/options AJAX




121
122
123
124
125
126
127
# File 'app/controllers/entities/campaigns_controller.rb', line 121

def options
  unless params[:cancel].true?
    @per_page = @current_user.pref[:campaigns_per_page] || Campaign.per_page
    @outline  = @current_user.pref[:campaigns_outline]  || Campaign.outline
    @sort_by  = @current_user.pref[:campaigns_sort_by]  || Campaign.sort_by
  end
end

#redrawObject

POST /campaigns/redraw AJAX




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

def redraw
  @current_user.pref[:campaigns_per_page] = params[:per_page] if params[:per_page]
  @current_user.pref[:campaigns_outline]  = params[:outline]  if params[:outline]
  @current_user.pref[:campaigns_sort_by]  = Campaign::sort_by_map[params[:sort_by]] if params[:sort_by]
  @campaigns = get_campaigns(:page => 1)
  render :index
end

#showObject

GET /campaigns/1




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

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

#updateObject

PUT /campaigns/1




86
87
88
89
90
91
92
93
94
# File 'app/controllers/entities/campaigns_controller.rb', line 86

def update
  respond_with(@campaign) do |format|
    if @campaign.update_with_permissions(params[:campaign], params[:users])
      get_data_for_sidebar if called_from_index_page?
    else
      @users = User.except(@current_user) # Need it to redraw [Edit Campaign] form.
    end
  end
end