Sha256: 9a551b9dc15262de5fd54defe5075f2cd5f0700ad9c6831da2bca4459e527abd

Contents?: true

Size: 1.45 KB

Versions: 40

Compression:

Stored size: 1.45 KB

Contents

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

  this.select2({
      placeholder: Spree.translations.taxon_placeholder,
      multiple: true,
      initSelection: function (element, callback) {
        var ids = element.val(),
            count = ids.split(",").length;

        Spree.ajax({
          type: "GET",
          url: Spree.routes.taxons_search,
          data: {
            ids: ids,
            per_page: count,
            without_children: true
          },
          success: function (data) {
            callback(data['taxons']);
          }
        });
      },
      ajax: {
        url: Spree.routes.taxons_search,
        datatype: 'json',
        data: function (term, page) {
          return {
            per_page: 50,
            page: page,
            without_children: true,
            q: {
              name_cont: term
            },
            token: Spree.api_key
          };
        },
        results: function (data, page) {
          var more = page < data.pages;
          return {
            results: data['taxons'],
            more: more
          };
        }
      },
      formatResult: function (taxon, container, query, escapeMarkup) {
        return escapeMarkup(taxon.pretty_name);
      },
      formatSelection: function (taxon, container, escapeMarkup) {
        return escapeMarkup(taxon.pretty_name);
      }
    });
};

Spree.ready(function () {
  $('#product_taxon_ids, .taxon_picker').taxonAutocomplete();
});

Version data entries

40 entries across 40 versions & 1 rubygems

Version Path
solidus_backend-2.10.5 app/assets/javascripts/spree/backend/taxon_autocomplete.js
solidus_backend-2.10.3 app/assets/javascripts/spree/backend/taxon_autocomplete.js
solidus_backend-2.10.2 app/assets/javascripts/spree/backend/taxon_autocomplete.js
solidus_backend-2.9.6 app/assets/javascripts/spree/backend/taxon_autocomplete.js
solidus_backend-2.8.6 app/assets/javascripts/spree/backend/taxon_autocomplete.js
solidus_backend-2.10.1 app/assets/javascripts/spree/backend/taxon_autocomplete.js
solidus_backend-2.9.5 app/assets/javascripts/spree/backend/taxon_autocomplete.js
solidus_backend-2.10.0 app/assets/javascripts/spree/backend/taxon_autocomplete.js
solidus_backend-2.9.4 app/assets/javascripts/spree/backend/taxon_autocomplete.js
solidus_backend-2.6.6 app/assets/javascripts/spree/backend/taxon_autocomplete.js
solidus_backend-2.7.4 app/assets/javascripts/spree/backend/taxon_autocomplete.js
solidus_backend-2.8.5 app/assets/javascripts/spree/backend/taxon_autocomplete.js
solidus_backend-2.9.3 app/assets/javascripts/spree/backend/taxon_autocomplete.js
solidus_backend-2.9.2 app/assets/javascripts/spree/backend/taxon_autocomplete.js
solidus_backend-2.10.0.beta1 app/assets/javascripts/spree/backend/taxon_autocomplete.js
solidus_backend-2.7.3 app/assets/javascripts/spree/backend/taxon_autocomplete.js
solidus_backend-2.6.5 app/assets/javascripts/spree/backend/taxon_autocomplete.js
solidus_backend-2.5.2 app/assets/javascripts/spree/backend/taxon_autocomplete.js
solidus_backend-2.9.1 app/assets/javascripts/spree/backend/taxon_autocomplete.js
solidus_backend-2.9.0 app/assets/javascripts/spree/backend/taxon_autocomplete.js