Module: Redde::AdminHelper

Included in:
Admin::BaseController
Defined in:
app/helpers/redde/admin_helper.rb

Instance Method Summary collapse

Instance Method Details



49
50
51
52
53
# File 'app/helpers/redde/admin_helper.rb', line 49

def command_link(name, action, confirm = nil)
  options = { method: :put }
  options[:data] = { confirm: confirm } if confirm.present?
  link_to name, admin_system_command_path(action), options
end

#page_header(item = nil, &block) ⇒ Object



11
12
13
14
15
16
17
18
19
# File 'app/helpers/redde/admin_helper.rb', line 11

def page_header(item = nil, &block)
  if block_given?
    content_for(:page_header, (:div, capture(&block), class: 'page-header'))
  elsif action_name == 'index'
    content_for(:page_header, (:div, render('admin/redde/page_header'), class: 'page-header'))
  else
    content_for(:page_header, (:div, render('admin/redde/page_header_edit', item: instance_variable_get("@#{record}")), class: 'page-header'))
  end
end

#page_sidebar(title = nil, &block) ⇒ Object



4
5
6
7
8
9
# File 'app/helpers/redde/admin_helper.rb', line 4

def page_sidebar title = nil, &block
  content_for :page_sidebar do
    concat (:div, title, class: 'page-sidebar__title') if title
    concat capture(&block)
  end
end

#photoable(parent) ⇒ Object



64
65
66
# File 'app/helpers/redde/admin_helper.rb', line 64

def photoable(parent)
  render('admin/redde_photos/photos', parent: parent) if parent.class.reflect_on_association(:photos)
end

#redde_page(&block) ⇒ Object



21
22
23
24
25
26
27
28
29
# File 'app/helpers/redde/admin_helper.rb', line 21

def redde_page(&block)
  item = instance_variable_get("@#{record}")

  capture do
    concat page_header
    concat redde_form_for([:admin, item]) { |f| capture(f, &block) }
    concat photoable(item)
  end
end

#redde_tree(collection, opts = {}, &block) ⇒ Object



31
32
33
34
35
# File 'app/helpers/redde/admin_helper.rb', line 31

def redde_tree collection, opts = {}, &block
   :ol, class: 'sort-tree', 'data-sort-tree' => opts.to_json do
    redde_tree_list collection, &block
  end
end

#redde_tree_list(collection, &block) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
# File 'app/helpers/redde/admin_helper.rb', line 37

def redde_tree_list collection, &block
  collection.each do |item|
    controls = (:div, link_to('Удал', url_for(action: :show, id: item), class: 'a_del sort-tree__btn', data: { confirm: 'Точно удалить?' }, method: 'delete'), class: 'sort-tree__controls')
    link = link_to title_for(item), url_for(action: :edit, id: item), class: 'sort-tree__link'
    html =  :div, (block_given? ? capture(item, &block) : link).concat(controls), class: 'sort-tree__wrap', 'data-sort-tree-tolerance' => ""
    html << (:ol) do
      redde_tree_list(item.children.order(:position), &block)
    end if item.has_children?
    concat (:li, html, class: 'sort-tree__item', 'data-sort-tree-item' => "", id: "list_#{item.id}")
  end
end


55
56
57
58
59
60
61
62
# File 'app/helpers/redde/admin_helper.rb', line 55

def sidebar_link(title, path = [], additional_names = [])
  additional_names = [additional_names] unless additional_names.is_a?(Array)
  active_names = additional_names + [path.try(:last) || '']
  active_names.map!(&:to_s)
  classes = ['sidebar__link']
  classes << '_active' if active_names.include?(controller_name)
  link_to title, path, class: classes
end

#taccusative(model_name) ⇒ Object



72
73
74
# File 'app/helpers/redde/admin_helper.rb', line 72

def taccusative(model_name)
  t("activerecord.models.#{model_name}.acc")
end

#tplural(model) ⇒ Object



76
77
78
# File 'app/helpers/redde/admin_helper.rb', line 76

def tplural(model)
  model.model_name.human(count: 'other')
end

#tsingular(model) ⇒ Object



68
69
70
# File 'app/helpers/redde/admin_helper.rb', line 68

def tsingular(model)
  model.model_name.human
end