Skip to content

Commit

Permalink
Merge pull request #2751 from AlchemyCMS/backport/7.1-stable/pr-2750
Browse files Browse the repository at this point in the history
[7.1-stable] Merge pull request #2750 from tvdeyen/fix-sortable-elements
  • Loading branch information
tvdeyen authored Feb 27, 2024
2 parents 0e069c3 + d32f68b commit 0b0f932
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
17 changes: 11 additions & 6 deletions app/javascript/alchemy_admin/sortable_elements.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,17 @@ function onSort(event) {
params.parent_element_id = parentElement.dataset.elementId
}

post(Alchemy.routes.order_admin_elements_path, params).then((response) => {
const data = response.data
Alchemy.growl(data.message)
Alchemy.PreviewWindow.refresh()
item.updateTitle(data.preview_text)
})
// Only send the request if the item was moved to a different container
// or sorted in the same list. Not on the old list in order to avoid incrementing
// the position of the other elements.
if (event.target === event.to) {
post(Alchemy.routes.order_admin_elements_path, params).then((response) => {
const data = response.data
Alchemy.growl(data.message)
Alchemy.PreviewWindow.refresh()
item.updateTitle(data.preview_text)
})
}
}

function onEnd() {
Expand Down
4 changes: 1 addition & 3 deletions app/views/alchemy/admin/elements/create.js.erb
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@
$element_area.append(element_html);
<%- end -%>

<% if @element.fixed? %>
Alchemy.SortableElements('[name="fixed-element-<%= @element.id %>"] .nested-elements');
<% end %>
Alchemy.SortableElements('[data-element-id="<%= @element.id %>"] .nested-elements');

Alchemy.growl('<%= Alchemy.t(:successfully_added_element) %>');
Alchemy.closeCurrentDialog();
Expand Down

0 comments on commit 0b0f932

Please sign in to comment.