Module: Admin::ShowViewHelper

Defined in:
app/helpers/admin/show_view_helper.rb

Instance Method Summary collapse

Instance Method Details

#build_action_buttonsObject



24
25
26
27
28
29
30
31
# File 'app/helpers/admin/show_view_helper.rb', line 24

def build_action_buttons
  edit_btn = Array(decorate.class.permitted_instance_methods_for(action_name)).collect { |action|
    render_to_string("actions/#{action}", locals: {record: decorate.object}, layout: false)
  }.join("\n").html_safe

  # edit_btn = link_to t('actions.edit'), [scope, record, action: 'edit'], class: 'btn btn-primary'
  (:div, edit_btn, class: 'pull-right')
end

#build_fields_for(decorator, fields) ⇒ Object



33
34
35
36
37
38
39
40
41
42
# File 'app/helpers/admin/show_view_helper.rb', line 33

def build_fields_for(decorator, fields)
  (:div, class: 'row detail-info clearfix') do
    (:ul, class: 'col-sm-12 col-md-12 list-unstyled') do
      fields.each do |field_name|
        options = decorator.try(:attribute_type_for, field_name, true) || {}
        concat(render_view(field_name, options))
      end
    end
  end
end

#build_view_for(attribute_name) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'app/helpers/admin/show_view_helper.rb', line 5

def build_view_for(attribute_name)
  fields_hash = decorator.try(attribute_name) || {}
  profiles = fields_hash.fetch(:profiles, [])

  form_fields = if profiles.present?
                  profiles.collect { |profile|
                    fields = fields_hash.fetch(profile.to_sym, {})
                    content = []
                    content << (:h3, I18n.t("profiles.#{profile}", default: profile), class: 'lead clearfix')
                    content << build_fields_for(decorator, fields)
                    content.join.html_safe
                  }.join.html_safe
                else
                  build_fields_for(decorator, fields_hash)
                end

  [build_action_buttons, form_fields].join.html_safe
end

#field_wrapper(method, options = {}, &block) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'app/helpers/admin/show_view_helper.rb', line 50

def field_wrapper(method, options = {}, &block)
  label_options = options.extract!(:label_class, :required, :block)
  is_block = label_options[:block]
  options[:class] ||= 'form-control'
  options.merge!(id: '_form_id_'.concat(method))

  (:li, class: is_block ? 'col-sm-12 col-md-12' : 'col-sm-6 col-md-6') do
    content = [(:b, [model.human_attribute_name(method), ":"].join, default: method)]
    if is_block
      content << (:p, yield(block))
    else
      content << (:span, yield(block))
    end
    content.join.html_safe
  end

end

#render_view(method, options = {}) ⇒ Object



44
45
46
47
48
# File 'app/helpers/admin/show_view_helper.rb', line 44

def render_view(method, options = {})
  field_wrapper(method, options) do
    decorate.human(method)
  end
end