diff options
author | Azul <azul@leap.se> | 2014-04-23 14:58:30 +0200 |
---|---|---|
committer | Azul <azul@leap.se> | 2014-04-25 12:18:40 +0200 |
commit | 689c10b618c6c469ce82a7f09e117567def577de (patch) | |
tree | 2e0d37efb7821ac65f03056a28366809c786d50d /lib | |
parent | 76ad25ba0ee344f185f8e8cdfe066685cd3b0447 (diff) |
simple form: add wrapped and loading... buttons #5542
the loading... text on the buttons was not capitalized before.
So in order to change this in a (more or less) single place i added
new button types to simple_form:
button :wrapped - normal button, with loading and an optional cancel button wrapped in the classical bootstrap action div.
cancel option contains the url to go to when canceling.
button :loading - simple button with loading text capitalized by using i18n (simple_form.buttons.loading)
Conflicts:
engines/support/app/views/tickets/new.html.haml
Diffstat (limited to 'lib')
-rw-r--r-- | lib/extensions/simple_form.rb | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/lib/extensions/simple_form.rb b/lib/extensions/simple_form.rb new file mode 100644 index 0000000..f28e18f --- /dev/null +++ b/lib/extensions/simple_form.rb @@ -0,0 +1,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 |