Sha256: b6a8c9219d9d85ad71d64347cead64cd5a27a81c175a4c64b231d4103303c8cd

Contents?: true

Size: 1.33 KB

Versions: 20

Compression:

Stored size: 1.33 KB

Contents

'use strict';

var set_taxon_select = function(){
  if ($('#product_taxon_ids').length > 0) {
    $('#product_taxon_ids').select2({
      placeholder: Spree.translations.taxon_placeholder,
      multiple: true,
      initSelection: function (element, callback) {
        var url = Spree.url(Spree.routes.taxons_search, {
          ids: element.val(),
          without_children: true
        });
        return Spree.getJSON(url, null, function (data) {
          return callback(data['taxons']);
        });
      },
      ajax: {
        url: Spree.routes.taxons_search,
        params: { "headers": { "X-Spree-Token": Spree.api_key } },
        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) {
        return taxon.pretty_name;
      },
      formatSelection: function (taxon) {
        return taxon.pretty_name;
      }
    });
  }
}

$(document).ready(function () {
  set_taxon_select()
});

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
solidus_backend-1.2.0 app/assets/javascripts/spree/backend/taxon_autocomplete.js.erb
solidus_backend-1.2.0.rc2 app/assets/javascripts/spree/backend/taxon_autocomplete.js.erb
solidus_backend-1.0.4 app/assets/javascripts/spree/backend/taxon_autocomplete.js.erb
solidus_backend-1.1.2 app/assets/javascripts/spree/backend/taxon_autocomplete.js.erb
solidus_backend-1.2.0.rc1 app/assets/javascripts/spree/backend/taxon_autocomplete.js.erb
solidus_backend-1.2.0.beta1 app/assets/javascripts/spree/backend/taxon_autocomplete.js.erb
solidus_backend-1.0.3 app/assets/javascripts/spree/backend/taxon_autocomplete.js.erb
solidus_backend-1.1.1 app/assets/javascripts/spree/backend/taxon_autocomplete.js.erb
solidus_backend-1.1.0 app/assets/javascripts/spree/backend/taxon_autocomplete.js.erb
solidus_backend-1.1.0.pre2 app/assets/javascripts/spree/backend/taxon_autocomplete.js.erb
solidus_backend-1.1.0.pre1 app/assets/javascripts/spree/backend/taxon_autocomplete.js.erb
solidus_backend-1.1.0.beta1 app/assets/javascripts/spree/backend/taxon_autocomplete.js.erb
solidus_backend-1.0.2 app/assets/javascripts/spree/backend/taxon_autocomplete.js.erb
solidus_backend-1.0.1 app/assets/javascripts/spree/backend/taxon_autocomplete.js.erb
solidus_backend-1.0.0 app/assets/javascripts/spree/backend/taxon_autocomplete.js.erb
solidus_backend-1.0.0.rc2 app/assets/javascripts/spree/backend/taxon_autocomplete.js.erb
solidus_backend-1.0.0.rc1 app/assets/javascripts/spree/backend/taxon_autocomplete.js.erb
solidus_backend-1.0.0.pre3 app/assets/javascripts/spree/backend/taxon_autocomplete.js.erb
solidus_backend-1.0.0.pre2 app/assets/javascripts/spree/backend/taxon_autocomplete.js.erb
solidus_backend-1.0.0.pre app/assets/javascripts/spree/backend/taxon_autocomplete.js.erb