Sha256: cfcf19bdbe2bf0730ce10c8c0d9a8f652db085474ecd266b9e041bfb1ae5741c

Contents?: true

Size: 1.78 KB

Versions: 21

Compression:

Stored size: 1.78 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.routes.classifications_api,
      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.routes.taxons_search,
      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.routes.taxon_products_api,
      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

21 entries across 21 versions & 1 rubygems

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