Module: Adminpanel::SharedPagesHelper

Included in:
ApplicationHelper
Defined in:
app/helpers/adminpanel/shared_pages_helper.rb

Instance Method Summary collapse

Instance Method Details

#active_tab(index) ⇒ Object



32
33
34
35
36
37
38
# File 'app/helpers/adminpanel/shared_pages_helper.rb', line 32

def active_tab(index)
  if index == 0
    return 'active'
  else
    return ''
  end
end

#belong_to_object_name(resource, belongs_to_assoc_name) ⇒ Object

Searches for current controller’s Class (@model) associaciations and execute the association method on the model, It’s going to return ‘name’ of the related object if it exists. E.x. Given a Prodcuct that belongs_to category, this method is going to search for a relationship named ‘category’



8
9
10
11
12
13
14
# File 'app/helpers/adminpanel/shared_pages_helper.rb', line 8

def belong_to_object_name(resource, belongs_to_assoc_name)
  if !resource.send(belongs_to_assoc_name).nil? #if there's something in the association
    return resource.send(belongs_to_assoc_name).name
  else
    return "#{belongs_to_assoc_name} N/A"
  end
end

#class_name_downcase(object) ⇒ Object



24
25
26
# File 'app/helpers/adminpanel/shared_pages_helper.rb', line 24

def class_name_downcase(object)
  demodulize_class(object.class)
end

#demodulize_class(class_name) ⇒ Object



28
29
30
# File 'app/helpers/adminpanel/shared_pages_helper.rb', line 28

def demodulize_class(class_name)
  class_name.to_s.demodulize.downcase
end

#field_value(properties, attribute, object) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'app/helpers/adminpanel/shared_pages_helper.rb', line 53

def field_value properties, attribute, object
  case properties['type']
  when 'belongs_to'
    belong_to_object_name(object, attribute.split('_id').first)
  when 'has_many'
    li_tags = ""
     :ul do
      object.send("#{pluralize_model(properties['model'])}").each do |member|
        li_tags << (:li, class: 'priority-low') do
          member.name
        end
      end
      li_tags.html_safe
    end
  when 'file_field'
     :ul do
      image_tag(object.send("#{attribute}_url", :thumb))
    end
  when 'boolean'
    if object.send(attribute)
      I18n.t('action.is_true')
    else
      I18n.t('action.is_false')
    end
  when 'enum_field'
    I18n.t("#{object.class.name.demodulize.downcase}.#{object.send(attribute)}")
  else
    object.send(attribute)
  end
end


40
41
42
43
44
45
46
47
48
49
50
51
# File 'app/helpers/adminpanel/shared_pages_helper.rb', line 40

def get_oauth_link(resource)
  Koala::Facebook::OAuth.new(
    Adminpanel.fb_app_id,
    Adminpanel.fb_app_secret,
    url_for({
      controller: params[:controller],
      action: 'fb_choose_page',
      id: resource,
      host: request.host
    })
  ).url_for_oauth_code
end

#is_customized_field?(field_name) ⇒ Boolean

Returns:

  • (Boolean)


84
85
86
87
88
89
90
91
# File 'app/helpers/adminpanel/shared_pages_helper.rb', line 84

def is_customized_field?(field_name)
  field_name = field_name.to_sym
  return (field_name == :adminpanel_file_field ||
    field_name == :belongs_to ||
    field_name == :file_field ||
    field_name == :non_image_file_field ||
    field_name == :has_many)
end

#pluralize_model(class_name) ⇒ Object



16
17
18
# File 'app/helpers/adminpanel/shared_pages_helper.rb', line 16

def pluralize_model(class_name)
  "#{demodulize_class(class_name).pluralize}"
end

#relationship_ids(class_string) ⇒ Object



20
21
22
# File 'app/helpers/adminpanel/shared_pages_helper.rb', line 20

def relationship_ids(class_string)
  "#{demodulize_class(class_string)}_ids"
end

#table_type(model) ⇒ Object



93
94
95
96
97
98
99
# File 'app/helpers/adminpanel/shared_pages_helper.rb', line 93

def table_type(model)
  if model.is_sortable?
    'sortable'
  else
    'information-table'
  end
end