Sha256: d49210cea4e615ce299e04e0703270edabed6e1f6749ab37e5c90804b698fee7
Contents?: true
Size: 1.38 KB
Versions: 2
Compression:
Stored size: 1.38 KB
Contents
/* eslint-disable no-new */ document.addEventListener('DOMContentLoaded', function() { const menuItemSortable = { group: { name: 'sortable-menu', pull: true, put: true }, handle: '.move-handle', swapThreshold: 0.5, emptyInsertThreshold: 8, dragClass: 'menu-item-dragged', draggable: '.dragable', animation: 350, forceFallback: false, onEnd: function (evt) { handleMenuItemMove(evt) } } let containers = null; containers = document.querySelectorAll('.menu-container'); for (let i = 0; i < containers.length; i++) { new Sortable(containers[i], menuItemSortable); } }) function handleMenuItemMove(evt) { const data = { moved_item_id: parseInt(evt.item.dataset.itemId, 10), new_parent_id: parseInt(evt.to.dataset.parentId, 10) || null, new_position_idx: parseInt(evt.newIndex, 10) } fetch(Spree.routes.menus_items_api_v2 + '/reposition', { method: 'PATCH', headers: { Authorization: 'Bearer ' + OAUTH_TOKEN, 'Content-Type': 'application/json' }, body: JSON.stringify(data) }) .then(response => { if (response.ok !== true) { handleMenuItemMoveError() } }) .catch(err => { console.error(err); }); } function handleMenuItemMoveError () { // eslint-disable-next-line no-undef show_flash('error', Spree.translations.move_could_not_be_saved) }
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
spree_backend-4.3.0.rc2 | app/assets/javascripts/spree/backend/menus/menu.es6 |
spree_backend-4.3.0.rc1 | app/assets/javascripts/spree/backend/menus/menu.es6 |