Sha256: e9d7017b4fa7e76ecff14e526d96ea51076643bfca17ce675a2804e2d2fa9506

Contents?: true

Size: 918 Bytes

Versions: 7

Compression:

Stored size: 918 Bytes

Contents

/* eslint-disable camelcase */
/* global sortable */

// Needs a `tbody` element inside a `#steps` section. The `tbody` element
// should have a `data-sort-url` attribute with the URL where the data should
// be posted to.
const sortSteps = () => {
  const $sortableElement = $('#steps tbody');

  if ($sortableElement.length > 0) {
    const sortUrl = $sortableElement.data('sort-url');

    sortable('#steps tbody', {
      placeholder: $('<tr style="border-style: dashed; border-color: #000"><td colspan="4">&nbsp;</td></tr>')[0]
    })[0].addEventListener('sortupdate', (event) => {
      const order = $(event.target).children()
        .map((index, child) => $(child).data('id'))
        .toArray();

      $.ajax({
        method: 'POST',
        url: sortUrl,
        contentType: 'application/json',
        data: JSON.stringify({ items_ids: order }) },
      );
    });
  }
};

window.sortSteps = sortSteps;

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
decidim-0.0.4 decidim-admin/app/assets/javascripts/decidim/admin/sort_steps.js.es6
decidim-admin-0.0.3 app/assets/javascripts/decidim/admin/sort_steps.js.es6
decidim-0.0.3 decidim-admin/app/assets/javascripts/decidim/admin/sort_steps.js.es6
decidim-admin-0.0.2 app/assets/javascripts/decidim/admin/sort_steps.js.es6
decidim-0.0.2 decidim-admin/app/assets/javascripts/decidim/admin/sort_steps.js.es6
decidim-admin-0.0.1 app/assets/javascripts/decidim/admin/sort_steps.js.es6
decidim-0.0.1 decidim-admin/app/assets/javascripts/decidim/admin/sort_steps.js.es6