From c4dc7a2735cb214d8b89cea901d97b755f8b985c Mon Sep 17 00:00:00 2001 From: Alberto Vena Date: Thu, 10 Jan 2013 15:02:02 +0100 Subject: [PATCH] refactor payment gateway forms in frontend+backend Fixes #2418 --- .../assets/javascripts/admin/payments/new.js | 11 ++++++++-- .../javascripts/store/checkout.js.coffee | 7 +++++++ .../payments/source_forms/_gateway.html.erb | 20 +++++++++---------- .../spree/checkout/payment/_gateway.html.erb | 12 +++++------ core/config/locales/en.yml | 1 - 5 files changed, 32 insertions(+), 19 deletions(-) diff --git a/core/app/assets/javascripts/admin/payments/new.js b/core/app/assets/javascripts/admin/payments/new.js index bf164dd38aa..c633f6eb40d 100644 --- a/core/app/assets/javascripts/admin/payments/new.js +++ b/core/app/assets/javascripts/admin/payments/new.js @@ -1,9 +1,16 @@ $(document).ready(function(){ - + $("#card_new").radioControlsVisibilityOfElement('#card_form'); - + $('select.jump_menu').change(function(){ window.location = this.options[this.selectedIndex].value; }); + $('#cvv_link').click(function(event){ + window_name = 'cvv_info'; + window_options = 'left=20,top=20,width=500,height=500,toolbar=0,resizable=0,scrollbars=1'; + window.open($(this).attr('href'), window_name, window_options); + event.preventDefault(); + }); + }); \ No newline at end of file diff --git a/core/app/assets/javascripts/store/checkout.js.coffee b/core/app/assets/javascripts/store/checkout.js.coffee index ef524658f6b..92e2215d78d 100644 --- a/core/app/assets/javascripts/store/checkout.js.coffee +++ b/core/app/assets/javascripts/store/checkout.js.coffee @@ -74,6 +74,13 @@ $ -> ($ '#payment_method_' + @value).show() if @checked ) + ($ '#cvv_link').live('click', (event) -> + window_name = 'cvv_info' + window_options = 'left=20,top=20,width=500,height=500,toolbar=0,resizable=0,scrollbars=1' + window.open(($ this).attr('href'), window_name, window_options) + event.preventDefault() + ) + # Activate already checked payment method if form is re-rendered # i.e. if user enters invalid data ($ 'input[type="radio"]:checked').click() diff --git a/core/app/views/spree/admin/payments/source_forms/_gateway.html.erb b/core/app/views/spree/admin/payments/source_forms/_gateway.html.erb index d3e8626ae85..d84b733a90f 100644 --- a/core/app/views/spree/admin/payments/source_forms/_gateway.html.erb +++ b/core/app/views/spree/admin/payments/source_forms/_gateway.html.erb @@ -9,7 +9,7 @@
<%= image_tag 'credit_cards/credit_card.gif', :id => 'credit-card-image' %>
- + <% param_prefix = "payment_source[#{payment_method.id}]" %>
@@ -17,8 +17,8 @@
- <%= label_tag nil, raw(t(:card_number) + content_tag(:span, ' *', :class => 'required')) %> - <%= text_field_tag "#{param_prefix}[number]", '', :class => 'required fullwidth', :maxlength => 19 %> + <%= label_tag 'card_number', raw(t(:card_number) + content_tag(:span, ' *', :class => 'required')) %> + <%= text_field_tag "#{param_prefix}[number]", '', :class => 'required fullwidth', :id => 'card_number', :maxlength => 19 %>
- <%= label_tag nil, raw(t(:expiration) + content_tag(:span, ' *', :class => 'required')) %>
- <%= select_month(Date.today, :prefix => param_prefix, :field_name => 'month', :use_month_numbers => true, :class => 'required select2') %> - <%= select_year(Date.today, :prefix => param_prefix, :field_name => 'year', :start_year => Date.today.year, :end_year => Date.today.year + 15, :class => 'required select2') %> + <%= label_tag 'card_month', raw(t(:expiration) + content_tag(:span, ' *', :class => 'required')) %>
+ <%= select_month(Date.today, { :prefix => param_prefix, :field_name => 'month', :use_month_numbers => true }, :class => 'required select2', :id => 'card_month') %> + <%= select_year(Date.today, { :prefix => param_prefix, :field_name => 'year', :start_year => Date.today.year, :end_year => Date.today.year + 15 }, :class => 'required select2', :id => 'card_year') %>
- <%= label_tag nil, raw(t(:card_code) + content_tag(:span, ' *', :class => "required")) %> - <%= text_field_tag "#{param_prefix}[verification_value]", '', :class => 'required fullwidth', :size => 5 %> - - (<%= t(:whats_this) %>) + <%= label_tag 'card_code', raw(t(:card_code) + content_tag(:span, ' *', :class => "required")) %> + <%= text_field_tag "#{param_prefix}[verification_value]", '', :class => 'required fullwidth', :size => 5, :id => 'card_code' %> + + (<%= t(:whats_is_this) %>)
diff --git a/core/app/views/spree/checkout/payment/_gateway.html.erb b/core/app/views/spree/checkout/payment/_gateway.html.erb index 2d76c1326d9..70245d03c2b 100644 --- a/core/app/views/spree/checkout/payment/_gateway.html.erb +++ b/core/app/views/spree/checkout/payment/_gateway.html.erb @@ -2,7 +2,7 @@ <% param_prefix = "payment_source[#{payment_method.id}]" %>

