Sha256: 388a0f0d1f5a04f49761c5c5044c25ab43a4545532f00870143130417320922f

Contents?: true

Size: 1.36 KB

Versions: 4

Compression:

Stored size: 1.36 KB

Contents

module Georgia
  class MessageActionsPresenter

    attr_reader :view, :message
    delegate :icon_tag, :content_tag, :link_to, :controller_name, :url_for, :main_app, :can?, :caret_tag, to: :view

    def initialize view, message
      @view = view
      @message = (message.decorated? ? message.object : message)
    end

    def to_s
      html = ActiveSupport::SafeBuffer.new
      html << content_tag(:li, link_to_print)
      if spam?
        html << content_tag(:li, link_to_ham) if can?(:ham, message)
      else
        html << content_tag(:li, link_to_spam) if can?(:spam, message)
      end
      html << content_tag(:li, link_to_trash) if can?(:destroy, message)
      html
    end

    private

    def link_to_print
      link_to "#{icon_tag('print')} Print".html_safe, "javascript:window.print()", target: '_blank'
    end

    def link_to_reply
      link_to "#{icon_tag('reply')} Reply".html_safe, "mailto:#{@message.email}", target: '_blank'
    end

    def link_to_ham
      link_to "#{icon_tag('thumbs-up')} Mark as ham".html_safe, [:ham, @message]
    end

    def link_to_spam
      link_to "#{icon_tag('thumbs-down')} Mark as spam".html_safe, [:spam, @message]
    end

    def link_to_trash
      link_to "#{icon_tag('trash-o')} Trash".html_safe, @message, method: :delete, data: {confirm: 'Are you sure?'}
    end

    def spam?
      @message.spam?
    end

  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
georgia-0.7.3 app/presenters/georgia/message_actions_presenter.rb
georgia-0.7.2 app/presenters/georgia/message_actions_presenter.rb
georgia-0.7.1 app/presenters/georgia/message_actions_presenter.rb
georgia-0.7.0 app/presenters/georgia/message_actions_presenter.rb