Class: MailEngine::MailSchedulesController

Inherits:
ApplicationController show all
Defined in:
app/controllers/mail_engine/mail_schedules_controller.rb

Constant Summary

Constants included from MailEngine

PLACEHOLDERS_IN_LAYOUT, VERSION

Instance Method Summary collapse

Methods inherited from ApplicationController

#close_modal_and_refresh

Instance Method Details

#createObject



19
20
21
22
23
24
25
26
27
# File 'app/controllers/mail_engine/mail_schedules_controller.rb', line 19

def create
  @mail_schedule = MailSchedule.new(params[:mail_engine_mail_schedule].merge(:payload => params[:mail_engine_mail_schedule][:payload].try(:join, ',')))

  if @mail_schedule.save
    redirect_to mail_schedule_path(@mail_schedule), :notice => 'Mail schedule was successfully created.'
  else
    render "new"
  end
end

#destroyObject



14
15
16
17
# File 'app/controllers/mail_engine/mail_schedules_controller.rb', line 14

def destroy
  @mail_schedule.destroy
  redirect_to mail_schedules_path
end

#editObject



11
12
# File 'app/controllers/mail_engine/mail_schedules_controller.rb', line 11

def edit
end

#indexObject



4
5
6
# File 'app/controllers/mail_engine/mail_schedules_controller.rb', line 4

def index
  @mail_schedules = MailSchedule.order("created_at desc").page(params[:page]).per(20)
end

#newObject



29
30
31
32
33
34
35
# File 'app/controllers/mail_engine/mail_schedules_controller.rb', line 29

def new
  if MailTemplate.for_marketing.count == 0
    flash[:notice] = "Add Marketing mail template first."
    redirect_to :action => :index
  end
  @mail_schedule = MailSchedule.new
end

#send_test_mailObject



45
46
47
48
49
50
# File 'app/controllers/mail_engine/mail_schedules_controller.rb', line 45

def send_test_mail
  @mail_schedule.send_test_mail_to!(params[:recipient], params[:sample_user_id])
  render :js => %Q{alert("Test Mail sent to #{params[:recipient]}"); $('#recipient').val('');}
rescue => e
  render :js => %Q{alert("Test Mail failed to send to #{params[:recipient]}, due to #{e.to_s.gsub(/\n/, '')}"); $('#recipient').val('');}
end

#showObject



8
9
# File 'app/controllers/mail_engine/mail_schedules_controller.rb', line 8

def show
end

#startObject



52
53
54
55
56
57
58
# File 'app/controllers/mail_engine/mail_schedules_controller.rb', line 52

def start
  if @mail_schedule.update_attribute :available, true
    render :js => %Q{alert('Start schedule successfully.'); showStopScheduleButton(#{@mail_schedule.id});}
  else
    render :js => %Q{alert('Failed to start schedule.')}
  end
end

#stopObject



60
61
62
63
64
65
66
# File 'app/controllers/mail_engine/mail_schedules_controller.rb', line 60

def stop
  if @mail_schedule.update_attribute :available, false
    render :js => %Q{alert('Stop schedule successfully.'); showStartScheduleButton(#{@mail_schedule.id});}
  else
    render :js => %Q{alert('Failed to stop schedule.')}
  end
end

#updateObject



37
38
39
40
41
42
43
# File 'app/controllers/mail_engine/mail_schedules_controller.rb', line 37

def update
  if @mail_schedule.update_attributes(params[:mail_engine_mail_schedule].merge(:payload => params[:mail_engine_mail_schedule][:payload].join(',')))
    redirect_to mail_schedule_path(@mail_schedule), :notice => 'Mail schedule was successfully updated.'
  else
    render "new"
  end
end