| Module | Flvorful::CustomHelpers |
| In: |
vendor/plugins/super_inplace_controls/lib/custom_helpers.rb
|
These are some extra form helpers to help you clean up your views. They add a label to the regular input field. There are several extra options to help control the look of the label.
:human_name - By default, the labeler will use the method as the label name. You can change it to whatever you want by passing in this option. ie:
text_field_with_label :product, :title, {:human_name => "Product Name"}
:required - pass :required => true to add a "*" after the label to indicate a require field. ie:
text_field_with_label :product, :title, {:required => true}
:br - pass :br => false to remove the defaulted <br /> tag after the form control group. ie:
text_field_with_label :product, :title, {:br => false}
will produce
<label id="product_title_label" class="text_field_label" for="product_title">Title: </label> <input id="product_title" class="input_text_field" type="text" value="123" size="30" name="product[title]" input_type="text_field"/>
instead of
<label id="product_title_label" class="text_field_label" for="product_title">Title: </label> <input id="product_title" class="input_text_field" type="text" value="123" size="30" name="product[title]" input_type="text_field"/> <br/>
used when you want to chain multiple form controls on one line by floating everything.
:break_after_label - pass :break_after_label => true to add a "<br />" after the label so that the input field falls below the label instead of next to it. ie:
text_field_with_label :product, :title, {:break_after_label => true}
| STATES | = | [ ['Select a State', 'None'], ['Alabama', 'AL'], ['Alaska', 'AK'], ['Arizona', 'AZ'], ['Arkansas', 'AR'], ['California', 'CA'], ['Colorado', 'CO'], ['Connecticut', 'CT'], ['Delaware', 'DE'], ['District Of Columbia', 'DC'], ['Florida', 'FL'], ['Georgia', 'GA'], ['Hawaii', 'HI'], ['Idaho', 'ID'], ['Illinois', 'IL'], ['Indiana', 'IN'], ['Iowa', 'IA'], ['Kansas', 'KS'], ['Kentucky', 'KY'], ['Louisiana', 'LA'], ['Maine', 'ME'], ['Maryland', 'MD'], ['Massachusetts', 'MA'], ['Michigan', 'MI'], ['Minnesota', 'MN'], ['Mississippi', 'MS'], ['Missouri', 'MO'], ['Montana', 'MT'], ['Nebraska', 'NE'], ['Nevada', 'NV'], ['New Hampshire', 'NH'], ['New Jersey', 'NJ'], ['New Mexico', 'NM'], ['New York', 'NY'], ['North Carolina', 'NC'], ['North Dakota', 'ND'], ['Ohio', 'OH'], ['Oklahoma', 'OK'], ['Oregon', 'OR'], ['Pennsylvania', 'PA'], ['Rhode Island', 'RI'], ['South Carolina', 'SC'], ['South Dakota', 'SD'], ['Tennessee', 'TN'], ['Texas', 'TX'], ['Utah', 'UT'], ['Vermont', 'VT'], ['Virginia', 'VA'], ['Washington', 'WA'], ['West Virginia', 'WV'], ['Wisconsin', 'WI'], ['Wyoming', 'WY'] |
creates a series of checkbox controls and labels with the specified collection
# File vendor/plugins/super_inplace_controls/lib/custom_helpers.rb, line 159
159: def checkbox_collection(object, method, instance, collection, opts = {})
160: css_class = opts[:css_class] || "inplace_checkbox"
161: columns = opts[:columns] || 1
162:
163: m2m = instance.send("#{method}")
164: name_string = "#{object}[#{method}][]"
165:
166: htm_class = opts.delete(:label_class)
167: htm_class ||= "checkbox_collection_label"
168: collection.map do |k, v|
169: id_string = "#{object}_#{method}_#{k}"
170: tag_options = {
171: :type => "checkbox",
172: :name => name_string,
173: :id => id_string,
174: :value => k,
175: :class => css_class
176: }
177: title = opts[:title] || v rescue "No Title"
178: tag_options[:checked] = "checked" if m2m.respond_to?(:collect) && m2m.include?(k)
179: final_out = tag(:input, tag_options) + content_tag(:label, title, :for => id_string, :class => htm_class )
180: str = []
181:
182: columns.to_i.times do |x|
183: str << " "
184: end unless columns == 1
185: str << tag(:br)
186: unless columns == 1
187: final_out << cycle("", str)
188: else
189: final_out << tag(:br)
190: end
191: final_out
192: end.join("\n") + tag(:br)
193: end
creates a checkbox control with a label mapped to the specified object/method combination
# File vendor/plugins/super_inplace_controls/lib/custom_helpers.rb, line 125
125: def checkbox_field_with_label(object_name, method, options = {})
126: set_class_name(options, "checkbox")
127: rad_options = options.dup
128: rad_options.delete(:break_after_label)
129: rad_options.delete(:human_name)
130: options[:radio_label] = true
131: set_input_type(options, "checkbox")
132: ret = check_box(object_name, method, rad_options)
133: ret << create_label_field(object_name, method, options)
134: ret << add_break_to_form(options)
135:
136: end
A Quick invisible loader. Creates a div container with an image tag. Looks for an image named spinner.gif in /images Can switch between 2 loaders (regular [spinner.gif] and white [spinner_white.gif])
# File vendor/plugins/super_inplace_controls/lib/custom_helpers.rb, line 224
224: def invisible_loader(message = nil, div_id = "loader", class_name = "loader", color = "regular")
225: spinner = case color
226: when "regular"
227: image_tag("spinner.gif")
228: when "white"
229: image_tag("spinner_white.gif")
230: end
231:
232: content_tag(:div, :id => div_id, :class => class_name, :style => "display:none" ) do
233: spinner + " " + content_tag(:span, message.to_s)
234: end
235: end
creates a radio control with a label mapped to the specified object/method combination
# File vendor/plugins/super_inplace_controls/lib/custom_helpers.rb, line 139
139: def radio_button_with_label(object_name, method, value, options = {})
140: rad_options = options.dup
141: rad_options.delete(:br)
142: set_class_name(rad_options, "radio")
143: ret = radio_button( object_name, method, value, rad_options )
144: options[:human_name] = options[:human_name] || value
145: options[:radio_label] = true
146: options[:radio_value] = value
147: set_input_type(options, "radio")
148: ret << create_label_field(object_name, method, options)
149: ret << add_break_to_form(options)
150: end
creates a series of radio controls and labels with the specified collection
# File vendor/plugins/super_inplace_controls/lib/custom_helpers.rb, line 197
197: def radio_collection(object, method, instance, collection, options = {})
198: ret = ""
199: columns = options[:columns] || 1
200:
201: label_class ||= options.delete(:label_class)
202: label_class ||= "radio_collection_label"
203: options[:class] ||= "input_radio radio_collection_input"
204: collection.each do |element|
205: ret << radio_button(object, method, element[1], options)
206: ret << content_tag(:label, element.first, {:for => "#{object}_#{method}_#{element[1]}", :class => label_class})
207: str = []
208: columns.to_i.times do |x|
209: str << " "
210: end unless columns == 1
211: str << tag(:br)
212: unless columns == 1
213: ret << cycle("", str)
214: else
215: ret << tag(:br)
216: end
217: end
218: ret << tag(:br)
219: ret
220: end
creates a select control with a label mapped to the specified object/method combination
# File vendor/plugins/super_inplace_controls/lib/custom_helpers.rb, line 107
107: def select_field_with_label(object_name, method, choices, options = {}, html_options = {})
108: set_class_name(html_options, "select") if html_options[:class].blank?
109: set_input_type(options, "select")
110: ret = create_label_field(object_name, method, options)
111: ret << select( object_name, method, choices, options, html_options)
112: ret << add_break_to_form(options)
113: end
Like country_select, but for US States
# File vendor/plugins/super_inplace_controls/lib/custom_helpers.rb, line 154
154: def state_select(object, method)
155: select(object, method, STATES)
156: end
creates a textfield control with a label mapped to the specified object/method combination
# File vendor/plugins/super_inplace_controls/lib/custom_helpers.rb, line 98
98: def text_field_with_label(object_name, method, options = {})
99: set_class_name(options, "text_field")
100: set_input_type(options, "text_field")
101: ret = create_label_field(object_name, method, options)
102: ret << text_field( object_name, method, options)
103: ret << add_break_to_form(options)
104: end
creates a textarea control with a label mapped to the specified object/method combination
# File vendor/plugins/super_inplace_controls/lib/custom_helpers.rb, line 116
116: def textarea_field_with_label(object_name, method, options = {})
117: set_class_name(options, "textarea")
118: set_input_type(options, "textarea")
119: ret = create_label_field(object_name, method, options)
120: ret << text_area( object_name, method, options)
121: ret << add_break_to_form(options)
122: end
# File vendor/plugins/super_inplace_controls/lib/custom_helpers.rb, line 239
239: def add_break_to_form(options)
240: unless options[:br] == false && !options[:br].nil?
241: ret = tag(:br)
242: end
243: ret || ""
244: end
# File vendor/plugins/super_inplace_controls/lib/custom_helpers.rb, line 254
254: def create_label_field(object_name, method, options = {})
255: human_name = options[:human_name] || method.proper_case.gsub(/url/i, "URL")
256: id_string = "#{object_name.to_s.downcase}_#{method.to_s.downcase}"
257: id_string = id_string + "_#{options[:radio_value].rubify}".gsub(/_$/, "") if options[:radio_label]
258: label_id = id_string + "_" + "label"
259: class_name = options[:input_type] + "_label"
260: ret = content_tag(:label, :for => id_string, :id => label_id, :class => class_name) do
261: "#{human_name}#{":" unless options[:radio_label]} #{"*" if options[:required] == true }"
262: end
263: ret << tag(:br) if options[:break_after_label]
264: ret
265: end
# File vendor/plugins/super_inplace_controls/lib/custom_helpers.rb, line 246
246: def set_class_name(options, type)
247: options.merge!({:class => "input_#{type}" })
248: end