Class: Effective::FormBuilder

Inherits:
ActionView::Helpers::FormBuilder
  • Object
show all
Defined in:
app/models/effective/form_builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object_name, object, template, options) ⇒ FormBuilder

Returns a new instance of FormBuilder.



8
9
10
11
12
13
14
15
16
17
18
# File 'app/models/effective/form_builder.rb', line 8

def initialize(object_name, object, template, options)
  @template = template

  @layout = (options.delete(:layout) || :vertical).to_sym
  @action = options.delete(:action)
  @readonly = options.delete(:readonly)
  @disabled = options.delete(:disabled)
  @remote = options[:remote]

  super
end

Instance Attribute Details

#actionObject

Returns the value of attribute action.



4
5
6
# File 'app/models/effective/form_builder.rb', line 4

def action
  @action
end

#disabledObject

Returns the value of attribute disabled.



4
5
6
# File 'app/models/effective/form_builder.rb', line 4

def disabled
  @disabled
end

#layoutObject

Returns the value of attribute layout.



4
5
6
# File 'app/models/effective/form_builder.rb', line 4

def layout
  @layout
end

#readonlyObject

Returns the value of attribute readonly.



4
5
6
# File 'app/models/effective/form_builder.rb', line 4

def readonly
  @readonly
end

#remoteObject

Returns the value of attribute remote.



4
5
6
# File 'app/models/effective/form_builder.rb', line 4

def remote
  @remote
end

#templateObject

Returns the value of attribute template.



4
5
6
# File 'app/models/effective/form_builder.rb', line 4

def template
  @template
end

Instance Method Details

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



25
26
27
# File 'app/models/effective/form_builder.rb', line 25

def article_editor(name, options = {}, &block)
  Effective::FormInputs::ArticleEditor.new(name, options, builder: self).to_html(&block)
end

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



34
35
36
37
38
39
40
# File 'app/models/effective/form_builder.rb', line 34

def check_box(name, options = {})
  Effective::FormInputs::CheckBox.new(name, options, builder: self).to_html {
    checked_value = options.fetch(:checked_value, '1')
    unchecked_value = options.fetch(:unchecked_value, '0')
    super(name, options.except(:checked_value, :unchecked_value), checked_value, unchecked_value)
  }
end

#checks(name, choices = nil, *args) ⇒ Object



42
43
44
45
# File 'app/models/effective/form_builder.rb', line 42

def checks(name, choices = nil, *args)
  options = args.extract_options!.merge!(collection: choices)
  Effective::FormInputs::Checks.new(name, options, builder: self).to_html
end

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



47
48
49
# File 'app/models/effective/form_builder.rb', line 47

def ck_editor(name, options = {}, &block)
  Effective::FormInputs::CkEditor.new(name, options, builder: self).to_html(&block)
end

#clear(name = 'Clear', options = {}) ⇒ Object



29
30
31
32
# File 'app/models/effective/form_builder.rb', line 29

def clear(name = 'Clear', options = {})
  (options = name; name = 'Clear') if name.kind_of?(Hash)
  Effective::FormInputs::Clear.new(name, options, builder: self).to_html
end

#date_field(name, options = {}) ⇒ Object



51
52
53
# File 'app/models/effective/form_builder.rb', line 51

def date_field(name, options = {})
  Effective::FormInputs::DateField.new(name, options, builder: self).to_html { super(name, options) }
end

#datetime_field(name, options = {}) ⇒ Object



55
56
57
# File 'app/models/effective/form_builder.rb', line 55

def datetime_field(name, options = {})
  Effective::FormInputs::DatetimeField.new(name, options, builder: self).to_html { super(name, options) }
end

#delete(name = 'Remove', url = nil, options = {}, &block) ⇒ Object



59
60
61
62
# File 'app/models/effective/form_builder.rb', line 59

def delete(name = 'Remove', url = nil, options = {}, &block)
  options[:href] ||= url
  Effective::FormInputs::Delete.new(name, options, builder: self).to_html(&block)
end

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



64
65
66
# File 'app/models/effective/form_builder.rb', line 64

def editor(name, options = {}, &block)
  Effective::FormInputs::Editor.new(name, options, builder: self).to_html(&block)
end

#email_cc_field(name, options = {}) ⇒ Object



72
73
74
# File 'app/models/effective/form_builder.rb', line 72

def email_cc_field(name, options = {})
  Effective::FormInputs::EmailCcField.new(name, options, builder: self).to_html
end

#email_field(name, options = {}) ⇒ Object



68
69
70
# File 'app/models/effective/form_builder.rb', line 68

def email_field(name, options = {})
  Effective::FormInputs::EmailField.new(name, options, builder: self).to_html { super(name, options) }
end

