Module: ActiveRecord::AdminpanelExtension::ClassMethods
- Defined in:
- lib/adminpanel/active_record/adminpanel_extension.rb
Overview
static(class) methods
Instance Method Summary collapse
- #belongs_to_relationships ⇒ Object
- #display_attributes ⇒ Object
- #display_name ⇒ Object
- #form_attributes ⇒ Object
- #get_attribute_label(field) ⇒ Object
- #get_attribute_name(field) ⇒ Object
- #get_attribute_placeholder(field) ⇒ Object
- #get_image_relationship ⇒ Object
- #has_images? ⇒ Boolean
- #has_many_relationships ⇒ Object
- #icon ⇒ Object
- #mount_images(relation) ⇒ Object
Instance Method Details
#belongs_to_relationships ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/adminpanel/active_record/adminpanel_extension.rb', line 98 def belongs_to_relationships belongs_to_classes = [] form_attributes.each do |fields| fields.each do |attribute, properties| if properties["type"] == "belongs_to" belongs_to_classes << properties["model"].classify.constantize end end end return belongs_to_classes end |
#display_attributes ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/adminpanel/active_record/adminpanel_extension.rb', line 63 def display_attributes display_attributes = [] form_attributes.each do |attribute| attribute.each do |name, properties| if properties["show"].nil? || properties["show"] == "true" display_attributes << attribute end end end return display_attributes end |
#display_name ⇒ Object
26 27 28 |
# File 'lib/adminpanel/active_record/adminpanel_extension.rb', line 26 def display_name "display_name" end |
#form_attributes ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/adminpanel/active_record/adminpanel_extension.rb', line 17 def form_attributes [{ "name" => { "type" => "text_field", "label" => "name" } }] end |
#get_attribute_label(field) ⇒ Object
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/adminpanel/active_record/adminpanel_extension.rb', line 41 def get_attribute_label(field) form_attributes.each do |attribute| attribute.each do |name, properties| if name == field return properties["label"] end end end return ":(" end |
#get_attribute_name(field) ⇒ Object
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/adminpanel/active_record/adminpanel_extension.rb', line 30 def get_attribute_name(field) form_attributes.each do |attribute| attribute.each do |name, properties| if name == field return properties["label"] end end end return ":(" end |
#get_attribute_placeholder(field) ⇒ Object
52 53 54 55 56 57 58 59 60 61 |
# File 'lib/adminpanel/active_record/adminpanel_extension.rb', line 52 def get_attribute_placeholder(field) form_attributes.each do |attribute| attribute.each do |name, properties| if name == field return properties["placeholder"] end end end return ":(" end |
#get_image_relationship ⇒ Object
87 88 89 90 91 92 93 94 95 96 |
# File 'lib/adminpanel/active_record/adminpanel_extension.rb', line 87 def get_image_relationship form_attributes.each do |fields| fields.each do |attribute, properties| if properties["type"] == "adminpanel_file_field" return attribute end end end return false end |
#has_images? ⇒ Boolean
76 77 78 79 80 81 82 83 84 85 |
# File 'lib/adminpanel/active_record/adminpanel_extension.rb', line 76 def has_images? form_attributes.each do |fields| fields.each do |attribute, properties| if properties["type"] == "adminpanel_file_field" return true end end end return false end |
#has_many_relationships ⇒ Object
110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/adminpanel/active_record/adminpanel_extension.rb', line 110 def has_many_relationships has_many_classes = [] form_attributes.each do |fields| fields.each do |attribute, properties| if properties["type"] == "has_many" has_many_classes << properties["model"].classify.constantize end end end return has_many_classes end |
#icon ⇒ Object
122 123 124 |
# File 'lib/adminpanel/active_record/adminpanel_extension.rb', line 122 def icon "icon-truck" end |
#mount_images(relation) ⇒ Object
12 13 14 15 |
# File 'lib/adminpanel/active_record/adminpanel_extension.rb', line 12 def mount_images(relation) has_many relation, :dependent => :destroy accepts_nested_attributes_for relation, :allow_destroy => true end |