Sha256: 7936e830685242e314434d11251dfe434ae7289e175506e6ad48b2338c9ae4e6

Contents?: true

Size: 1.45 KB

Versions: 85

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.pathFor('api/taxons'),
          data: {
            ids: ids,
            per_page: count,
            without_children: true
          },
          success: function (data) {
            callback(data['taxons']);
          }
        });
      },
      ajax: {
        url: Spree.pathFor('api/taxons'),
        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

85 entries across 85 versions & 1 rubygems

Version Path
solidus_backend-4.4.2 app/assets/javascripts/spree/backend/taxon_autocomplete.js
solidus_backend-4.4.1 app/assets/javascripts/spree/backend/taxon_autocomplete.js
solidus_backend-4.4.0 app/assets/javascripts/spree/backend/taxon_autocomplete.js
solidus_backend-4.3.4 app/assets/javascripts/spree/backend/taxon_autocomplete.js
solidus_backend-4.2.4 app/assets/javascripts/spree/backend/taxon_autocomplete.js
solidus_backend-4.1.5 app/assets/javascripts/spree/backend/taxon_autocomplete.js
solidus_backend-4.3.3 app/assets/javascripts/spree/backend/taxon_autocomplete.js
solidus_backend-4.3.2 app/assets/javascripts/spree/backend/taxon_autocomplete.js
solidus_backend-4.1.4 app/assets/javascripts/spree/backend/taxon_autocomplete.js
solidus_backend-4.3.1 app/assets/javascripts/spree/backend/taxon_autocomplete.js
solidus_backend-4.3.0 app/assets/javascripts/spree/backend/taxon_autocomplete.js
solidus_backend-4.2.3 app/assets/javascripts/spree/backend/taxon_autocomplete.js
solidus_backend-4.1.3 app/assets/javascripts/spree/backend/taxon_autocomplete.js
solidus_backend-4.0.4 app/assets/javascripts/spree/backend/taxon_autocomplete.js
solidus_backend-3.4.6 app/assets/javascripts/spree/backend/taxon_autocomplete.js
solidus_backend-4.0.3 app/assets/javascripts/spree/backend/taxon_autocomplete.js
solidus_backend-4.1.2 app/assets/javascripts/spree/backend/taxon_autocomplete.js
solidus_backend-4.2.2 app/assets/javascripts/spree/backend/taxon_autocomplete.js
solidus_backend-3.4.5 app/assets/javascripts/spree/backend/taxon_autocomplete.js
solidus_backend-4.2.1 app/assets/javascripts/spree/backend/taxon_autocomplete.js