Module: Adminpanel::SharedPagesHelper
- Included in:
- ApplicationHelper
- Defined in:
- app/helpers/adminpanel/shared_pages_helper.rb
Instance Method Summary collapse
- #active_tab(index) ⇒ Object
-
#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.
- #class_name_downcase(object) ⇒ Object
- #demodulize_class(class_name) ⇒ Object
- #field_value(attr_type, attribute, object) ⇒ Object
- #get_oauth_link(resource) ⇒ Object
- #is_customized_field?(field_name) ⇒ Boolean
- #pluralize_model(class_name) ⇒ Object
- #relationship_ids(class_string) ⇒ Object
- #table_type(model) ⇒ Object
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(attr_type, 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 83 84 85 86 87 88 |
# File 'app/helpers/adminpanel/shared_pages_helper.rb', line 53 def field_value(attr_type, attribute, object) case attr_type when 'select' belong_to_object_name(object, attribute.gsub('_id', '')) when 'checkbox' = "" content_tag :ul do object.send(attribute.gsub('_ids', '').pluralize).each do |member| << content_tag(:li, class: 'priority-low') do member.name end end .html_safe end when 'file_field' link_to(object[attribute], object.try(:send, "#{attribute}_url")) unless object[attribute].nil? when 'image_field' content_tag :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)}") when 'adminpanel_file_field' object.send(attribute).count when 'wysiwyg_field' (object.send(attribute).to_s).truncate(120) else object.send(attribute) end end |
#get_oauth_link(resource) ⇒ Object
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
90 91 92 93 94 95 96 97 98 99 |
# File 'app/helpers/adminpanel/shared_pages_helper.rb', line 90 def is_customized_field?(field_name) field_name = field_name.to_sym [ :adminpanel_file_field, :file_field, :non_image_file_field, :checkbox, :select ].include? field_name 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
101 102 103 104 105 106 107 |
# File 'app/helpers/adminpanel/shared_pages_helper.rb', line 101 def table_type(model) if model.is_sortable? 'sortable' else 'information-table' end end |