summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAzul <azul@leap.se>2014-04-23 14:58:30 +0200
committerAzul <azul@leap.se>2014-04-25 12:18:40 +0200
commit689c10b618c6c469ce82a7f09e117567def577de (patch)
tree2e0d37efb7821ac65f03056a28366809c786d50d
parent76ad25ba0ee344f185f8e8cdfe066685cd3b0447 (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
-rw-r--r--app/views/sessions/new.html.haml4
-rw-r--r--app/views/users/new.html.haml4
-rw-r--r--config/initializers/simple_form.rb2
-rw-r--r--config/locales/simple_form.en.yml3
-rw-r--r--engines/support/app/views/tickets/_new_comment_form.html.haml4
-rw-r--r--engines/support/app/views/tickets/_tabs.html.haml4
-rw-r--r--engines/support/app/views/tickets/new.html.haml7
-rw-r--r--lib/extensions/simple_form.rb28
8 files changed, 40 insertions, 16 deletions
diff --git a/app/views/sessions/new.html.haml b/app/views/sessions/new.html.haml
index 316eec1..6f3b324 100644
--- a/app/views/sessions/new.html.haml
+++ b/app/views/sessions/new.html.haml
@@ -6,6 +6,4 @@
= simple_form_for [:api, @session], :validate => true, :html => { :id => :new_session, :class => 'form-horizontal' } do |f|
= f.input :login, :required => false, :label => t(:username), :input_html => { :id => :srp_username }
= f.input :password, :required => false, :input_html => { :id => :srp_password }
- .form-actions
- = f.button :submit, :value => t(:login), :class => 'btn-primary'
- = link_to t(:cancel), home_path, :class => 'btn'
+ = f.button :wrapped, value: t(:login), cancel: home_path
diff --git a/app/views/users/new.html.haml b/app/views/users/new.html.haml
index 173dd8c..3478989 100644
--- a/app/views/users/new.html.haml
+++ b/app/views/users/new.html.haml
@@ -13,7 +13,5 @@
= f.input :login, :label => t(:username), :required => false, :input_html => { :id => :srp_username }
= f.input :password, :required => false, :validate => true, :input_html => { :id => :srp_password }
= f.input :password_confirmation, :required => false, :validate => true, :input_html => { :id => :srp_password_confirmation }
- .form-actions
- = f.button :submit, :value => t(:signup), :class => 'btn btn-primary'
- = link_to t(:cancel), home_path, :class => 'btn'
+ = f.button :wrapped, value: t(:signup), cancel: home_path
diff --git a/config/initializers/simple_form.rb b/config/initializers/simple_form.rb
index e3f8d09..710dacc 100644
--- a/config/initializers/simple_form.rb
+++ b/config/initializers/simple_form.rb
@@ -1,3 +1,5 @@
+require 'extensions/simple_form'
+
# Use this setup block to configure all options available in SimpleForm.
SimpleForm.setup do |config|
# Wrappers are used by the form builder to generate a
diff --git a/config/locales/simple_form.en.yml b/config/locales/simple_form.en.yml
index 0df11fe..4beeb7d 100644
--- a/config/locales/simple_form.en.yml
+++ b/config/locales/simple_form.en.yml
@@ -10,6 +10,9 @@ en:
# html: '<abbr title="required">*</abbr>'
error_notification:
default_message: "Please review the problems below:"
+ buttons:
+ cancel: 'Cancel'
+ loading: 'Loading...'
# Labels and hints examples
# labels:
# defaults:
diff --git a/engines/support/app/views/tickets/_new_comment_form.html.haml b/engines/support/app/views/tickets/_new_comment_form.html.haml
index 8418e01..40c737f 100644
--- a/engines/support/app/views/tickets/_new_comment_form.html.haml
+++ b/engines/support/app/views/tickets/_new_comment_form.html.haml
@@ -7,7 +7,7 @@
= c.input :body, :label => false, :as => :text, :input_html => {:class => "full-width", :rows=> 5}
- if admin?
= c.input :private, :as => :boolean, :label => false, :inline_label => true
- = f.button :button, t(:post_reply), :name => 'commit', :class => 'btn-primary', :type => 'submit', :value => 'post_reply'
+ = f.button :loading, t(:post_reply), class: 'btn-primary', value: 'post_reply'
- if logged_in? && @ticket.is_open
- = f.button :button, t(:reply_and_close), :name => 'commit', :class => 'btn', :type => 'submit', :value => 'reply_and_close'
+ = f.button :loading, t(:reply_and_close), value: 'reply_and_close'
= link_to t(:cancel), auto_tickets_path, :class => :btn
diff --git a/engines/support/app/views/tickets/_tabs.html.haml b/engines/support/app/views/tickets/_tabs.html.haml
index b7b5d3a..445a909 100644
--- a/engines/support/app/views/tickets/_tabs.html.haml
+++ b/engines/support/app/views/tickets/_tabs.html.haml
@@ -1,7 +1,7 @@
-#
-# SORT ORDER TABS
-#
-- unless action?(:new)
+- unless action?(:new) or action?(:create)
%ul.nav.nav-pills.pull-right.slim
%li{:class=> ("active" if search_order.start_with? 'created_at')}
= link_to_order('created')
@@ -19,5 +19,5 @@
= link_to_status 'closed'
%li{:class => ("active" if search_status == 'all')}
= link_to_status 'all'
- %li{:class => ("active" if action?(:new))}
+ %li{:class => ("active" if action?(:new) || action?(:create))}
= link_to icon(:plus, :black) + t(:new_ticket), auto_new_ticket_path
diff --git a/engines/support/app/views/tickets/new.html.haml b/engines/support/app/views/tickets/new.html.haml
index 65ed67b..ab008d2 100644
--- a/engines/support/app/views/tickets/new.html.haml
+++ b/engines/support/app/views/tickets/new.html.haml
@@ -14,9 +14,4 @@
= c.input :body, :label => t(:description), :as => :text, :input_html => {:class => "full-width", :rows=> 5}
- if admin?
= c.input :private, :as => :boolean, :label => false, :inline_label => true
- .form-actions
- = f.button :submit, :class => 'btn-primary', :value => t(:create_thing, :thing => t(:ticket))
- - if logged_in?
- = link_to t(:cancel), auto_tickets_path, :class => :btn
- - else
- = link_to t(:cancel), home_path, :class => 'btn'
+ = f.button :wrapped, cancel: (logged_in? ? auto_tickets_path : home_path)
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