Module: RightRails::Helpers::Forms::Util

Defined in:
lib/right_rails/helpers/forms.rb

Overview

Local utility methods, just hidding the things in here so they didn’t pollute the global scope

Class Method Summary collapse

Class Method Details

.autocompleter_options(context, options = {}) ⇒ Object

Prepares the autocompleter field options hash



192
193
194
195
196
197
198
199
200
201
202
203
# File 'lib/right_rails/helpers/forms.rb', line 192

def autocompleter_options(context, options={})
  require_modules(context, 'autocompleter')

  options[:url] = context.escape_javascript(context.url_for(options[:url]))

  url = options.delete(:url) if in_rightjs_1

  options = unit_options(options, 'autocompleter').merge({:autocomplete => 'off'})
  options.merge!({:rel => "autocompleter[#{url}]"})  if in_rightjs_1

  options
end

.calendar_options(context, options = {}) ⇒ Object

Prepares a list of options for the calendar widget



184
185
186
187
# File 'lib/right_rails/helpers/forms.rb', line 184

def calendar_options(context, options={})
  require_modules(context, 'calendar')
  unit_options(options, 'calendar').merge(in_rightjs_1 ? {:rel => 'calendar'} : {})
end

.colorpicker_options(context, options) ⇒ Object

Prepares the Colorpicker widget options



248
249
250
251
# File 'lib/right_rails/helpers/forms.rb', line 248

def colorpicker_options(context, options)
  require_modules context, 'colorpicker'
  unit_options(options, 'colorpicker').merge(in_rightjs_1 ? {:rel => 'colorpicker'} : {})
end

.in_rightjs_1Object

Checks if we are in the RightJS 1 mode



177
178
179
# File 'lib/right_rails/helpers/forms.rb', line 177

def in_rightjs_1
  RightRails::Config.rightjs_version < 2
end

.rater_generator(context, name, value, options, method = nil) ⇒ Object

Generates the rater initialization script



236
237
238
239
240
241
242
243
# File 'lib/right_rails/helpers/forms.rb', line 236

def rater_generator(context, name, value, options, method=nil)
  value ||= ActionView::Helpers::InstanceTag.value_before_type_cast(
    context.instance_variable_get("@#{name}"), method.to_s) if method
  name    = "#{name}[#{method}]" if method
  id      = options[:id] || context.send(:sanitize_to_id, name)
  options = RightRails::Helpers.unit_options(options.merge(:value => value), 'rater')
  context.javascript_tag "new Rater(#{options}).insertTo('#{id}','after').assignTo('#{id}');"
end

.rater_options(context, options) ⇒ Object

Prepares the rater widget options



228
229
230
231
# File 'lib/right_rails/helpers/forms.rb', line 228

def rater_options(context, options)
  require_modules context, 'rater'
  RightRails::Helpers.remove_unit_options(options, 'rater')
end

.require_modules(context, *list) ⇒ Object

Requires RightJS modules in the given context



163
164
165
# File 'lib/right_rails/helpers/forms.rb', line 163

def require_modules(context, *list)
  RightRails::Helpers.require_js_module context, *list
end

.rte_options(context, options) ⇒ Object

Prepares the RTE widget options



264
265
266
267
# File 'lib/right_rails/helpers/forms.rb', line 264

def rte_options(context, options)
  require_modules context, 'rte'
  unit_options(options, 'rte')
end

.slider_generator(context, name, value, options, method = nil) ⇒ Object

Generates the slider initialization script



216
217
218
219
220
221
222
223
# File 'lib/right_rails/helpers/forms.rb', line 216

def slider_generator(context, name, value, options, method=nil)
  value ||= ActionView::Helpers::InstanceTag.value_before_type_cast(
    context.instance_variable_get("@#{name}"), method.to_s ) if method
  name    = "#{name}[#{method}]" if method
  id      = options[:id] || context.send(:sanitize_to_id, name)
  options = RightRails::Helpers.unit_options(options.merge(:value => value), 'slider')
  context.javascript_tag "new Slider(#{options}).insertTo('#{id}','after').assignTo('#{id}');"
end

.slider_options(context, options) ⇒ Object

Prepares the list of slider options



208
209
210
211
# File 'lib/right_rails/helpers/forms.rb', line 208

def slider_options(context, options)
  require_modules context, 'dnd', 'slider'
  RightRails::Helpers.remove_unit_options(options, 'slider')
end

.tags_options(context, options) ⇒ Object

Prepares the Tags widget options



256
257
258
259
# File 'lib/right_rails/helpers/forms.rb', line 256

def tags_options(context, options)
  require_modules context, 'tags'
  unit_options(options, 'tags').merge(in_rightjs_1 ? {:rel => 'tags'} : {})
end

.unit_options(options, unit) ⇒ Object

Preprocesses the RightJS module options



170
171
172
# File 'lib/right_rails/helpers/forms.rb', line 170

def unit_options(options, unit)
  RightRails::Helpers.add_unit_options(options, unit)
end