-
-
Notifications
You must be signed in to change notification settings - Fork 314
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3053 from AlchemyCMS/turbo-frames-create-element
Use turbo frame and stream to create element
- Loading branch information
Showing
15 changed files
with
158 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
app/views/alchemy/admin/elements/_clipboard_button.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<%= render Alchemy::Admin::ToolbarButton.new( | ||
url: alchemy.admin_clipboard_path(remarkable_type: "elements"), | ||
label: Alchemy.t("Show clipboard"), | ||
icon: :clipboard, | ||
icon_style: clipboard_empty?("elements") ? "line" : "fill", | ||
dialog_options: { | ||
title: Alchemy.t("Clipboard"), | ||
size: "400x305" | ||
}, | ||
link_options: { | ||
id: "clipboard_button" | ||
}, | ||
if_permitted_to: [:index, :alchemy_admin_clipboard] | ||
) %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<% opts = { | ||
partial: "alchemy/admin/elements/element", | ||
locals: { | ||
element: Alchemy::ElementEditor.new(@element), | ||
created: true | ||
} | ||
} %> | ||
<% if @element.fixed? %> | ||
<% target = "fixed_element_#{@element.id}" %> | ||
<% elsif @element.parent_element %> | ||
<% target = "element_#{@element.parent_element_id}_nested_elements" %> | ||
<% else %> | ||
<% target = "main-content-elements" %> | ||
<% end %> | ||
<%- if @cut_element_id -%> | ||
<%= turbo_stream.remove "element_#{@cut_element_id}" %> | ||
<% end %> | ||
<% if @insert_at_top %> | ||
<%= turbo_stream.prepend target, **opts %> | ||
<% else %> | ||
<%= turbo_stream.append target, **opts %> | ||
<% end %> | ||
<%= turbo_stream.replace "clipboard_button", | ||
partial: "alchemy/admin/elements/clipboard_button" %> | ||
|
||
<alchemy-growl> | ||
<%= Alchemy.t(:successfully_added_element) %> | ||
</alchemy-growl> | ||
|
||
<alchemy-action name="closeCurrentDialog"></alchemy-action> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
require "rails_helper" | ||
|
||
RSpec.describe Alchemy::Admin::FormHelper do | ||
describe "#alchemy_form_for" do | ||
subject { helper.alchemy_form_for(resource) {} } | ||
|
||
let(:resource) do | ||
[alchemy, :admin, Alchemy::Element.new(name: "article")] | ||
end | ||
|
||
it "returns a form with alchemy class" do | ||
expect(subject).to have_css(".alchemy") | ||
end | ||
|
||
context "if options[:remote] is given" do | ||
context "and set to true" do | ||
subject { helper.alchemy_form_for(resource, remote: true) {} } | ||
|
||
it "makes the form remote" do | ||
expect(subject).to have_css("form[data-remote]") | ||
end | ||
end | ||
|
||
context "and set to false" do | ||
subject { helper.alchemy_form_for(resource, remote: false) {} } | ||
|
||
it "makes the form non-remote" do | ||
expect(subject).to have_css("form") | ||
expect(subject).to_not have_css("form[data-remote]") | ||
end | ||
end | ||
end | ||
|
||
context "if options[:remote] is not given" do | ||
context "and request is xhr" do | ||
before do | ||
allow(helper).to receive(:request).and_return(double(xhr?: true)) | ||
end | ||
|
||
it "makes the form remote" do | ||
expect(subject).to have_css("form[data-remote]") | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters