Permalink
Browse files

more updates for spree 1.0.x

  • Loading branch information...
1 parent ebdd983 commit 447a55152e99e43ecf3da223f4e31946b0b9c92b @devilcoders devilcoders committed Feb 8, 2012
@@ -1,83 +1,78 @@
(function($){
$(document).ready(function(){
+ if($('#checkout_form_payment').is('*')){
- //$('#checkout_form_address').validate();
+ $('#checkout_form_payment').validate();
- var get_states = function(region){
- var country = $('span#' + region + 'country :only-child').val();
- return state_mapper[country];
- }
-
- var update_state = function(region) {
- var states = get_states(region);
-
- var state_select = $('span#' + region + 'state select');
- var state_input = $('span#' + region + 'state input');
-
- if(states) {
- var selected = state_select.val();
- state_select.html('');
- var states_with_blank = [["",""]].concat(states);
- $.each(states_with_blank, function(pos,id_nm) {
- var opt = $(document.createElement('option'))
- .attr('value', id_nm[0])
- .html(id_nm[1]);
- if(selected==id_nm[0]){
- opt.attr('selected', 'selected');
- }
- state_select.append(opt);
- });
- state_select.removeAttr('disabled').show();
- state_input.hide().attr('disabled', 'disabled');
-
- } else {
- state_input.removeAttr('disabled').show();
- state_select.hide().attr('disabled', 'disabled');
+ var get_states = function(region){
+ country = $('p#' + region + 'country' + ' span#' + region + 'country :only-child').val();
+ return state_mapper[country];
}
- };
-
- var show_payment_method = function(){
- $('li.payment_method').hide();
- var id = $("input[name='order[payments_attributes][][payment_method_id]']:checked").val()
-
- $('li.payment_method.' + id).show();
- }
-
- // Show fields for the selected payment method
- $("input[type='radio'][name='order[payments_attributes][][payment_method_id]']").change(function(){
- show_payment_method();
- })
-
- $('span#bcountry select').change(function() { update_state('b'); });
- $('span#scountry select').change(function() { update_state('s'); });
- update_state('b');
- update_state('s');
- show_payment_method()
-
- $('input#order_use_billing').click(function() {
- if($(this).is(':checked')) {
- $('#shipping .inner').hide();
- $('#shipping .inner input, #shipping .inner select').attr('disabled', 'disabled');
- } else {
- $('#shipping .inner').show();
- $('#shipping .inner input, #shipping .inner select').removeAttr('disabled', 'disabled');
-
- //only want to enable relevant field
- if(get_states('s')){
- $('span#sstate input').hide().attr('disabled', 'disabled');
- }else{
- $('span#sstate select').hide().attr('disabled', 'disabled');
+ var update_state = function(region) {
+ states = get_states(region);
+
+ state_select = $('p#' + region + 'state select');
+ state_input = $('p#' + region + 'state input');
+
+ if(states) {
+ selected = state_select.val();
+ state_select.html('');
+ states_with_blank = [["",""]].concat(states);
+ $.each(states_with_blank, function(pos,id_nm) {
+ var opt = $(document.createElement('option'))
+ .attr('value', id_nm[0])
+ .html(id_nm[1]);
+ if(selected==id_nm[0]){
+ opt.prop("selected", true);
+ }
+ state_select.append(opt);
+ });
+ state_select.prop("disabled", false).show();
+ state_input.hide().prop("disabled", true);
+
+ } else {
+ state_input.prop("disabled", false).show();
+ state_select.hide().prop("disabled", true);
}
- }
- }).triggerHandler('click');
-
- $('form.edit_checkout').submit(function() {
- $(this).find(':submit, :image').attr('disabled', true).removeClass('primary').addClass('disabled');
- });
+ };
+
+ $('p#bcountry select').change(function() { update_state('b'); });
+ $('p#scountry select').change(function() { update_state('s'); });
+ update_state('b');
+ update_state('s');
+
+ $('input#order_use_billing').click(function() {
+ if($(this).is(':checked')) {
+ $('#shipping .inner').hide();
+ $('#shipping .inner input, #shipping .inner select').prop("disabled", true);
+ } else {
+ $('#shipping .inner').show();
+ $('#shipping .inner input, #shipping .inner select').prop("disabled", false);
+ //only want to enable relevant field
+ if(get_states('s')){
+ $('span#sstate input').hide().prop("disabled", true);
+ }else{
+ $('span#sstate select').hide().prop("disabled", true);
+ }
+ }
+ }).triggerHandler('click');
+ }
+ if($('#checkout_form_payment').is('*')){
+ // Show fields for the selected payment method
+ $("input[type='radio'][name='order[payments_attributes][][payment_method_id]']").click(function(){
+ $('#payment-methods li').hide();
+ if(this.checked){ $('#payment_method_'+this.value).show(); }
+ }).triggerHandler('click');
+ }
});
})(jQuery);
+function disableSaveOnClick() {
+ $('form.edit_spree_order').submit(function() {
+ $(this).find(':submit, :image').attr('disabled', true).removeClass('primary').addClass('disabled');
+ });
+}
Oops, something went wrong.

0 comments on commit 447a551

Please sign in to comment.