Sha256: 5412fabd794bb1d0c59dc69b6c57d92265f6fe8cad8b58f23c9a2237178ca034

Contents?: true

Size: 1.35 KB

Versions: 18

Compression:

Stored size: 1.35 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.pathFor('api/users'),
        params: { "headers": {  'Authorization': 'Bearer ' + Spree.api_key } },
        datatype: 'json',
        data: function(term, page) {
          return {
            q: {
              m: 'or',
              email_start: term,
              firstname_or_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

18 entries across 18 versions & 1 rubygems

Version Path
solidus_backend-2.11.17 app/assets/javascripts/spree/backend/views/order/customer_select.js
solidus_backend-2.11.16 app/assets/javascripts/spree/backend/views/order/customer_select.js
solidus_backend-2.11.15 app/assets/javascripts/spree/backend/views/order/customer_select.js
solidus_backend-2.11.14 app/assets/javascripts/spree/backend/views/order/customer_select.js
solidus_backend-2.11.13 app/assets/javascripts/spree/backend/views/order/customer_select.js
solidus_backend-2.11.12 app/assets/javascripts/spree/backend/views/order/customer_select.js
solidus_backend-2.11.11 app/assets/javascripts/spree/backend/views/order/customer_select.js
solidus_backend-2.11.10 app/assets/javascripts/spree/backend/views/order/customer_select.js
solidus_backend-2.11.9 app/assets/javascripts/spree/backend/views/order/customer_select.js
solidus_backend-2.11.8 app/assets/javascripts/spree/backend/views/order/customer_select.js
solidus_backend-2.11.7 app/assets/javascripts/spree/backend/views/order/customer_select.js
solidus_backend-2.11.6 app/assets/javascripts/spree/backend/views/order/customer_select.js
solidus_backend-2.11.5 app/assets/javascripts/spree/backend/views/order/customer_select.js
solidus_backend-2.11.4 app/assets/javascripts/spree/backend/views/order/customer_select.js
solidus_backend-2.11.3 app/assets/javascripts/spree/backend/views/order/customer_select.js
solidus_backend-2.11.2 app/assets/javascripts/spree/backend/views/order/customer_select.js
solidus_backend-2.11.1 app/assets/javascripts/spree/backend/views/order/customer_select.js
solidus_backend-2.11.0 app/assets/javascripts/spree/backend/views/order/customer_select.js