Sha256: 1b87018b7e1e535e2eb49350d71dcded0d8fda5b2321542e26a707e7147666b6

Contents?: true

Size: 1.26 KB

Versions: 55

Compression:

Stored size: 1.26 KB

Contents

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

/* Check if string is valid UUID */
function isAValidUUID(str) {
  // https://stackoverflow.com/a/13653180/8170555
  const regexExp = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-5][0-9a-f]{3}-[089ab][0-9a-f]{3}-[0-9a-f]{12}$/i;

  return regexExp.test(str);
}

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) || isAValidUUID(objId)) {
                positions['positions['+objId+']'] = index + 1;
              }
            }
          });
          Spree.ajax({
            type: 'POST',
            dataType: 'json',
            url: url,
            data: positions,
          });
        }
      });
    });
  }
};

Spree.ready(Spree.SortableTable.refresh);

Version data entries

55 entries across 55 versions & 1 rubygems

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