Sha256: 17af3ddd64f9b1100272324a6a1038376a1e8c99df34ec698ed0d796a837a04f

Contents?: true

Size: 1.87 KB

Versions: 26

Compression:

Stored size: 1.87 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
    model.group = Group.find(params[:group_id]) if params[:group_id]
  end

end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
radiant-reader-extension-3.0.29 app/controllers/admin/messages_controller.rb
radiant-reader-extension-3.0.28 app/controllers/admin/messages_controller.rb
radiant-reader-extension-3.0.27 app/controllers/admin/messages_controller.rb
radiant-reader-extension-3.0.26 app/controllers/admin/messages_controller.rb
radiant-reader-extension-3.0.25 app/controllers/admin/messages_controller.rb
radiant-reader-extension-3.0.24 app/controllers/admin/messages_controller.rb
radiant-reader-extension-3.0.23 app/controllers/admin/messages_controller.rb
radiant-reader-extension-3.0.20 app/controllers/admin/messages_controller.rb
radiant-reader-extension-3.0.19 app/controllers/admin/messages_controller.rb
radiant-reader-extension-3.0.18 app/controllers/admin/messages_controller.rb
radiant-reader-extension-3.0.17 app/controllers/admin/messages_controller.rb
radiant-reader-extension-3.0.16 app/controllers/admin/messages_controller.rb
radiant-reader-extension-3.0.15 app/controllers/admin/messages_controller.rb
radiant-reader-extension-3.0.14 app/controllers/admin/messages_controller.rb
radiant-reader-extension-3.0.13 app/controllers/admin/messages_controller.rb
radiant-reader-extension-3.0.11 app/controllers/admin/messages_controller.rb
radiant-reader-extension-3.0.10 app/controllers/admin/messages_controller.rb
radiant-reader-extension-3.0.9 app/controllers/admin/messages_controller.rb
radiant-reader-extension-3.0.8 app/controllers/admin/messages_controller.rb
radiant-reader-extension-3.0.7 app/controllers/admin/messages_controller.rb