Class: PropertyGrid::GroupProperty

Inherits:
Object
  • Object
show all
Defined in:
lib/property_grid.rb

Overview

A container for a property within a group.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(var, name, property_type, collection = nil) ⇒ GroupProperty

some of these use jquery: jqueryui.com/



59
60
61
62
63
64
# File 'lib/property_grid.rb', line 59

def initialize(var, name, property_type, collection = nil)
  @property_var = var
  @property_name = name
  @property_type = property_type
  @property_collection = collection
end

Instance Attribute Details

#property_collectionObject

Returns the value of attribute property_collection.



56
57
58
# File 'lib/property_grid.rb', line 56

def property_collection
  @property_collection
end

#property_nameObject

Returns the value of attribute property_name.



54
55
56
# File 'lib/property_grid.rb', line 54

def property_name
  @property_name
end

#property_typeObject

Returns the value of attribute property_type.



55
56
57
# File 'lib/property_grid.rb', line 55

def property_type
  @property_type
end

#property_varObject

Returns the value of attribute property_var.



53
54
55
# File 'lib/property_grid.rb', line 53

def property_var
  @property_var
end

Instance Method Details

#get_erb(form_type) ⇒ Object

Returns the erb for a given form type. This code handles the construction of the web control that will display the content of a property in the property grid. The web page must utilize a field_for … |f| for this construction to work.



78
79
80
81
82
83
84
85
86
# File 'lib/property_grid.rb', line 78

def get_erb(form_type)
  erb = "<%= f.#{form_type.type_name} :#{@property_var}"
  erb << ", class: '#{form_type.class_name}'" if form_type.class_name.present?
  erb << ", #{@property_collection}" if @property_collection.present? && @property_type == :list
  erb << ", options_from_collection_for_select(f.object.records, :id, :name, f.object.#{@property_var})" if @property_collection.present? && @property_type == :db_list
  erb << "%>"

  erb
end

#get_input_controlObject

returns the ERB for this property as defined by its property_type



67
68
69
70
71
72
73
# File 'lib/property_grid.rb', line 67

def get_input_control
  form_type = PropertyGridTypes.get_property_type_map[@property_type]
  raise "Property '#{@property_type}' is not mapped to an input control" if form_type.nil?
  erb = get_erb(form_type)

  erb
end