Class: Rapid::Web::SettingsFormBuilder

Inherits:
StandardFormBuilder
  • Object
show all
Defined in:
lib/rapid/web/settings_form_builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#object_field_nameObject

Returns the value of attribute object_field_name.



7
8
9
# File 'lib/rapid/web/settings_form_builder.rb', line 7

def object_field_name
  @object_field_name
end

#object_name=(value) ⇒ Object

Sets the attribute object_name

Parameters:

  • value

    the value to set the attribute object_name to.



6
7
8
# File 'lib/rapid/web/settings_form_builder.rb', line 6

def object_name=(value)
  @object_name = value
end

Instance Method Details

#check_box(field, options = {}) ⇒ Object



81
82
83
84
85
86
87
# File 'lib/rapid/web/settings_form_builder.rb', line 81

def check_box field, options = {}
  if field.is_a?(String) && field =~ /\.on\Z/ && !options.key?(:checked)
    options[:checked] = object[$`].on?
  end
  
  patched_check_box field, options.reverse_merge(:id => setting_id(field), :name => setting_name(field), :checked => object[field])
end

#control_group(field, options = {}, &block) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/rapid/web/settings_form_builder.rb', line 52

def control_group field, options = {}, &block
  label_text = options.delete(:label) || field.to_s.split('.').last.titleize
  
  label_html = label(field, :caption => label_text)
  field_html = @template.capture_html(&block)
  
  id = setting_id(field) + "_group"
  
  html = control_group_html id, label_html, field_html, options
  @template.concat_content html
  html
end

#control_group_check_box(field, options = {}) ⇒ Object



118
119
120
# File 'lib/rapid/web/settings_form_builder.rb', line 118

def control_group_check_box field, options = {}
  control_group_field :check_box, field, options
end

#control_group_file_field(field, options = {}) ⇒ Object



126
127
128
# File 'lib/rapid/web/settings_form_builder.rb', line 126

def control_group_file_field field, options = {}
  control_group_field :file_field, field, options
end

#control_group_password_field(field, options = {}) ⇒ Object



110
111
112
# File 'lib/rapid/web/settings_form_builder.rb', line 110

def control_group_password_field field, options = {}
  control_group_field :password_field, field, options
end

#control_group_radio_button(field, options = {}) ⇒ Object



122
123
124
# File 'lib/rapid/web/settings_form_builder.rb', line 122

def control_group_radio_button field, options = {}
  control_group_field :radio_button, field, options
end

#control_group_select(field, options = {}) ⇒ Object



114
115
116
# File 'lib/rapid/web/settings_form_builder.rb', line 114

def control_group_select field, options = {}
  control_group_field :select, field, options
end

#control_group_text_area(field, options = {}) ⇒ Object



106
107
108
# File 'lib/rapid/web/settings_form_builder.rb', line 106

def control_group_text_area field, options = {}
  control_group_field :text_area, field, options
end

#control_group_text_field(field, options = {}) ⇒ Object



102
103
104
# File 'lib/rapid/web/settings_form_builder.rb', line 102

def control_group_text_field field, options = {}
  control_group_field :text_field, field, options
end

#control_group_time_zone_select(field, options = {}) ⇒ Object



130
131
132
# File 'lib/rapid/web/settings_form_builder.rb', line 130

def control_group_time_zone_select field, options = {}
  control_group_field :time_zone_select, field, options
end

#fields_for(field, settings = {}, &block) ⇒ Object



17
18
19
20
# File 'lib/rapid/web/settings_form_builder.rb', line 17

def fields_for field, settings={}, &block
  fields_html = builder_html_for(field, settings, &block)
  @template.concat_content fields_html
end

#file_field(field, options = {}) ⇒ Object



93
94
95
# File 'lib/rapid/web/settings_form_builder.rb', line 93

def file_field field, options = {}
  super field, options.reverse_merge(:id => setting_id(field), :name => setting_name(field), :value => object[field])
end

#label(field, options = {}) ⇒ Object



9
10
11
12
13
14
15
# File 'lib/rapid/web/settings_form_builder.rb', line 9

def label field, options = {}
  if field.is_a?(String)
    super field.split('.').last, options.reverse_merge(:for => setting_id(field))
  else
    super
  end
end

#password_field(field, options = {}) ⇒ Object



73
74
75
# File 'lib/rapid/web/settings_form_builder.rb', line 73

def password_field field, options = {}
  super field, options.reverse_merge(:id => setting_id(field), :name => setting_name(field), :value => object[field])
end

#radio_button(field, options = {}) ⇒ Object



89
90
91
# File 'lib/rapid/web/settings_form_builder.rb', line 89

def radio_button field, options = {}
  super field, options.reverse_merge(:id => setting_id(field), :name => setting_name(field), :selected => object[field])
end

#section(name, options = {}, &block) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/rapid/web/settings_form_builder.rb', line 22

def section name, options = {}, &block
  body = @template.capture_html(&block)
  
  title = options[:label] || name.to_s.titleize
  a = @template.tag(:a, :href => '#', :class => 'toggle-section', :content => title)
  legend = @template.tag(:legend, :content => a)
  
  content = legend << body
  fieldset = @template.tag(:fieldset, :id => "section_#{name}", :class => "minimize", :content => content)
  @template.concat_content fieldset
  fieldset
end

#select(field, options = {}) ⇒ Object



77
78
79
# File 'lib/rapid/web/settings_form_builder.rb', line 77

def select field, options = {}
  super field, options.reverse_merge(:id => setting_id(field), :name => setting_name(field), :selected => object[field])
end

#settings(name, &block) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/rapid/web/settings_form_builder.rb', line 35

def settings name, &block
  id = "#{name.gsub('.', '_')}_settings"
  content = @template.capture_html &block
  
  namespace = object[name]
  if !namespace.respond_to?(:on?)
    off = true
  else
    off = !namespace.on?
  end
  
  css_class = off ? 'subsettings settings-off' : 'subsettings'
  
  html = @template.tag :div, :id => id, :class => css_class, :content => content
  @template.concat_content html
end

#text_area(field, options = {}) ⇒ Object



69
70
71
# File 'lib/rapid/web/settings_form_builder.rb', line 69

def text_area field, options = {}
  super field, options.reverse_merge(:id => setting_id(field), :name => setting_name(field), :value => object[field])
end

#text_field(field, options = {}) ⇒ Object



65
66
67
# File 'lib/rapid/web/settings_form_builder.rb', line 65

def text_field field, options = {}
  super field, options.reverse_merge(:id => setting_id(field), :name => setting_name(field), :value => object[field])
end

#time_zone_select(field, options = {}) ⇒ Object



97
98
99
100
# File 'lib/rapid/web/settings_form_builder.rb', line 97

def time_zone_select field, options = {}
  options.reverse_merge!(:id => setting_id(field), :value => object[field], :selected => field_value(field))
  @template.send :time_zone_select, setting_name(field), options
end