Fix js for switching form partial for new admin payments

All of the functional changes made in this commit came from a future version of Spree:
8a3a80b08a
This commit is contained in:
Rob Harrington
2017-08-02 15:36:33 +10:00
parent 2f6493bb86
commit a04116466e
3 changed files with 125 additions and 0 deletions

View File

@@ -0,0 +1,33 @@
// Override of Spree's logic in the file of the same name
// Changes made as per https://github.com/spree/spree/commit/8a3a80b08abf80fbed2fcee4b429ba1caf68baf1
// which allows the form partial in admin/payments/new to be switched using radio buttons
// We can remove this file when we reach 2.3.0
$(document).ready(function() {
if ($("#new_payment").is("*")) {
$('.payment_methods_radios').click(
function() {
$('.payment-methods').hide();
if (this.checked) {
$('#payment_method_' + this.value).show();
}
}
);
$('.payment_methods_radios').each(
function() {
if (this.checked) {
$('#payment_method_' + this.value).show();
} else {
$('#payment_method_' + this.value).hide();
}
}
);
$(".card_new").radioControlsVisibilityOfElement('.card_form');
$('select.jump_menu').change(function(){
window.location = this.options[this.selectedIndex].value;
});
}
});

View File

@@ -0,0 +1,34 @@
<div data-hook="admin_payment_form_fields" class="row">
<div class="alpha three columns">
<div class="field">
<%= f.label :amount, t(:amount) %>
<%= f.text_field :amount, :value => @order.outstanding_balance, :class => 'fullwidth' %>
</div>
</div>
<div class="omega nine columns">
<div class="field">
<label><%= t(:payment_method) %></label>
<ul>
<% @payment_methods.each do |method| %>
<li>
<label data-hook="payment_method_field">
<%= radio_button_tag 'payment[payment_method_id]', method.id, method == @payment_method, { class: "payment_methods_radios" } %>
<%= t(method.name, :scope => :payment_methods, :default => method.name) %>
</label>
</li>
<% end %>
</ul>
<div class="payment-method-settings">
<% @payment_methods.each do |method| %>
<div class="payment-methods" id="payment_method_<%= method.id %>">
<% if method.source_required? %>
<br />
<%= render :partial => "spree/admin/payments/source_forms/#{method.method_type}", :locals => { :payment_method => method } %>
<% end %>
</div>
<% end %>
</div>
</div>
</div>
</div>

View File

@@ -0,0 +1,58 @@
<fieldset class="no-border-bottom">
<div class="field" data-hook="previous_cards">
<% @previous_cards.each do |card| %>
<label><%= radio_button_tag :card, card.id, card == @previous_cards.first %> <%= card.display_number %><br /></label>
<% end %>
<label><%= radio_button_tag :card, 'new', @previous_cards.none?, { class: "card_new" } %> <%= t(:use_new_cc) %></label>
</div>
<div class="card_form" data-hook>
<% param_prefix = "payment_source[#{payment_method.id}]" %>
<div class="clear"></div>
<div class="alpha four columns">
<div data-hook="card_number">
<div class="field">
<%= hidden_field_tag "#{param_prefix}[cc_type]", '', {class: 'ccType'} %>
<%= label_tag "card_number#{payment_method.id}", raw(t(:card_number) + content_tag(:span, ' *', :class => 'required')) %>
<%= text_field_tag "#{param_prefix}[number]", '', :class => 'required fullwidth cardNumber', :id => "card_number#{payment_method.id}", :maxlength => 19 %>
<span id="card_type" style="display:none;">
( <span id="looks_like" ><%= t(:card_type_is) %> <span id="type"></span></span>
<span id="unrecognized"><%= t(:unrecognized_card_type) %></span>
)
</span>
</div>
</div>
</div>
<div class="alpha four columns">
<div data-hook="card_name">
<div class="field">
<%= label_tag "card_name#{payment_method.id}", raw(t(:name) + content_tag(:span, ' *', :class => 'required')) %>
<%= text_field_tag "#{param_prefix}[name]", '', id: "card_name#{payment_method.id}", class: 'required fullwidth', maxlength: 19 %>
</div>
</div>
</div>
<div class="three columns">
<div data-hook="card_expiration" class="field">
<%= label_tag "card_expiry#{payment_method.id}", raw(t(:expiration) + content_tag(:span, ' *', :class => 'required')) %><br>
<%= text_field_tag "#{param_prefix}[expiry]", '', id: "card_expiry#{payment_method.id}", class: "required cardExpiry", placeholder: "MM / YY" %>
</div>
</div>
<div class="omega two columns">
<div data-hook="card_code" class="field">
<%= label_tag "card_code#{payment_method.id}", raw(t(:card_code) + content_tag(:span, ' *', :class => "required")) %>
<%= text_field_tag "#{param_prefix}[verification_value]", '', id: "card_code#{payment_method.id}", class: 'required fullwidth cardCode', size: 5 %>
<a href="/content/cvv" class="info cvvLink" target="_blank">
(<%= t(:what_is_this) %>)
</a>
</div>
</div>
<div class="nine columns">
<%= image_tag 'credit_cards/credit_card.gif', :class => 'credit-card-image' %>
</div>
<div class="clear"></div>
</div>
</fieldset>