Sha256: ec3741e14dbde62f60d9dfc4dc680ac4f5050e53ac6d16c0fe63a5c8e17dd83c

Contents?: true

Size: 1.86 KB

Versions: 8

Compression:

Stored size: 1.86 KB

Contents

class Admin::MessagesController < Admin::ResourceController
  helper :reader
  skip_before_filter :load_model
  before_filter :load_model, :except => :index    # we want the filter to run before :show too
  before_filter :set_function, :only => :new
  before_filter :get_group, :only => :new

  # here :show is the preview/send page
  # continue_url is extended below to redirect to show rather than index after editing.
  def show
    
  end
  
  # mock email view called into an iframe in the :show view
  # the view calls @message.preview, which returns the message body
  def preview
    render :layout => false
  end

  def deliver
    case params['delivery']
    when "all"
      @readers = @message.possible_readers
    when "inactive"
      @readers = @message.inactive_readers
    when "unsent"
      @readers = @message.undelivered_readers
    when "selected"
      @readers = @message.possible_readers.find(params['recipients'])
    else
      redirect_to admin_message_url(@message)
      return
    end
    failures = @message.deliver(@readers) || []
    if failures.any?
      if failures.length == @readers.length
        flash[:error] = t("reader_extension.all_deliveries_failed")
      else
        addresses = failures.map(&:email).to_sentence
        flash[:notice] = t("reader_extension.some_deliveries_failed")
      end
    else
      flash[:notice] = t("reader_extension.message_delivered")
    end
    redirect_to admin_message_url(@message)
  end

protected

  def continue_url(options)
    if action_name == "destroy"
      redirect_to :back
    else
      options[:redirect_to] || (params[:continue] ? {:action => 'edit', :id => model.id} : admin_message_url(model))
    end
  end

  def set_function
    if params[:function]
      model.function_id = params[:function]
    end
  end
  
  def get_group
    @group = Group.find(params[:group_id]) if params[:group_id]
  end

end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
radiant-reader-extension-3.0.38 app/controllers/admin/messages_controller.rb
radiant-reader-extension-3.0.37 app/controllers/admin/messages_controller.rb
radiant-reader-extension-3.0.36 app/controllers/admin/messages_controller.rb
radiant-reader-extension-3.0.35 app/controllers/admin/messages_controller.rb
radiant-reader-extension-3.0.33 app/controllers/admin/messages_controller.rb
radiant-reader-extension-3.0.32 app/controllers/admin/messages_controller.rb
radiant-reader-extension-3.0.31 app/controllers/admin/messages_controller.rb
radiant-reader-extension-3.0.30 app/controllers/admin/messages_controller.rb