Sha256: b747f8ea4b43701fecdc3d3ca1dc8f98c626d7b271c26117914d7da1c96e1e24

Contents?: true

Size: 1.75 KB

Versions: 11

Compression:

Stored size: 1.75 KB

Contents

class ::IshManager::LeadsController < IshManager::ApplicationController

  before_action :set_lists

  ## alphabetized : )

  def bulkop
    authorize! :bulkop, ::Lead
    case params[:a]
    when 'add_to_campaign'
      c = 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
    end
  end

  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

  def edit
    @lead = ::Lead.find params[:id]
    authorize! :edit, @lead
  end

  def index
    authorize! :index, ::Lead
    @leads = ::Lead.all.includes( :leadset )
  end

  def new
    @new_lead = ::Lead.new
    authorize! :new, @new_lead
  end

  def show
    authorize! :redirect, IshManager::Ability
    redirect_to :action => :edit, :id => params[:id]
  end

  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 => 'index'
  end

  private

  def set_lists
    @leadsets_list = [ [nil,nil] ] + ::Leadset.all.map { |k| [ k.name, k.id ] }
    @email_campaigns_list = [ [nil,nil] ] + Ish::EmailContext.all_campaigns.map { |k| [ k.slug, k.id ] }
  end

end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
ish_manager-0.1.8.340 app/controllers/ish_manager/leads_controller.rb
ish_manager-0.1.8.339 app/controllers/ish_manager/leads_controller.rb
ish_manager-0.1.8.338 app/controllers/ish_manager/leads_controller.rb
ish_manager-0.1.8.337 app/controllers/ish_manager/leads_controller.rb
ish_manager-0.1.8.336 app/controllers/ish_manager/leads_controller.rb
ish_manager-0.1.8.335 app/controllers/ish_manager/leads_controller.rb
ish_manager-0.1.8.334 app/controllers/ish_manager/leads_controller.rb
ish_manager-0.1.8.333 app/controllers/ish_manager/leads_controller.rb
ish_manager-0.1.8.332 app/controllers/ish_manager/leads_controller.rb
ish_manager-0.1.8.331 app/controllers/ish_manager/leads_controller.rb
ish_manager-0.1.8.330 app/controllers/ish_manager/leads_controller.rb