summaryrefslogtreecommitdiff
path: root/lib/extensions/simple_form.rb
blob: f28e18f8d759ee7022b6b44c8b9a3898c640f7a9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
module WrappedButton
  def wrapped_button(*args, &block)
    template.content_tag :div, :class => "form-actions" do
      options = args.extract_options!
      options[:class] = ['btn-primary', options[:class]].compact
      args.unshift :loading
      args << options
      if cancel = options.delete(:cancel)
        cancel_link = template.link_to I18n.t('simple_form.buttons.cancel'),
          cancel, class: :btn
        button(*args, &block) + ' ' + cancel_link
      else
        button(*args, &block)
      end
    end
  end
end
SimpleForm::FormBuilder.send :include, WrappedButton

module LoadingButton
  def loading_button(*args, &block)
    options = args.extract_options!
    options[:"data-loading-text"] = I18n.t('simple_form.buttons.loading')
    args << options
    button_button(*args, &block)
  end
end
SimpleForm::FormBuilder.send :include, LoadingButton