#error(name = nil, options = {}) ⇒ Object Also known as: errors



76
77
78
# File 'app/models/effective/form_builder.rb', line 76

def error(name = nil, options = {})
  Effective::FormInputs::ErrorField.new(name, options, builder: self).to_html()
end

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



81
82
83
# File 'app/models/effective/form_builder.rb', line 81

def file_field(name, options = {})
  Effective::FormInputs::FileField.new(name, options, builder: self).to_html { super(name, options) }
end

#float_field(name, options = {}) ⇒ Object



85
86
87
# File 'app/models/effective/form_builder.rb', line 85

def float_field(name, options = {})
  Effective::FormInputs::FloatField.new(name, options, builder: self).to_html
end

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



89
90
91
# File 'app/models/effective/form_builder.rb', line 89

def form_group(name = nil, options = {}, &block)
  Effective::FormInputs::FormGroup.new(name, options, builder: self).to_html(&block)
end

#has_many(name, collection = nil, options = {}, &block) ⇒ Object

Has Many



211
212
213
214
215
216
217
218
219
220
221
222
# File 'app/models/effective/form_builder.rb', line 211

def has_many(name, collection = nil, options = {}, &block)
  association = object.class.reflect_on_all_associations.find { |a| a.name == name }
  raise("expected #{object.class.name} to has_many :#{name}") if association.blank?

  nested_attributes_options = (object.class.nested_attributes_options || {})[name]
  raise("expected #{object.class.name} to accepts_nested_attributes_for :#{name}") if nested_attributes_options.blank?

  options = collection if collection.kind_of?(Hash)
  options.merge!(collection: collection) if collection && !collection.kind_of?(Hash)

  Effective::FormInputs::HasMany.new(name, options, builder: self).to_html(&block)
end

#hidden_field(name = nil, options = {}) ⇒ Object



93
94
95
# File 'app/models/effective/form_builder.rb', line 93

def hidden_field(name = nil, options = {})
  Effective::FormInputs::HiddenField.new(name, options, builder: self).to_html
end

#hide_if(*args, &block) ⇒ Object

Logics



198
199
200
# File 'app/models/effective/form_builder.rb', line 198

def hide_if(*args, &block)
  Effective::FormLogics::HideIf.new(*args, builder: self).to_html(&block)
end

#integer_field(name, options = {}) ⇒ Object



97
98
99
# File 'app/models/effective/form_builder.rb', line 97

def integer_field(name, options = {})
  Effective::FormInputs::IntegerField.new(name, options, builder: self).to_html
end

#number_field(name, options = {}) ⇒ Object



115
116
117
# File 'app/models/effective/form_builder.rb', line 115

def number_field(name, options = {})
  Effective::FormInputs::NumberField.new(name, options, builder: self).to_html { super(name, options) }
end

#number_text_field(name, options = {}) ⇒ Object



119
120
121
# File 'app/models/effective/form_builder.rb', line 119

def number_text_field(name, options = {})
  Effective::FormInputs::NumberTextField.new(name, options, builder: self).to_html
end

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



123
124
125
# File 'app/models/effective/form_builder.rb', line 123

def password_field(name, options = {})
  Effective::FormInputs::PasswordField.new(name, options, builder: self).to_html { super(name, options) }
end

#percent_field(name, options = {}) ⇒ Object



127
128
129
# File 'app/models/effective/form_builder.rb', line 127

def percent_field(name, options = {})
  Effective::FormInputs::PercentField.new(name, options, builder: self).to_html
end

#phone_field(name, options = {}) ⇒ Object Also known as: tel_field, telephone_field



131
132
133
# File 'app/models/effective/form_builder.rb', line 131

def phone_field(name, options = {})
  Effective::FormInputs::PhoneField.new(name, options, builder: self).to_html { super(name, options) }
end

#price_field(name, options = {}) ⇒ Object



137
138
139
# File 'app/models/effective/form_builder.rb', line 137

def price_field(name, options = {})
  Effective::FormInputs::PriceField.new(name, options, builder: self).to_html { super(name, options) }
end

#radios(name, choices = nil, *args) ⇒ Object



166
167
168
169
# File 'app/models/effective/form_builder.rb', line 166

def radios(name, choices = nil, *args)
  options = args.extract_options!.merge!(collection: choices)
  Effective::FormInputs::Radios.new(name, options, builder: self).to_html
end

This is gonna be a post?



102
103
104
105
# File 'app/models/effective/form_builder.rb', line 102

def remote_link_to(name, url, options = {}, &block)
  options[:href] ||= url
  Effective::FormInputs::RemoteLinkTo.new(name, options, builder: self).to_html(&block)
end

#reset(name = 'Reset', options = {}) ⇒ Object



