Class: CamaleonCms::CustomFieldGroup
- Inherits:
-
CustomField
- Object
- ActiveRecord::Base
- CustomField
- CamaleonCms::CustomFieldGroup
- Defined in:
- app/models/camaleon_cms/custom_field_group.rb
Overview
Camaleon CMS is a content management system
Copyright (C) 2015 by Owen Peredo Diaz
Email: [email protected]
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License (GPLv3) for more details.
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): “field_key”:“text_box”,“multiple”:“1”,“required”:“1”,“translate”:“1” * field_key (string) | translate (boolean) | default_value (unique value) | default_values (array - multiple values for this field) | label_eval (boolean) | multiple_options (array) * multiple_options (used for select, radio and checkboxes ): [Title”, “value”=>“2”, “default”=>“1”, “value”=>“3”] * label_eval: (Boolean, default false), true => will evaluate the label and description of current field using (eval(‘my_label’)) to have translatable|dynamic labels ****** 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_multiple_options, #set_option
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]]
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'app/models/camaleon_cms/custom_field_group.rb', line 50 def add_fields(items, ) self.fields.where.not(id: items.map{|k, obj| obj['id'] }.uniq).destroy_all cache_fields, order_index, errors_saved = [], 0, [] if items.present? items.each do |i,item| item[:field_order] = order_index = [i] || {} if item[:id].present? && (field_item = self.fields.where(id: item[:id]).first).present? saved = field_item.update(item) cache_fields << field_item else field_item = self.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): “field_key”:“text_box”,“multiple”:“1”,“required”:“1”,“translate”:“1”
-
field_key (string) | translate (boolean) | default_value (unique value) | default_values (array - multiple values for this field) | label_eval (boolean) | multiple_options (array)
-
multiple_options (used for select, radio and checkboxes ): [Title”, “value”=>“2”, “default”=>“1”, “value”=>“3”]
-
label_eval: (Boolean, default false), true => will evaluate the label and description of current field using (eval(‘my_label’)) to have translatable|dynamic labels
****** check all options for each case in Admin::CustomFieldsHelper **** SAMPLE: my_model.add_field(Title”, “slug”=>“subtitle”, “translate”=>true, default_value: “Get in Touch”)
30 31 32 33 34 35 36 37 38 39 40 |
# File 'app/models/camaleon_cms/custom_field_group.rb', line 30 def add_manual_field(item, ) c = get_field(item[:slug] || item["slug"]) return c if c.present? field_item = self.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
77 78 79 80 81 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 |
# File 'app/models/camaleon_cms/custom_field_group.rb', line 77 def = "" begin case self.object_class when "PostType_Post" = "Fields for Contents in <b>#{self.site.post_types.find(self.objectid).decorate.the_title}</b>" when 'PostType_Category' = "Fields for Categories in <b>#{self.site.post_types.find(self.objectid).decorate.the_title}</b>" when 'PostType_PostTag' = "Fields for Post tags in <b>#{self.site.post_types.find(self.objectid).decorate.the_title}</b>" when 'Widget::Main' = "Fields for Widget <b>(#{CamaleonCms::Widget::Main.find(self.objectid).name.translate})</b>" when 'Theme' = "Field settings for Theme <b>(#{self.site.themes.find(self.objectid).name rescue self.objectid})</b>" when 'NavMenu' = "Field settings for Menus <b>(#{CamaleonCms::NavMenu.find(self.objectid).name})</b>" when 'Site' = "Field settings the site" when 'PostType' = "Fields for all <b>Post_Types</b>" when 'Post' p = CamaleonCms::Post.find(self.objectid).decorate = "Fields for content <b>(#{p.the_title})</b>" else # 'Plugin' or other class = "Fields for <b>#{self.object_class}</b>" end rescue => e Rails.logger.info "----------#{e.}----#{self.attributes}" end end |
#get_field(slug) ⇒ Object
return a field with slug = slug from current group
44 45 46 |
# File 'app/models/camaleon_cms/custom_field_group.rb', line 44 def get_field(slug) self.fields.where(slug: slug).first end |