Skip to content

Commit

Permalink
Set parent element id when pasting from clipboard
Browse files Browse the repository at this point in the history
Set the parent element id for elements created from clipboard.

Fixes #817
  • Loading branch information
tvdeyen committed May 14, 2018
1 parent c2da6d3 commit cfce49f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
5 changes: 4 additions & 1 deletion app/controllers/alchemy/admin/elements_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,10 @@ def element_from_clipboard

def paste_element_from_clipboard
@source_element = Element.find(element_from_clipboard['id'])
new_attributes = {page_id: @page.id}
new_attributes = {
parent_element_id: params[:element][:parent_element_id],
page_id: @page.id
}
if @page.can_have_cells?
new_attributes = new_attributes.merge({cell_id: find_or_create_cell.try(:id)})
end
Expand Down
3 changes: 2 additions & 1 deletion app/views/alchemy/admin/elements/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
</div>
<div id="paste_element_tab">
<%= alchemy_form_for([:admin, @element]) do |f| %>
<%= f.hidden_field(:page_id) %>
<%= f.hidden_field :page_id %>
<%= f.hidden_field :parent_element_id, value: @parent_element.try(:id) %>
<div class="input select">
<label for="paste_from_clipboard" class="control-label"><%= Alchemy.t("Element") %></label>
<%= select_tag 'paste_from_clipboard',
Expand Down
10 changes: 10 additions & 0 deletions spec/controllers/alchemy/admin/elements_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,16 @@ module Alchemy
expect(session[:alchemy_clipboard]['elements'].detect { |item| item['id'] == element_in_clipboard.id.to_s }).to be_nil
end
end

context "with parent_element_id given" do
let(:element_in_clipboard) { create(:alchemy_element, name: 'slide', parent_element: create(:alchemy_element, name: 'slider', page: alchemy_page), page: alchemy_page) }
let(:parent_element) { create(:alchemy_element, :with_nestable_elements, page: alchemy_page) }

it "moves the element to new parent" do
alchemy_xhr :post, :create, {paste_from_clipboard: element_in_clipboard.id, element: {page_id: alchemy_page.id, parent_element_id: parent_element.id}}
expect(Alchemy::Element.last.parent_element_id).to eq(parent_element.id)
end
end
end

context 'if element could not be saved' do
Expand Down

0 comments on commit cfce49f

Please sign in to comment.