Sha256: 69efa0e0877551bb13568cbdaefaa0422219cfda4ba3eafcc4f2c7eeaa34842d

Contents?: true

Size: 1.47 KB

Versions: 67

Compression:

Stored size: 1.47 KB

Contents

# variant autocompletion
$(document).ready ->
  if $("#variant_autocomplete_template").length > 0
    window.variantTemplate = Handlebars.compile($("#variant_autocomplete_template").text())
    window.variantStockTemplate = Handlebars.compile($("#variant_autocomplete_stock_template").text())
    window.variantLineItemTemplate = Handlebars.compile($("#variant_line_items_autocomplete_stock_template").text())
  return

formatVariantResult = (variant) ->
  variant.image = variant.images[0].mini_url  if variant["images"][0] isnt `undefined` and variant["images"][0].mini_url isnt `undefined`
  variantTemplate variant: variant

$.fn.variantAutocomplete = ->
  @select2
    placeholder: Spree.translations.variant_placeholder
    minimumInputLength: 3
    initSelection: (element, callback) ->
      $.get Spree.routes.variants_api + "/" + element.val(), { token: Spree.api_key }, (data) ->
        callback data
    ajax:
      url: Spree.url(Spree.routes.variants_api)
      quietMillis: 200
      datatype: "json"
      data: (term, page) ->
        q:
          product_name_or_sku_cont: term
        token: Spree.api_key

      results: (data, page) ->
        window.variants = data["variants"]
        results: data["variants"]

    formatResult: formatVariantResult
    formatSelection: (variant, container, escapeMarkup) ->
      if !!variant.options_text
        Select2.util.escapeMarkup("#{variant.name} (#{variant.options_text})")
      else
        Select2.util.escapeMarkup(variant.name)

Version data entries

67 entries across 67 versions & 1 rubygems

Version Path
spree_backend-3.4.6 app/assets/javascripts/spree/backend/variant_autocomplete.js.coffee
spree_backend-3.2.9 app/assets/javascripts/spree/backend/variant_autocomplete.js.coffee
spree_backend-3.1.14 app/assets/javascripts/spree/backend/variant_autocomplete.js.coffee
spree_backend-3.6.6 app/assets/javascripts/spree/backend/variant_autocomplete.js.coffee
spree_backend-3.6.5 app/assets/javascripts/spree/backend/variant_autocomplete.js.coffee
spree_backend-3.6.4 app/assets/javascripts/spree/backend/variant_autocomplete.js.coffee
spree_backend-3.6.3 app/assets/javascripts/spree/backend/variant_autocomplete.js.coffee
spree_backend-3.6.2 app/assets/javascripts/spree/backend/variant_autocomplete.js.coffee
spree_backend-3.6.1 app/assets/javascripts/spree/backend/variant_autocomplete.js.coffee
spree_backend-3.6.0 app/assets/javascripts/spree/backend/variant_autocomplete.js.coffee
spree_backend-3.5.0 app/assets/javascripts/spree/backend/variant_autocomplete.js.coffee
spree_backend-3.3.6 app/assets/javascripts/spree/backend/variant_autocomplete.js.coffee
spree_backend-3.2.8 app/assets/javascripts/spree/backend/variant_autocomplete.js.coffee
spree_backend-3.1.13 app/assets/javascripts/spree/backend/variant_autocomplete.js.coffee
spree_backend-3.6.0.rc1 app/assets/javascripts/spree/backend/variant_autocomplete.js.coffee
spree_backend-3.5.0.rc2 app/assets/javascripts/spree/backend/variant_autocomplete.js.coffee
spree_backend-3.5.0.rc1 app/assets/javascripts/spree/backend/variant_autocomplete.js.coffee
spree_backend-3.4.5 app/assets/javascripts/spree/backend/variant_autocomplete.js.coffee
spree_backend-3.3.5 app/assets/javascripts/spree/backend/variant_autocomplete.js.coffee
spree_backend-3.4.4 app/assets/javascripts/spree/backend/variant_autocomplete.js.coffee