Sha256: 461c45d7da0d13f6b379733bf7e45805aa51dff9fb1389180469f8f18dc3a4e7

Contents?: true

Size: 1.11 KB

Versions: 21

Compression:

Stored size: 1.11 KB

Contents

$.fn.userAutocomplete = function () {
  'use strict';

  function formatUser(user) {
    return Select2.util.escapeMarkup(user.email);
  }

  this.select2({
    minimumInputLength: 1,
    multiple: true,
    initSelection: function (element, callback) {
      Spree.ajax({
        url: Spree.routes.users_api,
        data: {
          ids: element.val()
        },
        success: function(data) {
          callback(data.users);
        }
      });
    },
    ajax: {
      url: Spree.routes.users_api,
      datatype: 'json',
      params: { "headers": {  'Authorization': 'Bearer ' + Spree.api_key } },
      data: function (term) {
        return {
          q: {
            m: 'or',
            email_start: term,
            addresses_firstname_start: term,
            addresses_lastname_start: term
          }
        };
      },
      results: function (data) {
        return {
          results: data.users,
          more: data.current_page < data.pages
        };
      }
    },
    formatResult: formatUser,
    formatSelection: formatUser
  });
};

Spree.ready(function () {
  $('.user_picker').userAutocomplete();
});

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
solidus_backend-2.10.5 app/assets/javascripts/spree/backend/user_picker.js
solidus_backend-2.10.3 app/assets/javascripts/spree/backend/user_picker.js
solidus_backend-2.10.2 app/assets/javascripts/spree/backend/user_picker.js
solidus_backend-2.9.6 app/assets/javascripts/spree/backend/user_picker.js
solidus_backend-2.8.6 app/assets/javascripts/spree/backend/user_picker.js
solidus_backend-2.10.1 app/assets/javascripts/spree/backend/user_picker.js
solidus_backend-2.9.5 app/assets/javascripts/spree/backend/user_picker.js
solidus_backend-2.10.0 app/assets/javascripts/spree/backend/user_picker.js
solidus_backend-2.9.4 app/assets/javascripts/spree/backend/user_picker.js
solidus_backend-2.8.5 app/assets/javascripts/spree/backend/user_picker.js
solidus_backend-2.9.3 app/assets/javascripts/spree/backend/user_picker.js
solidus_backend-2.9.2 app/assets/javascripts/spree/backend/user_picker.js
solidus_backend-2.10.0.beta1 app/assets/javascripts/spree/backend/user_picker.js
solidus_backend-2.9.1 app/assets/javascripts/spree/backend/user_picker.js
solidus_backend-2.9.0 app/assets/javascripts/spree/backend/user_picker.js
solidus_backend-2.9.0.rc.1 app/assets/javascripts/spree/backend/user_picker.js
solidus_backend-2.8.4 app/assets/javascripts/spree/backend/user_picker.js
solidus_backend-2.8.3 app/assets/javascripts/spree/backend/user_picker.js
solidus_backend-2.8.2 app/assets/javascripts/spree/backend/user_picker.js
solidus_backend-2.8.1 app/assets/javascripts/spree/backend/user_picker.js