-
-
Notifications
You must be signed in to change notification settings - Fork 315
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 #2766 from sascha-karnatz/link-tab-components
Moved the link dialog partials into view components
- Loading branch information
Showing
19 changed files
with
452 additions
and
148 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# frozen_string_literal: true | ||
|
||
module Alchemy | ||
module Admin | ||
module LinkDialog | ||
class AnchorTab < BaseTab | ||
def title | ||
Alchemy.t("link_overlay_tab_label.anchor") | ||
end | ||
|
||
def name | ||
:anchor | ||
end | ||
|
||
def fields | ||
[ | ||
anchor_select, | ||
title_input | ||
] | ||
end | ||
|
||
def message | ||
render_message(:info, content_tag("p", Alchemy.t(:anchor_link_headline))) | ||
end | ||
|
||
private | ||
|
||
def anchor_select | ||
label = label_tag("anchor_link", Alchemy.t(:anchor), class: "control-label") | ||
select = select_tag(:anchor_link, | ||
options_for_select([[Alchemy.t("Please choose"), ""]]), | ||
is: "alchemy-select") | ||
content_tag("div", label + select, class: "input select") | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# frozen_string_literal: true | ||
|
||
module Alchemy | ||
module Admin | ||
module LinkDialog | ||
class BaseTab < ViewComponent::Base | ||
include BaseHelper | ||
|
||
erb_template <<~ERB | ||
<sl-tab slot="nav" panel="<%= panel_name %>"><%= title %></sl-tab> | ||
<sl-tab-panel name="<%= panel_name %>"> | ||
<form data-link-form-type="<%= name %>"> | ||
<%= message %> | ||
<% fields.each do |field| %> | ||
<%= field %> | ||
<% end %> | ||
<div class="submit"> | ||
<%= button_tag(Alchemy.t(:apply)) %> | ||
</div> | ||
</form> | ||
</sl-tab-panel> | ||
ERB | ||
|
||
def title | ||
raise ArgumentError, "The tab needs to have a title" | ||
end | ||
|
||
def name | ||
raise ArgumentError, "The tab needs to have a name" | ||
end | ||
|
||
def fields | ||
[] | ||
end | ||
|
||
def message | ||
"" | ||
end | ||
|
||
private | ||
|
||
def panel_name | ||
"overlay_tab_#{name}_link" | ||
end | ||
|
||
def title_input | ||
input_name = "#{name}_link_title" | ||
label = label_tag(input_name, Alchemy.t(:link_title), class: "control-label") | ||
input = text_field_tag input_name, "", class: "link_title" | ||
content_tag("div", label + input, class: "input text") | ||
end | ||
|
||
def target_select | ||
select_name = "#{name}_link_target" | ||
label = label_tag(select_name, Alchemy.t("Open Link in"), class: "control-label") | ||
select = select_tag(select_name, options_for_select(Alchemy::Page.link_target_options, @target), class: "link_target") | ||
content_tag("div", label + select, class: "input select") | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# frozen_string_literal: true | ||
|
||
module Alchemy | ||
module Admin | ||
module LinkDialog | ||
class ExternalTab < BaseTab | ||
def title | ||
Alchemy.t("link_overlay_tab_label.external") | ||
end | ||
|
||
def name | ||
:external | ||
end | ||
|
||
def fields | ||
[ | ||
url_input, | ||
title_input, | ||
target_select | ||
] | ||
end | ||
|
||
def message | ||
main_message = content_tag("h3", Alchemy.t(:enter_external_link)) + | ||
content_tag("p", Alchemy.t(:external_link_notice_1)) + | ||
content_tag("p", Alchemy.t(:external_link_notice_2)) | ||
|
||
render_message(:info, main_message) + | ||
content_tag("div", content_tag("ul"), id: "errors", class: "errors") | ||
end | ||
|
||
private | ||
|
||
def url_input | ||
label = label_tag("external_link", "URL", class: "control-label") | ||
input = text_field_tag "external_link", "" | ||
content_tag("div", label + input, class: "input text") | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# frozen_string_literal: true | ||
|
||
module Alchemy | ||
module Admin | ||
module LinkDialog | ||
class FileTab < BaseTab | ||
delegate :alchemy, to: :helpers | ||
|
||
def title | ||
Alchemy.t("link_overlay_tab_label.file") | ||
end | ||
|
||
def name | ||
:file | ||
end | ||
|
||
def fields | ||
[ | ||
attachment_select, | ||
title_input, | ||
target_select | ||
] | ||
end | ||
|
||
def message | ||
render_message(:info, content_tag("h3", Alchemy.t(:choose_file_to_link))) | ||
end | ||
|
||
private | ||
|
||
def attachments | ||
@_attachments ||= Attachment.all.collect { |f| | ||
[f.name, alchemy.download_attachment_path(id: f.id, name: f.slug)] | ||
} | ||
end | ||
|
||
def attachment_select | ||
label = label_tag("file_link", Alchemy.t(:file), class: "control-label") | ||
select = select_tag "file_link", | ||
options_for_select(attachments), | ||
prompt: Alchemy.t("Please choose"), | ||
is: "alchemy-select" | ||
content_tag("div", label + select, class: "input select") | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# frozen_string_literal: true | ||
|
||
module Alchemy | ||
module Admin | ||
module LinkDialog | ||
class InternalTab < BaseTab | ||
def title | ||
Alchemy.t("link_overlay_tab_label.internal") | ||
end | ||
|
||
def name | ||
:internal | ||
end | ||
|
||
def fields | ||
[ | ||
page_select, | ||
dom_id_select, | ||
title_input, | ||
target_select | ||
] | ||
end | ||
|
||
def message | ||
main_message = content_tag("h3", Alchemy.t(:internal_link_headline)) + | ||
content_tag("p", Alchemy.t(:internal_link_page_elements_explanation)) | ||
render_message(:info, main_message) | ||
end | ||
|
||
private | ||
|
||
def page_select | ||
label = label_tag("internal_link", Alchemy.t(:page), class: "control-label") | ||
input = text_field_tag("internal_link", "", id: "internal_link", class: "alchemy_selectbox full_width") | ||
content_tag("div", label + input, class: "input select") | ||
end | ||
|
||
def dom_id_select | ||
label = label_tag("element_anchor", Alchemy.t(:anchor), class: "control-label") | ||
options = {id: "element_anchor", class: "alchemy_selectbox full_width", disabled: true, placeholder: Alchemy.t("Select a page first")} | ||
input = text_field_tag("element_anchor", nil, options) | ||
content_tag("div", label + input, class: "input select") | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# frozen_string_literal: true | ||
|
||
module Alchemy | ||
module Admin | ||
module LinkDialog | ||
class Tabs < ViewComponent::Base | ||
erb_template <<~ERB | ||
<sl-tab-group id="overlay_tabs"> | ||
<% tabs.each do |tab| %> | ||
<%= render tab.new %> | ||
<% end %> | ||
</sl-tab-group> | ||
ERB | ||
|
||
def tabs | ||
Alchemy.link_dialog_tabs | ||
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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.