Sha256: ecfc1a35f329962572f4bb42d479eeda4601fb18d0a0dce09dd6e2185b0d4545

Contents?: true

Size: 947 Bytes

Versions: 4

Compression:

Stored size: 947 Bytes

Contents

//= 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;
      }
    });
  }
})

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
spree_promo-1.2.5 app/assets/javascripts/admin/spree_promo.js
spree_promo-1.2.4 app/assets/javascripts/admin/spree_promo.js
spree_promo-1.2.3 app/assets/javascripts/admin/spree_promo.js
spree_promo-1.3.0.rc1 app/assets/javascripts/admin/spree_promo.js