Sha256: d216e3582913548167b3300f309cf9d365095b60110d7a82a3753ad44ef8a61d

Contents?: true

Size: 1.58 KB

Versions: 21

Compression:

Stored size: 1.58 KB

Contents

(function() {
  var variantTemplate = HandlebarsTemplates["variants/autocomplete"];

  var formatVariantResult = function(variant) {
    return variantTemplate({
      variant: variant
    });
  };

  $.fn.variantAutocomplete = function(searchOptions) {
    if (searchOptions == null) {
      searchOptions = {};
    }
    this.select2({
      placeholder: Spree.translations.variant_placeholder,
      minimumInputLength: 3,
      initSelection: function(element, callback) {
        Spree.ajax({
          url: Spree.routes.variants_api + "/" + element.val(),
          success: callback
        });
      },
      ajax: {
        url: Spree.routes.variants_api,
        datatype: "json",
        quietMillis: 500,
        params: {
          "headers": {
            'Authorization': 'Bearer ' + Spree.api_key
          }
        },
        data: function(term, page) {
          var searchData = {
            q: {
              product_name_or_sku_cont: term
            },
            token: Spree.api_key
          };
          return _.extend(searchData, searchOptions);
        },

        results: function(data, page) {
          window.variants = data["variants"];
          return {
            results: data["variants"]
          };
        }
      },

      formatResult: formatVariantResult,
      formatSelection: function(variant, container, escapeMarkup) {
        if (variant.options_text) {
          return Select2.util.escapeMarkup(variant.name + " (" + variant.options_text + ")");
        } else {
          return Select2.util.escapeMarkup(variant.name);
        }
      }
    });
  };
})();

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
solidus_backend-2.10.5 app/assets/javascripts/spree/backend/variant_autocomplete.js
solidus_backend-2.10.3 app/assets/javascripts/spree/backend/variant_autocomplete.js
solidus_backend-2.10.2 app/assets/javascripts/spree/backend/variant_autocomplete.js
solidus_backend-2.9.6 app/assets/javascripts/spree/backend/variant_autocomplete.js
solidus_backend-2.8.6 app/assets/javascripts/spree/backend/variant_autocomplete.js
solidus_backend-2.10.1 app/assets/javascripts/spree/backend/variant_autocomplete.js
solidus_backend-2.9.5 app/assets/javascripts/spree/backend/variant_autocomplete.js
solidus_backend-2.10.0 app/assets/javascripts/spree/backend/variant_autocomplete.js
solidus_backend-2.9.4 app/assets/javascripts/spree/backend/variant_autocomplete.js
solidus_backend-2.8.5 app/assets/javascripts/spree/backend/variant_autocomplete.js
solidus_backend-2.9.3 app/assets/javascripts/spree/backend/variant_autocomplete.js
solidus_backend-2.9.2 app/assets/javascripts/spree/backend/variant_autocomplete.js
solidus_backend-2.10.0.beta1 app/assets/javascripts/spree/backend/variant_autocomplete.js
solidus_backend-2.9.1 app/assets/javascripts/spree/backend/variant_autocomplete.js
solidus_backend-2.9.0 app/assets/javascripts/spree/backend/variant_autocomplete.js
solidus_backend-2.9.0.rc.1 app/assets/javascripts/spree/backend/variant_autocomplete.js
solidus_backend-2.8.4 app/assets/javascripts/spree/backend/variant_autocomplete.js
solidus_backend-2.8.3 app/assets/javascripts/spree/backend/variant_autocomplete.js
solidus_backend-2.8.2 app/assets/javascripts/spree/backend/variant_autocomplete.js
solidus_backend-2.8.1 app/assets/javascripts/spree/backend/variant_autocomplete.js