Sha256: 64c9c2d6225bdb20b8a804960c86a9d2ad1a7a814c6e385520da3f049eeaf94a

Contents?: true

Size: 1019 Bytes

Versions: 29

Compression:

Stored size: 1019 Bytes

Contents

//= require solidus_admin/Sortable
/* eslint no-unused-vars: "off" */

Spree.SortableTable = {
  refresh: function() {
    var sortable_tables = document.querySelectorAll('table.sortable');

    _.each(sortable_tables, function(table) {
      var url = table.getAttribute('data-sortable-link');
      var tbody = table.querySelector('tbody');
      var sortable = Sortable.create(tbody,{
        handle: ".handle",
        onEnd: function(e) {
          var positions = {};
          _.each(e.to.querySelectorAll('tr'), function(el, index) {
            var idAttr = el.id;
            if (idAttr) {
              var objId = idAttr.split('_').slice(-1);
              if (!isNaN(objId)) {
                positions['positions['+objId+']'] = index + 1;
              }
            }
          });
          Spree.ajax({
            type: 'POST',
            dataType: 'json',
            url: url,
            data: positions,
          });
        }
      });
    });
  }
};

Spree.ready(Spree.SortableTable.refresh);

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
solidus_backend-2.11.15 app/assets/javascripts/spree/backend/components/sortable_table.js
solidus_backend-2.11.14 app/assets/javascripts/spree/backend/components/sortable_table.js
solidus_backend-3.0.5 app/assets/javascripts/spree/backend/components/sortable_table.js
solidus_backend-3.1.5 app/assets/javascripts/spree/backend/components/sortable_table.js
solidus_backend-2.11.13 app/assets/javascripts/spree/backend/components/sortable_table.js
solidus_backend-3.0.4 app/assets/javascripts/spree/backend/components/sortable_table.js
solidus_backend-3.1.4 app/assets/javascripts/spree/backend/components/sortable_table.js
solidus_backend-2.11.12 app/assets/javascripts/spree/backend/components/sortable_table.js
solidus_backend-3.0.3 app/assets/javascripts/spree/backend/components/sortable_table.js
solidus_backend-3.1.3 app/assets/javascripts/spree/backend/components/sortable_table.js
solidus_backend-3.1.2 app/assets/javascripts/spree/backend/components/sortable_table.js
solidus_backend-3.1.1 app/assets/javascripts/spree/backend/components/sortable_table.js
solidus_backend-3.1.0 app/assets/javascripts/spree/backend/components/sortable_table.js
solidus_backend-2.11.11 app/assets/javascripts/spree/backend/components/sortable_table.js
solidus_backend-3.0.2 app/assets/javascripts/spree/backend/components/sortable_table.js
solidus_backend-2.11.10 app/assets/javascripts/spree/backend/components/sortable_table.js
solidus_backend-3.0.1 app/assets/javascripts/spree/backend/components/sortable_table.js
solidus_backend-3.0.0 app/assets/javascripts/spree/backend/components/sortable_table.js
solidus_backend-2.11.9 app/assets/javascripts/spree/backend/components/sortable_table.js
solidus_backend-2.11.8 app/assets/javascripts/spree/backend/components/sortable_table.js