Sha256: c0518717fb6425ab3e00f038e908bcef2b35a5257a707bafda52514a2fdac462

Contents?: true

Size: 1.79 KB

Versions: 85

Compression:

Stored size: 1.79 KB

Contents

//= require solidus_admin/Sortable

Spree.ready(function() {
  var productTemplate = HandlebarsTemplates['products/sortable'];
  var productListTemplate = function(products) {
    return _.map(products, productTemplate).join('') || "<h4>" + Spree.translations.no_results + "</h4>";
  };

  var saveSort = function(e) {
    var item = e.item;
    Spree.ajax({
      url: Spree.pathFor('api/classifications'),
      method: 'PUT',
      data: {
        product_id: item.getAttribute('data-product-id'),
        taxon_id: $('#taxon_id').val(),
        position: e.newIndex
      }
    });
  };

  var formatTaxon = function(taxon) {
    return Select2.util.escapeMarkup(taxon.pretty_name);
  };

  $('#taxon_id').select2({
    dropdownCssClass: "taxon_select_box",
    placeholder: Spree.translations.find_a_taxon,
    ajax: {
      url: Spree.pathFor('api/taxons'),
      params: {
        "headers": {
          'Authorization': 'Bearer ' + Spree.api_key
        }
      },
      data: function(term, page) {
        return {
          per_page: 50,
          page: page,
          q: {
            name_cont: term
          }
        };
      },
      results: function(data) {
        return {
          results: data['taxons'],
          more: data.current_page < data.pages
        };
      }
    },
    formatResult: formatTaxon,
    formatSelection: formatTaxon
  });

  $('#taxon_id').on("change", function(e) {
    Spree.ajax({
      url: Spree.pathFor('api/taxons/products'),
      data: {
        id: e.val,
        simple: 1
      },
      success: function(data) {
        $('#taxon_products').html(productListTemplate(data.products));

        var el = document.querySelector('#taxon_products')

        new Sortable(el, {
          draggable: ".sort_item",
          onEnd: saveSort
        });
      }
    });
  });
});

Version data entries

85 entries across 85 versions & 1 rubygems

Version Path
solidus_backend-4.4.2 app/assets/javascripts/spree/backend/taxons.js
solidus_backend-4.4.1 app/assets/javascripts/spree/backend/taxons.js
solidus_backend-4.4.0 app/assets/javascripts/spree/backend/taxons.js
solidus_backend-4.3.4 app/assets/javascripts/spree/backend/taxons.js
solidus_backend-4.2.4 app/assets/javascripts/spree/backend/taxons.js
solidus_backend-4.1.5 app/assets/javascripts/spree/backend/taxons.js
solidus_backend-4.3.3 app/assets/javascripts/spree/backend/taxons.js
solidus_backend-4.3.2 app/assets/javascripts/spree/backend/taxons.js
solidus_backend-4.1.4 app/assets/javascripts/spree/backend/taxons.js
solidus_backend-4.3.1 app/assets/javascripts/spree/backend/taxons.js
solidus_backend-4.3.0 app/assets/javascripts/spree/backend/taxons.js
solidus_backend-4.2.3 app/assets/javascripts/spree/backend/taxons.js
solidus_backend-4.1.3 app/assets/javascripts/spree/backend/taxons.js
solidus_backend-4.0.4 app/assets/javascripts/spree/backend/taxons.js
solidus_backend-3.4.6 app/assets/javascripts/spree/backend/taxons.js
solidus_backend-4.0.3 app/assets/javascripts/spree/backend/taxons.js
solidus_backend-4.1.2 app/assets/javascripts/spree/backend/taxons.js
solidus_backend-4.2.2 app/assets/javascripts/spree/backend/taxons.js
solidus_backend-3.4.5 app/assets/javascripts/spree/backend/taxons.js
solidus_backend-4.2.1 app/assets/javascripts/spree/backend/taxons.js