Module: Redde::AdminHelper
- Included in:
- Admin::BaseController
- Defined in:
- app/helpers/redde/admin_helper.rb
Instance Method Summary collapse
- #command_link(name, action, confirm = nil) ⇒ Object
- #page_header(item = nil, &block) ⇒ Object
- #page_sidebar(title = nil, &block) ⇒ Object
- #redde_file_field_tag(name, options = {}) ⇒ Object
- #redde_flash ⇒ Object
- #redde_page(&block) ⇒ Object
- #redde_tree(collection, opts = {}, &block) ⇒ Object
- #redde_tree_list(collection, &block) ⇒ Object
- #sidebar_link(title, path = [], additional_names = []) ⇒ Object
- #taccusative(model_name) ⇒ Object
- #tplural(model) ⇒ Object
- #tsingular(model) ⇒ Object
Instance Method Details
#command_link(name, action, confirm = nil) ⇒ Object
64 65 66 67 68 |
# File 'app/helpers/redde/admin_helper.rb', line 64 def command_link(name, action, confirm = nil) = { method: :put } [:data] = { confirm: confirm } if confirm.present? link_to name, admin_system_command_path(action), end |
#page_header(item = nil, &block) ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'app/helpers/redde/admin_helper.rb', line 26 def page_header(item = nil, &block) if block_given? content_for(:page_header, content_tag(:div, capture(&block), class: 'page-header')) elsif action_name == 'index' content_for(:page_header, content_tag(:div, render('admin/redde/page_header'), class: 'page-header')) else content_for(:page_header, content_tag(:div, render('admin/redde/page_header_edit', item: instance_variable_get("@#{record}")), class: 'page-header')) end end |
#page_sidebar(title = nil, &block) ⇒ Object
19 20 21 22 23 24 |
# File 'app/helpers/redde/admin_helper.rb', line 19 def title = nil, &block content_for :page_sidebar do concat content_tag(:div, title, class: 'page-sidebar__title') if title concat capture(&block) end end |
#redde_file_field_tag(name, options = {}) ⇒ Object
4 5 6 7 8 9 10 |
# File 'app/helpers/redde/admin_helper.rb', line 4 def redde_file_field_tag name, = {} content_tag(:span, class: ['redde-form__file rfile jsr-file', [:class]]) do concat content_tag :span, raw('Загрузить') + content_tag(:span, file_field_tag(name, .merge(class: 'rfile__inp')), class: 'rfile__wrap jsr-file--wrap'), class: 'rfile__btn btn icon-upload' concat content_tag(:span, '', class: 'rfile__name jsr-file--name') concat content_tag(:span, raw(' '), title: 'удалить', class: 'rfile__del jsr-file--del', hidden: "") end end |
#redde_flash ⇒ Object
12 13 14 15 16 17 |
# File 'app/helpers/redde/admin_helper.rb', line 12 def redde_flash msg = "".html_safe msg.concat content_tag(:div, flash[:notice], class: 'flash-msg _notice') if flash[:notice].present? msg.concat content_tag(:div, flash[:alert], class: 'flash-msg _alert') if flash[:alert].present? msg end |
#redde_page(&block) ⇒ Object
36 37 38 39 40 41 42 43 44 |
# File 'app/helpers/redde/admin_helper.rb', line 36 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 render('admin/redde_photos/photos', parent: item) if item.class.reflect_on_association(:photos) end end |
#redde_tree(collection, opts = {}, &block) ⇒ Object
46 47 48 49 50 |
# File 'app/helpers/redde/admin_helper.rb', line 46 def redde_tree collection, opts = {}, &block content_tag :ol, class: 'sort-tree', 'data-sort-tree' => opts.to_json do redde_tree_list collection, &block end end |
#redde_tree_list(collection, &block) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 |
# File 'app/helpers/redde/admin_helper.rb', line 52 def redde_tree_list collection, &block collection.each do |item| controls = content_tag(: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 = content_tag :div, (block_given? ? capture(item, &block) : link).concat(controls), class: 'sort-tree__wrap', 'data-sort-tree-tolerance' => "" html << content_tag(:ol) do redde_tree_list(item.children.order(:position), &block) end if item.has_children? concat content_tag(:li, html, class: 'sort-tree__item', 'data-sort-tree-item' => "", id: "list_#{item.id}") end end |
#sidebar_link(title, path = [], additional_names = []) ⇒ Object
70 71 72 73 74 75 76 77 |
# File 'app/helpers/redde/admin_helper.rb', line 70 def (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
83 84 85 |
# File 'app/helpers/redde/admin_helper.rb', line 83 def taccusative(model_name) t("activerecord.models.#{model_name}.acc") end |
#tplural(model) ⇒ Object
87 88 89 |
# File 'app/helpers/redde/admin_helper.rb', line 87 def tplural(model) model.model_name.human(count: 'other') end |
#tsingular(model) ⇒ Object
79 80 81 |
# File 'app/helpers/redde/admin_helper.rb', line 79 def tsingular(model) model.model_name.human end |