Sha256: ad2f6519730e9ffd344e430835bf25015a95970a9b765a88b1e31db80e79e78a

Contents?: true

Size: 1.25 KB

Versions: 4

Compression:

Stored size: 1.25 KB

Contents

'use strict';

var set_taxon_select = function(selector){
  function formatTaxon(taxon) {
    return Select2.util.escapeMarkup(taxon.pretty_name);
  }

  if ($(selector).length > 0) {
    $(selector).select2({
      placeholder: Spree.translations.taxon_placeholder,
      multiple: true,
      initSelection: function (element, callback) {
        var url = Spree.url(Spree.routes.taxons_search, {
          ids: element.val(),
          token: Spree.api_key
        });
        return $.getJSON(url, null, function (data) {
          return 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: formatTaxon,
      formatSelection: formatTaxon
    });
  }
}

$(document).ready(function () {
  set_taxon_select('#product_taxon_ids')
});

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
spree_backend-3.0.10 app/assets/javascripts/spree/backend/taxon_autocomplete.js
spree_backend-3.0.9 app/assets/javascripts/spree/backend/taxon_autocomplete.js
spree_backend-3.0.8 app/assets/javascripts/spree/backend/taxon_autocomplete.js
spree_backend-3.0.7 app/assets/javascripts/spree/backend/taxon_autocomplete.js