Sha256: f4b6d606d242e4db6abf36bfc7ec6e3ff0d655bd42ae1c985c803bd800b2a021

Contents?: true

Size: 1.08 KB

Versions: 82

Compression:

Stored size: 1.08 KB

Contents

Spree.Views.Order.Address = Backbone.View.extend({
  initialize: function(options) {
    // read initial values from page
    this.onChange();

    this.stateSelect =
      new Spree.Views.StateSelect({
        model: this.model,
        el: this.$el
      });

    this.render();
    this.listenTo(this.model, "change", this.render);
  },

  events: {
    "change": "onChange",
  },

  onChange: function() {
    this.model.set(this.getValues())
  },

  eachField: function(callback){
    var view = this;
    var fields = ["name", "company", "address1", "address2",
      "city", "zipcode", "phone", "country_id", "state_name"];
    _.each(fields, function(field) {
      var el = view.$('[name$="[' + field + ']"]');
      if (el.length) callback(field, el);
    });
  },

  getValues: function() {
    var attributes = {};
    this.eachField(function(name, el) {
      attributes[name] = el.val();
    });
    return attributes;
  },

  render: function() {
    var model = this.model;
    this.eachField(function(name, el) {
      el.val(model.get(name))
    });

    this.stateSelect.render();
  }
});

Version data entries

82 entries across 82 versions & 1 rubygems

Version Path
solidus_backend-4.4.2 app/assets/javascripts/spree/backend/views/order/address.js
solidus_backend-4.4.1 app/assets/javascripts/spree/backend/views/order/address.js
solidus_backend-4.4.0 app/assets/javascripts/spree/backend/views/order/address.js
solidus_backend-4.3.4 app/assets/javascripts/spree/backend/views/order/address.js
solidus_backend-4.2.4 app/assets/javascripts/spree/backend/views/order/address.js
solidus_backend-4.1.5 app/assets/javascripts/spree/backend/views/order/address.js
solidus_backend-4.3.3 app/assets/javascripts/spree/backend/views/order/address.js
solidus_backend-4.3.2 app/assets/javascripts/spree/backend/views/order/address.js
solidus_backend-4.1.4 app/assets/javascripts/spree/backend/views/order/address.js
solidus_backend-4.3.1 app/assets/javascripts/spree/backend/views/order/address.js
solidus_backend-4.3.0 app/assets/javascripts/spree/backend/views/order/address.js
solidus_backend-4.2.3 app/assets/javascripts/spree/backend/views/order/address.js
solidus_backend-4.1.3 app/assets/javascripts/spree/backend/views/order/address.js
solidus_backend-4.0.4 app/assets/javascripts/spree/backend/views/order/address.js
solidus_backend-3.4.6 app/assets/javascripts/spree/backend/views/order/address.js
solidus_backend-4.0.3 app/assets/javascripts/spree/backend/views/order/address.js
solidus_backend-4.1.2 app/assets/javascripts/spree/backend/views/order/address.js
solidus_backend-4.2.2 app/assets/javascripts/spree/backend/views/order/address.js
solidus_backend-3.4.5 app/assets/javascripts/spree/backend/views/order/address.js
solidus_backend-4.2.1 app/assets/javascripts/spree/backend/views/order/address.js