Sha256: 6ac9c62294e3cbbccb3e0e9882e5d880737a451821e8995b5c994a60b2583006

Contents?: true

Size: 1.1 KB

Versions: 31

Compression:

Stored size: 1.1 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": { "X-Spree-Token": 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
  });
};

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

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
solidus_backend-2.4.2 app/assets/javascripts/spree/backend/user_picker.js
solidus_backend-2.4.1 app/assets/javascripts/spree/backend/user_picker.js
solidus_backend-2.3.1 app/assets/javascripts/spree/backend/user_picker.js
solidus_backend-2.2.2 app/assets/javascripts/spree/backend/user_picker.js
solidus_backend-2.1.1 app/assets/javascripts/spree/backend/user_picker.js
solidus_backend-2.0.3 app/assets/javascripts/spree/backend/user_picker.js
solidus_backend-1.4.2 app/assets/javascripts/spree/backend/user_picker.js
solidus_backend-2.4.0 app/assets/javascripts/spree/backend/user_picker.js
solidus_backend-2.4.0.rc1 app/assets/javascripts/spree/backend/user_picker.js
solidus_backend-2.4.0.beta1 app/assets/javascripts/spree/backend/user_picker.js
solidus_backend-2.3.0 app/assets/javascripts/spree/backend/user_picker.js
solidus_backend-2.3.0.rc3 app/assets/javascripts/spree/backend/user_picker.js
solidus_backend-2.3.0.rc2 app/assets/javascripts/spree/backend/user_picker.js
solidus_backend-2.3.0.rc1 app/assets/javascripts/spree/backend/user_picker.js
solidus_backend-2.3.0.beta1 app/assets/javascripts/spree/backend/user_picker.js
solidus_backend-2.0.2 app/assets/javascripts/spree/backend/user_picker.js
solidus_backend-1.4.1 app/assets/javascripts/spree/backend/user_picker.js
solidus_backend-2.2.1 app/assets/javascripts/spree/backend/user_picker.js
solidus_backend-2.2.0 app/assets/javascripts/spree/backend/user_picker.js
solidus_backend-2.2.0.rc1 app/assets/javascripts/spree/backend/user_picker.js