Sha256: 111012bf2367a7720ff8cce83945e1b7e921b17ac74d452a52bfcbb5d521c3cf

Contents?: true

Size: 1.31 KB

Versions: 57

Compression:

Stored size: 1.31 KB

Contents

'use strict'
// eslint-disable-next-line camelcase
function set_taxon_select (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_api, {
          ids: element.val(),
          without_children: true,
          token: Spree.api_key
        })
        return $.getJSON(url, null, function (data) {
          return callback(data['taxons'])
        })
      },
      ajax: {
        url: Spree.routes.taxons_api,
        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

57 entries across 57 versions & 1 rubygems

Version Path
spree_backend-4.0.9 app/assets/javascripts/spree/backend/taxon_autocomplete.js
spree_backend-4.1.15 app/assets/javascripts/spree/backend/taxon_autocomplete.js
spree_backend-4.1.14 app/assets/javascripts/spree/backend/taxon_autocomplete.js
spree_backend-4.0.8 app/assets/javascripts/spree/backend/taxon_autocomplete.js
spree_backend-3.7.14.1 app/assets/javascripts/spree/backend/taxon_autocomplete.js
spree_backend-4.1.13.1 app/assets/javascripts/spree/backend/taxon_autocomplete.js
spree_backend-4.0.7.1 app/assets/javascripts/spree/backend/taxon_autocomplete.js
spree_backend-4.0.7 app/assets/javascripts/spree/backend/taxon_autocomplete.js
spree_backend-3.7.14 app/assets/javascripts/spree/backend/taxon_autocomplete.js
spree_backend-4.1.13 app/assets/javascripts/spree/backend/taxon_autocomplete.js
spree_backend-4.0.6 app/assets/javascripts/spree/backend/taxon_autocomplete.js
spree_backend-4.2.0.rc2 app/assets/javascripts/spree/backend/taxon_autocomplete.js
spree_backend-3.7.13 app/assets/javascripts/spree/backend/taxon_autocomplete.js
spree_backend-4.0.5 app/assets/javascripts/spree/backend/taxon_autocomplete.js
spree_backend-4.1.12 app/assets/javascripts/spree/backend/taxon_autocomplete.js
spree_backend-3.7.12 app/assets/javascripts/spree/backend/taxon_autocomplete.js
spree_backend-4.2.0.rc1 app/assets/javascripts/spree/backend/taxon_autocomplete.js
spree_backend-4.0.4 app/assets/javascripts/spree/backend/taxon_autocomplete.js
spree_backend-3.7.11 app/assets/javascripts/spree/backend/taxon_autocomplete.js
spree_backend-4.1.11 app/assets/javascripts/spree/backend/taxon_autocomplete.js