- <%= label_tag nil, t(:card_number) %>*
+ <%= label_tag "card_number", t(:card_number) %>*
<% options_hash = Rails.env.production? ? {:autocomplete => 'off'} : {} %> <%= text_field_tag "#{param_prefix}[number]", '', options_hash.merge(:id => 'card_number', :class => 'required', :size => 19, :maxlength => 19, :autocomplete => "off") %>   @@ -13,14 +13,14 @@

- <%= label_tag nil, t(:expiration) %>*
- <%= select_month(Date.today, { :prefix => param_prefix, :field_name => 'month', :use_month_numbers => true }, :class => 'required') %> - <%= select_year(Date.today, { :prefix => param_prefix, :field_name => 'year', :start_year => Date.today.year, :end_year => Date.today.year + 15 }, :class => 'required') %> + <%= label_tag "card_month", t(:expiration) %>*
+ <%= select_month(Date.today, { :prefix => param_prefix, :field_name => 'month', :use_month_numbers => true }, :class => 'required', :id => "card_month") %> + <%= select_year(Date.today, { :prefix => param_prefix, :field_name => 'year', :start_year => Date.today.year, :end_year => Date.today.year + 15 }, :class => 'required', :id => "card_year") %>

- <%= label_tag nil, t(:card_code) %>*
+ <%= label_tag "card_code", t(:card_code) %>*
<%= text_field_tag "#{param_prefix}[verification_value]", '', options_hash.merge(:id => 'card_code', :class => 'required', :size => 5) %> - <%= link_to "(#{t(:whats_this)})", spree.content_path('cvv'), :target => '_blank', :onclick => "window.open(this.href,'cvv_info','left=20,top=20,width=500,height=500,toolbar=0,resizable=0,scrollbars=1');return false", "data-hook" => "cvv_link" %> + <%= link_to "(#{t(:what_is_this)})", spree.content_path('cvv'), :target => '_blank', "data-hook" => "cvv_link", :id => "cvv_link" %>

<%= hidden_field param_prefix, 'first_name', :value => @order.billing_firstname %> <%= hidden_field param_prefix, 'last_name', :value => @order.billing_lastname %> diff --git a/core/config/locales/en.yml b/core/config/locales/en.yml index 14c70acf021..0868c5eeb7d 100644 --- a/core/config/locales/en.yml +++ b/core/config/locales/en.yml @@ -1139,7 +1139,6 @@ en: welcome_to_sample_store: "Welcome to the sample store" what_is_a_cvv: "What is a (CVV) Credit Card Code?" what_is_this: "What's This?" - whats_this: "What's this" width: Width year: Year you_have_been_logged_out: "You have been logged out."