Class: CamaleonCms::CustomFieldGroup
- Inherits:
-
CustomField
- Object
- ActiveRecord::Base
- CamaleonRecord
- CustomField
- CamaleonCms::CustomFieldGroup
- Defined in:
- app/models/camaleon_cms/custom_field_group.rb
Instance Method Summary collapse
-
#add_fields(items, item_options) ⇒ Object
only used by form on admin panel (protected) return array of failed_fields and full_fields [[failed fields], [all fields]].
-
#add_manual_field(item, options) ⇒ Object
(also: #add_field)
add fields to group item: - sample: “slug”=>“my_slug”, “description”=>“my description (optional)” - options (textbox sample): “translate”:“1” * field_key (string) | translate (boolean) | default_value (unique value) | default_values (array - multiple values for this field) | multiple_options (array) * multiple_options (used for select, radio and checkboxes ): [Title”, “value”=>“2”, “default”=>“1”, “value”=>“3”] ****** check all options for each case in Admin::CustomFieldsHelper **** SAMPLE: my_model.add_field(Title”, “slug”=>“subtitle”, “translate”=>true, default_value: “Get in Touch”).
-
#get_caption ⇒ Object
generate the caption for this group.
-
#get_field(slug) ⇒ Object
return a field with slug = slug from current group.
Methods included from Metas
#delete_meta, #delete_option, #fix_save_metas_options_no_changed, #get_meta, #get_option, #options, #save_metas_options, #save_metas_options_skip, #set_meta, #set_metas, #set_option, #set_options
Methods inherited from CamaleonRecord
#cama_build_cache_key, #cama_fetch_cache, #cama_get_cache, #cama_remove_cache, #cama_set_cache
Instance Method Details
#add_fields(items, item_options) ⇒ Object
only used by form on admin panel (protected) return array of failed_fields and full_fields [[failed fields], [all fields]]
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 |
# File 'app/models/camaleon_cms/custom_field_group.rb', line 53 def add_fields(items, ) fields.where.not(id: items.to_h.map { |_k, obj| obj['id'] }.uniq).destroy_all cache_fields = [] order_index = 0 errors_saved = [] if items.present? items.each do |i, item| item[:field_order] = order_index = [i] || {} if item[:id].present? && (field_item = fields.find_by(id: item[:id])).present? saved = field_item.update(item) cache_fields << field_item else field_item = fields.new(item) cache_fields << field_item saved = field_item.save auto_save_default_values(field_item, ) if saved errors_saved << field_item unless saved end if saved field_item.('_default', ) order_index += 1 end end end [errors_saved, cache_fields] end |
#add_manual_field(item, options) ⇒ Object Also known as: add_field
add fields to group item:
-
sample: “slug”=>“my_slug”, “description”=>“my description (optional)”
-
options (textbox sample):
"translate":"1"
-
field_key (string) | translate (boolean) | default_value (unique value) |
default_values (array - multiple values for this field) | multiple_options (array)
-
multiple_options (used for select, radio and checkboxes ): [{“title”=>“Option Title”,
"value"=>"2", "default"=>"1"}, {"title"=>"abcde", "value"=>"3"}]
****** check all options for each case in Admin::CustomFieldsHelper **** SAMPLE: my_model.add_field({“name”=>“Sub Title”, “slug”=>“subtitle”}, {“field_key”=>“text_box”,
"translate"=>true, default_value: "Get in Touch"})
33 34 35 36 37 38 39 40 41 42 43 |
# File 'app/models/camaleon_cms/custom_field_group.rb', line 33 def add_manual_field(item, ) c = get_field(item[:slug] || item['slug']) return c if c.present? field_item = fields.new(item) if field_item.save field_item.() auto_save_default_values(field_item, ) end field_item end |
#get_caption ⇒ Object
generate the caption for this group
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'app/models/camaleon_cms/custom_field_group.rb', line 82 def = '' begin case object_class when 'PostType_Post' = "Fields for Contents in <b>#{site.post_types.find(objectid).decorate.the_title}</b>" when 'PostType_Category' = "Fields for Categories in <b>#{site.post_types.find(objectid).decorate.the_title}</b>" when 'PostType_PostTag' = "Fields for Post tags in <b>#{site.post_types.find(objectid).decorate.the_title}</b>" when 'Widget::Main' = "Fields for Widget <b>(#{CamaleonCms::Widget::Main.find(objectid).name.translate})</b>" when 'Theme' = "Field settings for Theme <b>(#{begin site.themes.find(objectid).name rescue StandardError objectid end})</b>" when 'NavMenu' = "Field settings for Menus <b>(#{CamaleonCms::NavMenu.find(objectid).name})</b>" when 'Site' = 'Field settings the site' when 'PostType' = 'Fields for all <b>Post_Types</b>' when 'Post' p = CamaleonCms::Post.find(objectid).decorate = "Fields for content <b>(#{p.the_title})</b>" else # 'Plugin' or other class = "Fields for <b>#{object_class}</b>" end rescue StandardError => e Rails.logger.debug "Camaleon CMS - Menu Item Error: #{e.} ==> Attrs: #{attributes}" end end |
#get_field(slug) ⇒ Object
return a field with slug = slug from current group
47 48 49 |
# File 'app/models/camaleon_cms/custom_field_group.rb', line 47 def get_field(slug) fields.find_by(slug: slug) end |