171
172
173
174
# File 'app/models/effective/form_builder.rb', line 171

def reset(name = 'Reset', options = {})
  (options = name; name = 'Reset') if name.kind_of?(Hash)
  Effective::FormInputs::Reset.new(name, options, builder: self).to_html
end

#rich_text_area(name, options = {}) ⇒ Object



107
108
109
# File 'app/models/effective/form_builder.rb', line 107

def rich_text_area(name, options = {})
  Effective::FormInputs::RichTextArea.new(name, options, builder: self).to_html { super(name, options) }
end

#save(name = 'Save', options = {}) ⇒ Object



141
142
143
144
# File 'app/models/effective/form_builder.rb', line 141

def save(name = 'Save', options = {})
  (options = name; name = 'Save') if name.kind_of?(Hash)
  Effective::FormInputs::Save.new(name, options, builder: self).to_html { super(name, options) }
end

#search_field(name, options = {}) ⇒ Object



111
112
113
# File 'app/models/effective/form_builder.rb', line 111

def search_field(name, options = {})
  Effective::FormInputs::SearchField.new(name, options, builder: self).to_html { super(name, options) }
end

#select(name, choices = nil, *args) ⇒ Object



146
147
148
149
# File 'app/models/effective/form_builder.rb', line 146

def select(name, choices = nil, *args)
  options = args.extract_options!.merge!(collection: choices)
  Effective::FormInputs::Select.new(name, options, builder: self).to_html
end

#select_or_text(name, name_text, choices = nil, *args) ⇒ Object



151
152
153
154
# File 'app/models/effective/form_builder.rb', line 151

def select_or_text(name, name_text, choices = nil, *args)
  options = args.extract_options!.merge!(name_text: name_text, collection: choices)
  Effective::FormInputs::SelectOrText.new(name, options, builder: self).to_html
end

#show_if(*args, &block) ⇒ Object



202
203
204
# File 'app/models/effective/form_builder.rb', line 202

def show_if(*args, &block)
  Effective::FormLogics::ShowIf.new(*args, builder: self).to_html(&block)
end

#show_if_any(*args, &block) ⇒ Object



206
207
208
# File 'app/models/effective/form_builder.rb', line 206

def show_if_any(*args, &block)
  Effective::FormLogics::ShowIfAny.new(*args, builder: self).to_html(&block)
end

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



161
162
163
164
# File 'app/models/effective/form_builder.rb', line 161

def static_field(name, options = {}, &block)
  options = { value: options } if options.kind_of?(String)
  Effective::FormInputs::StaticField.new(name, options, builder: self).to_html(&block)
end

#submit(name = 'Save', options = {}, &block) ⇒ Object



156
157
158
159
# File 'app/models/effective/form_builder.rb', line 156

def submit(name = 'Save', options = {}, &block)
  (options = name; name = 'Save') if name.kind_of?(Hash)
  Effective::FormInputs::Submit.new(name, options, builder: self).to_html(&block)
end

#super_hidden_fieldObject



23
# File 'app/models/effective/form_builder.rb', line 23

alias_method :super_hidden_field, :hidden_field

#super_number_fieldObject



20
# File 'app/models/effective/form_builder.rb', line 20

alias_method :super_number_field, :number_field

#super_text_areaObject



22
# File 'app/models/effective/form_builder.rb', line 22

alias_method :super_text_area, :text_area

#super_text_fieldObject



21
# File 'app/models/effective/form_builder.rb', line 21

alias_method :super_text_field, :text_field

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



176
177
178
# File 'app/models/effective/form_builder.rb', line 176

def text_area(name, options = {})
  Effective::FormInputs::TextArea.new(name, options, builder: self).to_html { super(name, options) }
end

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



180
181
182
# File 'app/models/effective/form_builder.rb', line 180

def text_field(name, options = {})
  Effective::FormInputs::TextField.new(name, options, builder: self).to_html { super(name, options) }
end

#time_field(name, options = {}) ⇒ Object



184
185
186
# File 'app/models/effective/form_builder.rb', line 184

def time_field(name, options = {})
  Effective::FormInputs::TimeField.new(name, options, builder: self).to_html { super(name, options) }
end

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



188
189
190
191
# File 'app/models/effective/form_builder.rb', line 188

def time_zone_select(name, options = {})
  opts = options.merge(collection: Effective::FormInputs::TimeZoneSelect.time_zone_collection)
  Effective::FormInputs::TimeZoneSelect.new(name, opts, builder: self).to_html
end

#url_field(name, options = {}) ⇒ Object



193
194
195
# File 'app/models/effective/form_builder.rb', line 193

def url_field(name, options = {})
  Effective::FormInputs::UrlField.new(name, options, builder: self).to_html { super(name, options) }
end