Sha256: be4febb263b0cfb2374a11e16b75d360c91a72d6f8881021c7c82ead0576a79c

Contents?: true

Size: 1.38 KB

Versions: 35

Compression:

Stored size: 1.38 KB

Contents

Spree.Views.Order.CustomerSelect = Backbone.View.extend({
  initialize: function() {
    this.render();
  },

  events: {
    "select2-selecting": "onSelect"
  },

  onSelect: function(e) {
    var customer = e.choice;
    this.trigger("select", customer)
  },

  render: function() {
    var customerTemplate = HandlebarsTemplates['orders/customer_details/autocomplete'];

    var formatCustomerResult = function(customer) {
      return customerTemplate({
        customer: customer,
        bill_address: customer.bill_address,
        ship_address: customer.ship_address
      })
    }

    this.$el.select2({
      placeholder: Spree.translations.choose_a_customer,
      ajax: {
        url: Spree.routes.users_api,
        params: { "headers": { "X-Spree-Token": Spree.api_key } },
        datatype: 'json',
        data: function(term, page) {
          return {
            q: {
              m: 'or',
              email_start: term,
              addresses_firstname_start: term,
              addresses_lastname_start: term
            }
          }
        },
        results: function(data, page) {
          return {
            results: data.users,
            more: data.current_page < data.pages
          }
        }
      },
      formatResult: formatCustomerResult,
      formatSelection: function (customer) {
        return Select2.util.escapeMarkup(customer.email);
      }
    })
  }
});

Version data entries

35 entries across 35 versions & 1 rubygems

Version Path
solidus_backend-2.6.6 app/assets/javascripts/spree/backend/views/order/customer_select.js
solidus_backend-2.7.4 app/assets/javascripts/spree/backend/views/order/customer_select.js
solidus_backend-2.7.3 app/assets/javascripts/spree/backend/views/order/customer_select.js
solidus_backend-2.6.5 app/assets/javascripts/spree/backend/views/order/customer_select.js
solidus_backend-2.5.2 app/assets/javascripts/spree/backend/views/order/customer_select.js
solidus_backend-2.7.2 app/assets/javascripts/spree/backend/views/order/customer_select.js
solidus_backend-2.6.4 app/assets/javascripts/spree/backend/views/order/customer_select.js
solidus_backend-2.5.1 app/assets/javascripts/spree/backend/views/order/customer_select.js
solidus_backend-2.6.3 app/assets/javascripts/spree/backend/views/order/customer_select.js
solidus_backend-2.7.1 app/assets/javascripts/spree/backend/views/order/customer_select.js
solidus_backend-2.6.2 app/assets/javascripts/spree/backend/views/order/customer_select.js
solidus_backend-2.7.0 app/assets/javascripts/spree/backend/views/order/customer_select.js
solidus_backend-2.6.1 app/assets/javascripts/spree/backend/views/order/customer_select.js
solidus_backend-2.6.0 app/assets/javascripts/spree/backend/views/order/customer_select.js
solidus_backend-2.6.0.rc1 app/assets/javascripts/spree/backend/views/order/customer_select.js
solidus_backend-2.5.0 app/assets/javascripts/spree/backend/views/order/customer_select.js
solidus_backend-2.5.0.rc1 app/assets/javascripts/spree/backend/views/order/customer_select.js
solidus_backend-2.5.0.beta2 app/assets/javascripts/spree/backend/views/order/customer_select.js
solidus_backend-2.5.0.beta1 app/assets/javascripts/spree/backend/views/order/customer_select.js
solidus_backend-2.4.2 app/assets/javascripts/spree/backend/views/order/customer_select.js