Sha256: 25bfc440c12839393c6fbf3b2904088a7f07ad2f1fcacfaa75ca388a206754dc

Contents?: true

Size: 1.36 KB

Versions: 15

Compression:

Stored size: 1.36 KB

Contents

<%#encoding: UTF-8%>
// variant autocompletion

$(document).ready(function() {

  if ($('#variant_autocomplete_template').length > 0) {
    window.variantTemplate = Handlebars.compile($('#variant_autocomplete_template').text());
    window.variantStockTemplate = Handlebars.compile($('#variant_autocomplete_stock_template').text());
  }
});

formatVariantResult = function(variant) {
  if (variant["images"][0] != undefined && variant["images"][0].urls != undefined) {
    variant.image = variant.images[0].urls.mini
  }
  return variantTemplate({ variant: variant })
}

$.fn.variantAutocomplete = function() {
  this.parent().children(".options_placeholder").attr('id', this.parent().data('index'))
  this.select2({
    placeholder: Spree.translations.variant_placeholder,
    minimumInputLength: 3,
    ajax: {
      url: Spree.url(Spree.routes.variants_search),
      datatype: 'json',
      data: function(term, page) {
        return {
          q: {
            "product_name_or_sku_cont": term
          }
        }
      },
      results: function (data, page) {
        window.variants = data['variants'];

        return { results: data['variants'] }
      }
    },
    formatResult: formatVariantResult,
    formatSelection: function (variant) {
      $(this.element).parent().children('.options_placeholder').html(variant.options_text)
      return variant.name;
    }
  })
}

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
spree_backend-2.1.12 app/assets/javascripts/admin/variant_autocomplete.js.erb
spree_backend-2.1.11 app/assets/javascripts/admin/variant_autocomplete.js.erb
spree_backend-2.1.10 app/assets/javascripts/admin/variant_autocomplete.js.erb
spree_backend-2.0.13 app/assets/javascripts/admin/variant_autocomplete.js.erb
spree_backend-2.1.9 app/assets/javascripts/admin/variant_autocomplete.js.erb
spree_backend-2.1.8 app/assets/javascripts/admin/variant_autocomplete.js.erb
spree_backend-2.0.12 app/assets/javascripts/admin/variant_autocomplete.js.erb
spree_backend-2.1.7 app/assets/javascripts/admin/variant_autocomplete.js.erb
spree_backend-2.0.11 app/assets/javascripts/admin/variant_autocomplete.js.erb
spree_backend-2.0.10 app/assets/javascripts/admin/variant_autocomplete.js.erb
spree_backend-2.1.6 app/assets/javascripts/admin/variant_autocomplete.js.erb
spree_backend-2.1.5 app/assets/javascripts/admin/variant_autocomplete.js.erb
spree_backend-2.0.9 app/assets/javascripts/admin/variant_autocomplete.js.erb
spree_backend-2.1.4 app/assets/javascripts/admin/variant_autocomplete.js.erb
spree_backend-2.0.8 app/assets/javascripts/admin/variant_autocomplete.js.erb