Module: Cdx::Admin::ResourceHelper

Defined in:
app/helpers/cdx/admin/resource_helper.rb

Instance Method Summary collapse

Instance Method Details

#content_header_page_titleObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'app/helpers/cdx/admin/resource_helper.rb', line 4

def content_header_page_title
  # Work arround with Ransack issue, where all helpers are available
  # even with our initializer : include_all_helpers = false
  if @object && try(:member_action?)
    # TODO : Parent data ?
    if member_action? && @object.persisted?
      "#{t("activerecord.models.#{@resource.model_class.model_name.to_s.underscore}.one")} : #{@object.content_header_title}"
    else
      t("activerecord.models.#{@resource.model_class.model_name.to_s.underscore}.other")
    end
  else

    t("admin.content_header.page_title.#{context_tag}")
  end
end


58
59
60
61
62
63
64
65
66
67
# File 'app/helpers/cdx/admin/resource_helper.rb', line 58

def link_to_delete(resource, options = {})
  if can? :destroy, resource
    url                      = options[:url] || object_url(resource)
    options[:class]          = %w(btn-sm btn-danger)
    options[:data]           ||= {}
    options[:data][:method]  ||= :delete
    options[:data][:confirm] ||= resource&.content_header_title ? t('admin.ujs_confirm.delete', o: resource.content_header_title) : t('admin.ujs_confirm.default')
    link_to fa_icon(:trash), url, options
  end
end


50
51
52
53
54
55
56
# File 'app/helpers/cdx/admin/resource_helper.rb', line 50

def link_to_edit(resource, options = {})
  if can? :edit, resource
    url             = options[:url] || edit_object_url(resource)
    options[:class] = 'btn-sm btn-info'
    link_to fa_icon(:pencil), url, options
  end
end


32
33
34
35
36
37
38
39
40
# File 'app/helpers/cdx/admin/resource_helper.rb', line 32

def link_to_new(options = {})
  if can? :new, @object.class
    url = options[:url] || new_object_url
    options[:class] = 'btn-sm btn-info pull-right'
    link_to url, options do
      fa_icon(:plus) + ' ' + t('admin.actions.new')
    end
  end
end


69
70
71
72
73
74
75
# File 'app/helpers/cdx/admin/resource_helper.rb', line 69

def link_to_return(options = {})
  if can? :index, @object.class
    url             = options[:url] || collection_url
    options[:class] = %w(btn btn-default)
    link_to t('admin.actions.return'), url, options
  end
end


42
43
44
45
46
47
48
# File 'app/helpers/cdx/admin/resource_helper.rb', line 42

def link_to_show(resource, options = {})
  if can? :show, resource
    url             = options[:url] || object_url(resource)
    options[:class] = 'btn-sm btn-success'
    link_to fa_icon(:eye), url, options
  end
end

#render_content_header_breadcrumbObject



20
21
22
23
24
25
26
27
28
29
30
# File 'app/helpers/cdx/admin/resource_helper.rb', line 20

def render_content_header_breadcrumb
  content_for :content_header_breadcrumb do
    if @parent
      concat tag.li link_to(@parent.model_name.human.pluralize, parent_collection_url)
      concat tag.li link_to(@parent.content_header_title, edit_parent_object_url)
    end
    concat tag.li link_to(@resource.model_class.model_name.human.pluralize, collection_url)
    concat tag.li link_to(@object.content_header_title, edit_object_url(@object)) if (member_action? && @object.persisted?)
    concat tag.li t("admin.content_header.page_title.actions.#{action_name}")
  end
end