Class: RailsAdmin::Config::Fields::Base
- Inherits:
-
Object
- Object
- RailsAdmin::Config::Fields::Base
- Includes:
- Configurable, Groupable, Hideable, Proxyable
- Defined in:
- lib/rails_admin/config/fields/base.rb
Direct Known Subclasses
Association, Types::Boolean, Types::Color, Types::Datetime, Types::Decimal, Types::Enum, Types::FileUpload, Types::Float, Types::Hidden, Types::Integer, Types::String, Types::Text
Instance Attribute Summary collapse
-
#abstract_model ⇒ Object
readonly
Returns the value of attribute abstract_model.
-
#defined ⇒ Object
Returns the value of attribute defined.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#order ⇒ Object
Returns the value of attribute order.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
-
#properties ⇒ Object
readonly
Returns the value of attribute properties.
-
#root ⇒ Object
readonly
Returns the value of attribute root.
-
#section ⇒ Object
Returns the value of attribute section.
Attributes included from Proxyable
Instance Method Summary collapse
-
#association? ⇒ Boolean
Is this an association.
- #editable? ⇒ Boolean
-
#errors ⇒ Object
Reader for validation errors of the bound object.
- #form_default_value ⇒ Object
- #form_value ⇒ Object
- #generic_field_help ⇒ Object
- #generic_help ⇒ Object
-
#initialize(parent, name, properties) ⇒ Base
constructor
A new instance of Base.
- #inspect ⇒ Object
- #inverse_of ⇒ Object
- #method_name ⇒ Object
-
#optional(state = nil, &block) ⇒ Object
Inverse accessor whether this field is required.
-
#optional=(state) ⇒ Object
Writer to make field optional.
-
#optional? ⇒ Boolean
Reader whether field is optional.
- #parse_input(params) ⇒ Object
-
#type ⇒ Object
Reader for field’s type.
- #type_css_class ⇒ Object
-
#value ⇒ Object
Reader for field’s value.
- #virtual? ⇒ Boolean
Methods included from Groupable
Methods included from Hideable
#hidden?, #hide, included, #show
Methods included from Configurable
#has_option?, included, #register_deprecated_instance_option, #register_instance_option
Methods included from Proxyable
Constructor Details
#initialize(parent, name, properties) ⇒ Base
Returns a new instance of Base.
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/rails_admin/config/fields/base.rb', line 19 def initialize(parent, name, properties) @parent = parent @root = parent.root @abstract_model = parent.abstract_model @defined = false @name = name.to_sym @order = 0 @properties = properties @section = parent end |
Instance Attribute Details
#abstract_model ⇒ Object (readonly)
Returns the value of attribute abstract_model.
15 16 17 |
# File 'lib/rails_admin/config/fields/base.rb', line 15 def abstract_model @abstract_model end |
#defined ⇒ Object
Returns the value of attribute defined.
16 17 18 |
# File 'lib/rails_admin/config/fields/base.rb', line 16 def defined @defined end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
15 16 17 |
# File 'lib/rails_admin/config/fields/base.rb', line 15 def name @name end |
#order ⇒ Object
Returns the value of attribute order.
16 17 18 |
# File 'lib/rails_admin/config/fields/base.rb', line 16 def order @order end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
17 18 19 |
# File 'lib/rails_admin/config/fields/base.rb', line 17 def parent @parent end |
#properties ⇒ Object (readonly)
Returns the value of attribute properties.
15 16 17 |
# File 'lib/rails_admin/config/fields/base.rb', line 15 def properties @properties end |
#root ⇒ Object (readonly)
Returns the value of attribute root.
17 18 19 |
# File 'lib/rails_admin/config/fields/base.rb', line 17 def root @root end |
#section ⇒ Object
Returns the value of attribute section.
16 17 18 |
# File 'lib/rails_admin/config/fields/base.rb', line 16 def section @section end |
Instance Method Details
#association? ⇒ Boolean
Is this an association
221 222 223 |
# File 'lib/rails_admin/config/fields/base.rb', line 221 def association? kind_of?(RailsAdmin::Config::Fields::Association) end |
#editable? ⇒ Boolean
216 217 218 |
# File 'lib/rails_admin/config/fields/base.rb', line 216 def editable? !(@properties && @properties[:read_only]) end |
#errors ⇒ Object
Reader for validation errors of the bound object
226 227 228 229 230 |
# File 'lib/rails_admin/config/fields/base.rb', line 226 def errors ([name] + children_fields).uniq.map do |column_name| bindings[:object].errors[column_name] end.uniq.flatten end |
#form_default_value ⇒ Object
300 301 302 |
# File 'lib/rails_admin/config/fields/base.rb', line 300 def form_default_value (self.default_value if bindings[:object].new_record? && self.value.nil? && !self.default_value.nil?) end |
#form_value ⇒ Object
304 305 306 |
# File 'lib/rails_admin/config/fields/base.rb', line 304 def form_value self.form_default_value.nil? ? self.formatted_value : self.form_default_value end |
#generic_field_help ⇒ Object
281 282 283 284 285 286 |
# File 'lib/rails_admin/config/fields/base.rb', line 281 def generic_field_help model = abstract_model.model_name.underscore model_lookup = "admin.help.#{model}.#{name}".to_sym translated = I18n.translate(model_lookup, :help => generic_help, :default => [generic_help]) (translated.is_a?(Hash) ? translated.to_a.first[1] : translated).html_safe end |
#generic_help ⇒ Object
277 278 279 |
# File 'lib/rails_admin/config/fields/base.rb', line 277 def generic_help (required? ? I18n.translate("admin.form.required") : I18n.translate("admin.form.optional")) + '. ' end |
#inspect ⇒ Object
308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 |
# File 'lib/rails_admin/config/fields/base.rb', line 308 def inspect "#<#{self.class.name}[#{name}] #{ instance_variables.map do |v| value = instance_variable_get(v) if [:@parent, :@root, :@section, :@children_fields_registered, :@associated_model_config, :@group, :@bindings].include? v if value.respond_to? :name "#{v}=#{value.name.inspect}" else "#{v}=#{value.class.name}" end else "#{v}=#{value.inspect}" end end.join(", ") }>" end |
#inverse_of ⇒ Object
292 293 294 |
# File 'lib/rails_admin/config/fields/base.rb', line 292 def inverse_of nil end |
#method_name ⇒ Object
296 297 298 |
# File 'lib/rails_admin/config/fields/base.rb', line 296 def method_name name end |
#optional(state = nil, &block) ⇒ Object
Inverse accessor whether this field is required.
242 243 244 245 246 247 248 |
# File 'lib/rails_admin/config/fields/base.rb', line 242 def optional(state = nil, &block) if !state.nil? || block required state.nil? ? proc { false == (instance_eval &block) } : false == state else optional? end end |
#optional=(state) ⇒ Object
Writer to make field optional.
253 254 255 |
# File 'lib/rails_admin/config/fields/base.rb', line 253 def optional=(state) optional(state) end |
#optional? ⇒ Boolean
Reader whether field is optional.
235 236 237 |
# File 'lib/rails_admin/config/fields/base.rb', line 235 def optional? not required? end |
#parse_input(params) ⇒ Object
288 289 290 |
# File 'lib/rails_admin/config/fields/base.rb', line 288 def parse_input(params) # overriden end |
#type ⇒ Object
Reader for field’s type
258 259 260 |
# File 'lib/rails_admin/config/fields/base.rb', line 258 def type @type ||= self.class.name.to_s.demodulize.underscore.to_sym end |
#type_css_class ⇒ Object
35 36 37 |
# File 'lib/rails_admin/config/fields/base.rb', line 35 def type_css_class "#{type}_type" end |
#value ⇒ Object
Reader for field’s value
263 264 265 |
# File 'lib/rails_admin/config/fields/base.rb', line 263 def value bindings[:object].safe_send(name) end |
#virtual? ⇒ Boolean
39 40 41 |
# File 'lib/rails_admin/config/fields/base.rb', line 39 def virtual? properties.blank? end |