Sha256: 89ca6a53fd7d5c115b7b44d287c0253376663d019a4337d160c2cd21db2a7afb

Contents?: true

Size: 1.7 KB

Versions: 1

Compression:

Stored size: 1.7 KB

Contents

# frozen_string_literal: true

module Admin::FeedbackHelper
  def comment_class(state)
    return "label-info" if state.to_s.casecmp("presumed_ham").zero?
    return "label-warning" if state.to_s.casecmp("presumed_spam").zero?
    return "label-success" if state.to_s.casecmp("ham").zero?

    "label-danger"
  end

  def show_feedback_actions(item, context = "listing")
    return unless can? :manage, "admin/feedback"

    safe_join [
      change_status(item, context),
      button_to_edit_comment(item),
      button_to_delete_comment(item),
      button_to_conversation(item)
    ], " "
  end

  def button_to_edit_comment(item)
    link_to(t("generic.edit"),
            { controller: "admin/feedback", action: "edit", id: item.id },
            { class: "btn btn-primary btn-xs btn-action" })
  end

  def button_to_delete_comment(item)
    link_to(t("generic.delete"),
            { controller: "admin/feedback", action: "destroy", id: item.id },
            { class: "btn btn-danger btn-xs btn-action" })
  end

  def button_to_conversation(item)
    link_to(t("generic.conversation"),
            { controller: "admin/feedback", action: "article", id: item.article_id },
            { class: "btn btn-default btn-xs btn-action" })
  end

  def change_status(item, context = "listing")
    spammy = item.state.to_s.downcase.include? "spam"
    link_text = spammy ? t("generic.mark_as_ham") : t("generic.mark_as_spam")
    button_type = spammy ? "success" : "warning"

    link_to(link_text,
            { controller: "admin/feedback", action: "change_state",
              id: item.id, context: context },
            { class: "btn btn-#{button_type} btn-xs btn-action",
              method: :post, remote: true })
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
publify_core-10.0.2 app/helpers/admin/feedback_helper.rb