<commit_before>//= require admin/spree_core
//= require_tree .

function cleanUsers(data) {
  var users = $.map(data['users'], function(result) {
    return result['user']
  })
  return users;
}

$(document).ready(function() {
  $('.user_picker').select2({
    minimumInputLength: 1,
    multiple: true,
    initSelection: function(element, callback) {
      $.get(Spree.routes.user_search, { ids: element.val() }, function(data) { 
        callback(cleanUsers(data))
      })
    },
    ajax: {
      url: Spree.routes.user_search,
      datatype: 'json',
      data: function(term, page) {
        return { q: term }
      },
      results: function(data, page) {
        return { results: cleanUsers(data) }
      }
    },
    formatResult: function(user) {
      return user.email;
    },
    formatSelection: function(user) {
      return user.email;
    }
  });
})
<commit_msg>Don't call select2 for user_picker in spree_promo.js if that element does not exist<commit_after>//= require admin/spree_core
//= require_tree .

function cleanUsers(data) {
  var users = $.map(data['users'], function(result) {
    return result['user']
  })
  return users;
}

$(document).ready(function() {
  if ($('user_picker').length > 0) {
    $('.user_picker').select2({
      minimumInputLength: 1,
      multiple: true,
      initSelection: function(element, callback) {
        $.get(Spree.routes.user_search, { ids: element.val() }, function(data) { 
          callback(cleanUsers(data))
        })
      },
      ajax: {
        url: Spree.routes.user_search,
        datatype: 'json',
        data: function(term, page) {
          return { q: term }
        },
        results: function(data, page) {
          return { results: cleanUsers(data) }
        }
      },
      formatResult: function(user) {
        return user.email;
      },
      formatSelection: function(user) {
        return user.email;
      }
    });
  }
})

{'fraction_non_alphanumeric': 0.14893617021276595, 'fraction_numerical': 0.0031136481577581734, 'mean_word_length': 2.449016100178891, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6433033', 'n_tokens_mistral': 606, 'n_tokens_neox': 601, 'n_words': 121}