Class: WcoEmail::ContextsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- WcoEmail::ContextsController
- Defined in:
- app/controllers/wco_email/contexts_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #send_immediate ⇒ Object
- #send_schedule ⇒ Object
- #show ⇒ Object
- #show_iframe ⇒ Object
- #summary ⇒ Object
- #update ⇒ Object
Instance Method Details
#create ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'app/controllers/wco_email/contexts_controller.rb', line 8 def create @ctx = WcoEmail::Context.new params[:context].permit! @tmpl = WcoEmail::EmailTemplate.find @ctx.email_template_id @ctx.from_email ||= @tmpl.from_email @ctx.subject ||= @tmpl.subject if params[:respond_inline] @ctx. = params[:respond_inline] end :create, @ctx if @ctx.save flash_notice 'Saved.' redirect_to action: 'show', id: @ctx.id return else flash_alert @ctx redirect_to request.referrer end end |
#destroy ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 |
# File 'app/controllers/wco_email/contexts_controller.rb', line 30 def destroy @ctx = WcoEmail::Context.find params[:id] :destroy, @ctx flag = @ctx.destroy if flag flash[:notice] = 'Destroyed the email context' else flash[:alert] = 'Could not destroy email context' end redirect_to action: :index end |
#edit ⇒ Object
42 43 44 45 |
# File 'app/controllers/wco_email/contexts_controller.rb', line 42 def edit @ctx = WcoEmail::Context.find params[:id] :edit, @ctx end |
#index ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'app/controllers/wco_email/contexts_controller.rb', line 47 def index :index, WcoEmail::Context @ctxs = WcoEmail::Context.all if params[:lead_id] @lead = Lead.find params[:lead_id] @ctxs = @ctxs.where( lead_id: @lead.id ) end if 'true' == params[:sent] @ctxs = @ctxs.where( :sent_at.ne => nil ) elsif 'false' == params[:sent] @ctxs = @ctxs.where( sent_at: nil ) # else # ## default, show notsent. # @ctxs = @ctxs.where( :sent_at.ne => nil ) end @ctxs = @ctxs.order_by( sent_at: :desc, send_at: :desc ).page( params[:ctxs_page] ).per( current_profile.per_page ) end |
#new ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 |
# File 'app/controllers/wco_email/contexts_controller.rb', line 71 def new :new, WcoEmail::Context @tmpl = @email_template = WcoEmail::EmailTemplate.where( slug: params[:template_slug] ).first || WcoEmail::EmailTemplate.where( id: params[:template_slug] ).first || WcoEmail::EmailTemplate.where({ slug: 'blank' }).last attrs = {} if @tmpl attrs = @tmpl.attributes.slice( :subject, :body, :from_email ) end @ctx = WcoEmail::Context.new({ email_template: @tmpl }.merge(attrs)) end |
#send_immediate ⇒ Object
83 84 85 86 87 88 89 90 91 92 |
# File 'app/controllers/wco_email/contexts_controller.rb', line 83 def send_immediate @ctx = WcoEmail::Context.find params[:id] :do_send, @ctx out = WcoEmail::ApplicationMailer.send_context_email( @ctx[:id].to_s ) Rails.env.production? ? out.deliver_later : out.deliver_now flash_notice 'Sent immediately.' redirect_to request.referrer end |
#send_schedule ⇒ Object
94 95 96 97 98 99 100 101 102 103 |
# File 'app/controllers/wco_email/contexts_controller.rb', line 94 def send_schedule @ctx = WcoEmail::Context.find params[:id] :do_send, @ctx flash[:notice] = 'Scheduled a single send - v2' @ctx.send_at = Time.now @ctx.save redirect_to action: 'index' end |
#show ⇒ Object
105 106 107 108 |
# File 'app/controllers/wco_email/contexts_controller.rb', line 105 def show @ctx = @email_context = WcoEmail::Context.find( params[:id] ) :show, @ctx end |
#show_iframe ⇒ Object
110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'app/controllers/wco_email/contexts_controller.rb', line 110 def show_iframe @ctx = @email_context = WcoEmail::Context.find params[:id] :iframe_src, @ctx @tmpl = @email_template = @ctx.email_template @tmpl_config = OpenStruct.new JSON.parse( @ctx.tmpl[:config_json] ) @lead = @ctx.lead @body = @ctx.body @renderer = WcoEmail::ApplicationMailer.renderer ctx: @ctx render layout: false end |
#summary ⇒ Object
124 125 126 127 128 129 130 131 132 133 134 |
# File 'app/controllers/wco_email/contexts_controller.rb', line 124 def summary :summary, WcoEmail::Context @results = WcoEmail::Context.summary respond_to do |format| format.html format.csv do render layout: false end end end |
#update ⇒ Object
136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'app/controllers/wco_email/contexts_controller.rb', line 136 def update @ctx = WcoEmail::Context.find params[:id] :update, @ctx if @ctx.update_attributes params[:context].permit! flash[:notice] = 'Saved.' redirect_to action: 'edit', id: @ctx.id return else flash[:alert] = "Could not save: #{@ctx.errors..join(', ')}" render action: :edit return end end |