Class: Forge::DispatchesController

Inherits:
ForgeController show all
Defined in:
lib/forge/app/controllers/forge/dispatches_controller.rb

Instance Method Summary collapse

Methods inherited from ForgeController

#get_menu_items, #load_help, #set_crumbs, #set_title, #uses_ckeditor

Methods inherited from ApplicationController

#app_init

Instance Method Details

#chart_dataObject



27
28
29
# File 'lib/forge/app/controllers/forge/dispatches_controller.rb', line 27

def chart_data
  render :json => @dispatch.chart_data
end

#clicksObject



35
36
37
# File 'lib/forge/app/controllers/forge/dispatches_controller.rb', line 35

def clicks
  @clicks = DispatchLinkClick.includes(:dispatch_link).where("dispatch_links.dispatch_id = ?", @dispatch.id).paginate(:per_page => 15, :page => params[:page])
end

#createObject



43
44
45
46
47
48
49
50
51
# File 'lib/forge/app/controllers/forge/dispatches_controller.rb', line 43

def create
  @dispatch = Dispatch.new(params[:dispatch])
  if @dispatch.save
    flash[:notice] = 'Dispatch was successfully created.'
    redirect_to(forge_dispatches_path)
  else
    render :action => "new"
  end
end

#destroyObject



62
63
64
65
# File 'lib/forge/app/controllers/forge/dispatches_controller.rb', line 62

def destroy
  @dispatch.destroy
  redirect_to(forge_dispatches_path)
end

#editObject



20
21
# File 'lib/forge/app/controllers/forge/dispatches_controller.rb', line 20

def edit
end

#indexObject



5
6
7
8
9
10
11
12
13
14
# File 'lib/forge/app/controllers/forge/dispatches_controller.rb', line 5

def index
  respond_to do |format|
    format.html { @dispatches = Dispatch.paginate(:per_page => 10, :page => params[:page]) }
    format.js { 
      params[:q] ||= ''
      @dispatches = Dispatch.where("LOWER(subject) LIKE ? OR LOWER(content) LIKE ?", "%#{params[:q].downcase}%", "%#{params[:q].downcase}%")
      render :partial => "dispatch", :collection => @dispatches
    }
  end
end

#newObject



16
17
18
# File 'lib/forge/app/controllers/forge/dispatches_controller.rb', line 16

def new
  @dispatch = Dispatch.new
end

#opensObject



31
32
33
# File 'lib/forge/app/controllers/forge/dispatches_controller.rb', line 31

def opens
  @opens = @dispatch.opens.paginate(:per_page => 15, :page => params[:page])
end

#queueObject



67
68
69
70
# File 'lib/forge/app/controllers/forge/dispatches_controller.rb', line 67

def queue
  @groups = SubscriberGroup.all
  @total_subscribers = Subscriber.count
end

#send_allObject



78
79
80
81
82
83
84
85
86
87
# File 'lib/forge/app/controllers/forge/dispatches_controller.rb', line 78

def send_all
  if params[:group_send] && params[:group_ids].blank?
    flash[:warning] = "You must select the groups to send the dispatch to."
    redirect_to queue_forge_dispatch_path(@dispatch)
  else
    @dispatch.deliver!(params[:group_ids])
    flash[:notice] = "Your dispatch is currently sending."
    redirect_to forge_dispatches_path
  end
end

#showObject



23
24
25
# File 'lib/forge/app/controllers/forge/dispatches_controller.rb', line 23

def show
  @dispatch = Dispatch.find(params[:id], :include => [:messages, :queued_messages, :opens, :sent_messages, :failed_messages])
end

#test_sendObject



72
73
74
75
76
# File 'lib/forge/app/controllers/forge/dispatches_controller.rb', line 72

def test_send
  DispatchMailer.dispatch(@dispatch, params[:test_send_email], "Admin", current_user.id).deliver
  flash[:notice] = "A copy of the dispatch was sent to #{params[:test_send_email]}."
  redirect_to queue_forge_dispatch_path(@dispatch)
end

#unsubscribesObject



39
40
41
# File 'lib/forge/app/controllers/forge/dispatches_controller.rb', line 39

def unsubscribes
  @unsubscribes = @dispatch.unsubscribes.paginate(:per_page => 15, :page => params[:page])
end

#updateObject



53
54
55
56
57
58
59
60
# File 'lib/forge/app/controllers/forge/dispatches_controller.rb', line 53

def update
  if @dispatch.update_attributes(params[:dispatch])
    flash[:notice] = 'Dispatch was successfully updated.'
    redirect_to(forge_dispatches_path)
  else
    render :action => "edit"
  end
end