Module: Admin::BaseHelper

Includes:
ActionView::Helpers::DateHelper
Defined in:
app/helpers/admin/base_helper.rb

Instance Method Summary collapse

Instance Method Details

#button_to_delete(item) ⇒ Object



59
60
61
62
63
64
65
66
# File 'app/helpers/admin/base_helper.rb', line 59

def button_to_delete(item)
  confirm_text = t("admin.shared.destroy.are_you_sure",
                   element: item.class.model_name.human.downcase)
  link_to(t("generic.delete"),
          { action: "destroy", id: item.id },
          { class: "btn btn-danger btn-xs btn-action", method: :delete,
            data: { confirm: confirm_text } })
end

#button_to_edit(item) ⇒ Object



53
54
55
56
57
# File 'app/helpers/admin/base_helper.rb', line 53

def button_to_edit(item)
  link_to(t("generic.edit"),
          { action: "edit", id: item.id },
          { class: "btn btn-primary btn-xs btn-action" })
end

#button_to_short_url(item) ⇒ Object



68
69
70
71
72
73
# File 'app/helpers/admin/base_helper.rb', line 68

def button_to_short_url(item)
  return "" if item.short_url.nil?

  link_to(t("generic.short_url"), item.short_url,
          class: "btn btn-success btn-xs btn-action")
end

#class_for_admin_state(sidebar, this_position) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/helpers/admin/base_helper.rb', line 10

def class_for_admin_state(sidebar, this_position)
  case sidebar.admin_state
  when :active
    "active alert-info"
  when :will_change_position
    if this_position == sidebar.active_position
      "will_change ghost"
    else
      "will_change alert-warning"
    end
  else
    raise sidebar.admin_state.inspect
  end
end

#display_pagination(collection, cols, _first = "", _last = "") ⇒ Object



45
46
47
48
49
50
51
# File 'app/helpers/admin/base_helper.rb', line 45

def display_pagination(collection, cols, _first = "", _last = "")
  return if collection.count == 0

  tag.tr do
    tag.td(paginate(collection), class: "paginate", colspan: cols)
  end
end


79
80
81
82
83
84
85
# File 'app/helpers/admin/base_helper.rb', line 79

def menu_item(name, url)
  if current_page? url
    tag.li(link_to(name, "#"), class: "active")
  else
    tag.li(link_to(name, url))
  end
end

#plugin_options(kind) ⇒ Object



31
32
33
34
35
# File 'app/helpers/admin/base_helper.rb', line 31

def plugin_options(kind)
  PublifyPlugins::Keeper.available_plugins(kind).map do |plugin|
    [plugin.name, plugin.to_s]
  end
end

#show_actions(item) ⇒ Object



37
38
39
40
41
42
43
# File 'app/helpers/admin/base_helper.rb', line 37

def show_actions(item)
  tag.div(class: "action", style: "") do
    safe_join [button_to_edit(item),
               button_to_delete(item),
               button_to_short_url(item)], " "
  end
end

#text_filter_optionsObject



25
26
27
28
29
# File 'app/helpers/admin/base_helper.rb', line 25

def text_filter_options
  TextFilter.all.map do |filter|
    [filter.description, filter.name]
  end
end

#toggle_element(element, label = t("generic.change")) ⇒ Object



6
7
8
# File 'app/helpers/admin/base_helper.rb', line 6

def toggle_element(element, label = t("generic.change"))
  link_to label, "##{element}", data: { toggle: :collapse }
end

#twitter_available?(blog, user) ⇒ Boolean

Returns:

  • (Boolean)


75
76
77
# File 'app/helpers/admin/base_helper.rb', line 75

def twitter_available?(blog, user)
  blog.has_twitter_configured? && user.has_twitter_configured?
end