Sha256: 162e278322ba12a812dff72034e605788189b51f1791b054f7ad4712073c367d

Contents?: true

Size: 1.94 KB

Versions: 24

Compression:

Stored size: 1.94 KB

Contents

APP.features.checkout = {
  config: {
    $billingProvince: $("#billing_address_province_id"),
    $billingCountry: $("#billing_address_country_id"),
    $shippingProvince: $("#shipping_address_province_id"),
    $shippingCountry: $("#shipping_address_country_id")
  },
  
  init: function (options) {
    var self = APP.features.checkout;
    $.extend(self.config, options);
    self.updateProvincesForSelectedCountry(self.config.$billingProvince, self.config.$billingCountry);
    self.updateProvincesForSelectedCountry(self.config.$shippingProvince, self.config.$shippingCountry);
    
    self.config.$billingCountry.on('change', function() { self.updateProvincesForSelectedCountry(self.config.$billingProvince, self.config.$billingCountry) });
    self.config.$shippingCountry.on('change', function() { self.updateProvincesForSelectedCountry(self.config.$shippingProvince, self.config.$shippingCountry) });
    self.toggleShippingAddressField();
  },
  
  updateProvincesForSelectedCountry: function (provinceElement, countryElement) {
    var self = APP.features.checkout;
    
    $.getJSON('/countries/' + countryElement.val() + '/get_provinces_for_checkout.js', function(data) {
      province_element.html(self.createOptionsFromJSON(data, provinceElement.val())); 
    });
  },
  
  createOptionsFromJSON: function (data, currentVal) {
    var html = "";
    var selected = "";
    $.each(data, function(index, element) {
      selected = element[1] == currentVal ? " selected='selected'" : "";
      html += "<option value='" + element[1] + selected + "'>" + element[0] + "</option>\n";
    });
    return html;
  },
  
  toggleShippingAddressField: function () {
    if($("#use_billing_for_shipping").is(":checked")) {
      $('.shipping_address').hide();
    };

    $('#use_billing_for_shipping').change(function() {
      if($(this).is(":checked")) {
        $('.shipping_address').hide();
      } else {
        $('.shipping_address').show();
      }  
    });
  }
}

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
forge-cli-0.1.10 lib/forge/app/assets/javascripts/features/checkout.js
forge-cli-0.1.9 lib/forge/app/assets/javascripts/features/checkout.js
forge-cli-0.1.8 lib/forge/app/assets/javascripts/features/checkout.js
forge-cli-0.1.7 lib/forge/app/assets/javascripts/features/checkout.js
forge-cli-0.1.6 lib/forge/app/assets/javascripts/features/checkout.js
forge-cli-0.1.5 lib/forge/app/assets/javascripts/features/checkout.js
forge-cli-0.1.4 lib/forge/app/assets/javascripts/features/checkout.js
forge-cli-0.1.3 lib/forge/app/assets/javascripts/features/checkout.js
forge-cli-0.1.2 lib/forge/app/assets/javascripts/features/checkout.js
forge-cli-0.1.1 lib/forge/app/assets/javascripts/features/checkout.js
forge-cli-0.1.0 lib/forge/app/assets/javascripts/features/checkout.js
forge-cli-0.0.18 lib/forge/app/assets/javascripts/features/checkout.js
forge-cli-0.0.17 lib/forge/app/assets/javascripts/features/checkout.js
forge-cli-0.0.16 lib/forge/app/assets/javascripts/features/checkout.js
forge-cli-0.0.15 lib/forge/app/assets/javascripts/features/checkout.js
forge-cli-0.0.14 lib/forge/app/assets/javascripts/features/checkout.js
forge-cli-0.0.13 lib/forge/app/assets/javascripts/features/checkout.js
forge-cli-0.0.12 lib/forge/app/assets/javascripts/features/checkout.js
forge-cli-0.0.11 lib/forge/app/assets/javascripts/features/checkout.js
forge-cli-0.0.10 lib/forge/app/assets/javascripts/features/checkout.js