Module: JqueryUiForm::Helpers::ButtonHelper

Included in:
FormBuilder
Defined in:
lib/jquery_ui_form/helpers/button_helper.rb

Instance Method Summary collapse

Instance Method Details

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



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/jquery_ui_form/helpers/button_helper.rb', line 5

def button(name, options = {})
  if use_i18n && !options.delete(:translate)
    name = I18n.t(name)
  elsif name == name.to_sym
    name = name.to_s.upcase.humanize
  end
  (options[:class] ||= "") << " ui-button"
  options[:type] ||= "submit"
  
  if (icon = options.delete(:icon)) 
    options["data-icon"] = "ui-icon-#{icon}"
  end
  template.button_tag(name, options)
end

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



28
29
30
31
32
33
34
35
# File 'lib/jquery_ui_form/helpers/button_helper.rb', line 28

def cancel(name=nil, options = {})
  options.merge!(name) && name = nil  if name.is_a?(Hash)
  options[:type] ||= "reset"
  options[:icon] ||= "close"
  (options[:class] ||= "") << " ui-state-error"
  name ||= :cancel
  button(name, options)
end

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



20
21
22
23
24
25
26
# File 'lib/jquery_ui_form/helpers/button_helper.rb', line 20

def submit(name=nil, options = {})
  options.merge!(name) && name = nil if name.is_a?(Hash)
  options[:type] ||= "submit"
  options[:icon] ||= "check"
  name ||= (@object && @object.respond_to?(:new_record?) && @object.new_record? ? :create : :update )
  button(name, options)
end