Sha256: 7576922197b88d2a9ced2d158ab5c56f6ca2abdcf57a299ba09bf709e9d3632d

Contents?: true

Size: 1.38 KB

Versions: 11

Compression:

Stored size: 1.38 KB

Contents

function SpreeDeliveryOptionsForm() {

  var that = this;

  this.initializeForm = function() {
     var formUrl = $('#delivery-options-form').attr('action');

     $("#delivery-options-form input[type='submit']").click(function(event){
       event.preventDefault();

       var formData = $('#delivery-options-form').serialize();
       $.post(
         formUrl,
         formData,
         function(data) {
           if (data.delivery_date !== null) {
             location.reload();
           } else {
             that.showErrorMessage("Please enter a valid date.");
           }
         }).fail(function(data){
           if (data.responseJSON.errors.delivery_date !== undefined) {
             that.showErrorMessage(data.responseJSON.errors.delivery_date[0]);
           } else if (data.responseJSON.errors.delivery_time !== undefined) {
             that.showErrorMessage(data.responseJSON.errors.delivery_time[0]);
           } else {
             that.showErrorMessage("We could not update the delivery date. Please try at checkout.");
           }
         });
     });
  };

  this.showErrorMessage = function(message) {
    $('#delivery-options-homepage .error').html("<h5>" + message + "</h5>");
    $('#delivery-options-homepage .error').show();
  };

}

$(document).ready(function() {
  var deliveryOptionsForm = new SpreeDeliveryOptionsForm();
  deliveryOptionsForm.initializeForm();
});

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
spree_delivery_options-2.2.11 app/assets/javascripts/spree/frontend/delivery_options_form.js
spree_delivery_options-2.2.10 app/assets/javascripts/spree/frontend/delivery_options_form.js
spree_delivery_options-2.2.8 app/assets/javascripts/spree/frontend/delivery_options_form.js
spree_delivery_options-2.2.7 app/assets/javascripts/spree/frontend/delivery_options_form.js
spree_delivery_options-2.2.6 app/assets/javascripts/spree/frontend/delivery_options_form.js
spree_delivery_options-2.2.5 app/assets/javascripts/spree/frontend/delivery_options_form.js
spree_delivery_options-2.2.4 app/assets/javascripts/spree/frontend/delivery_options_form.js
spree_delivery_options-2.2.3 app/assets/javascripts/store/delivery_options_form.js
spree_delivery_options-2.2.2 app/assets/javascripts/store/delivery_options_form.js
spree_delivery_options-2.2.1 app/assets/javascripts/store/delivery_options_form.js
spree_delivery_options-2.2.0 app/assets/javascripts/store/delivery_options_form.js