-
Notifications
You must be signed in to change notification settings - Fork 194
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate featured links to new add-another
Call the new publishing components add another template for featured links
- Loading branch information
Showing
5 changed files
with
83 additions
and
77 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,77 +1,53 @@ | ||
<% | ||
featured_links = form.object.featured_links | ||
featured_links = [LocalisedModel.new(FeaturedLink.new, I18n.default_locale)] unless featured_links.any? | ||
model = form.object.model_name.singular | ||
<%= form.fields_for :featured_links, featured_link do |featured_link_form| %> | ||
<% if @translation_locale && @translation_locale.code != I18n.default_locale %> | ||
<%= render "components/translated_input", { | ||
input: { | ||
label: { | ||
text: "Title", | ||
}, | ||
heading_size: "m", | ||
value: featured_link_form.object.title, | ||
name: "#{model}[featured_links_attributes][#{index}][title]", | ||
id: "#{model}_featured_links[#{index}]_title", | ||
}, | ||
details: { | ||
text: featured_link_form.object.title, | ||
}, | ||
} %> | ||
if form.object.respond_to?(:visible_featured_links_count) | ||
visible_links = form.object.visible_featured_links_count | ||
else | ||
visible_links = FeaturedLink::DEFAULT_SET_SIZE | ||
end | ||
<%= render "components/translated_input", { | ||
input: { | ||
label: { | ||
text: "URL", | ||
}, | ||
heading_size: "m", | ||
value: featured_link_form.object.url, | ||
name: "#{model}[featured_links_attributes][#{index}][url]", | ||
id: "#{model}_featured_links[#{index}]_url", | ||
}, | ||
details: { | ||
text: featured_link_form.object.url, | ||
}, | ||
} %> | ||
<% else %> | ||
<%= render "govuk_publishing_components/components/input", { | ||
label: { | ||
text: "Title", | ||
}, | ||
heading_size: "m", | ||
value: featured_link_form.object.title, | ||
name: "#{model}[featured_links_attributes][#{index}][title]", | ||
id: "#{model}_featured_links[#{index}]_title", | ||
} %> | ||
remove_banner ||= false | ||
%> | ||
<% unless remove_banner %> | ||
<%= render "govuk_publishing_components/components/inset_text", { | ||
text: "Only the first #{visible_links} links will be shown on the public site.", | ||
} %> | ||
<% end %> | ||
|
||
<div data-module="AddAnother" data-add-text="Add another featured link"> | ||
<%= form.fields_for :featured_links do |featured_link_form| %> | ||
<div class="js-duplicate-fields-set govuk-!-margin-bottom-6"> | ||
<% if @translation_locale && @translation_locale.code != I18n.default_locale %> | ||
<%= render "components/translated_input", { | ||
input: { | ||
label: { | ||
text: "Title", | ||
}, | ||
heading_size: "m", | ||
value: featured_link_form.object.title, | ||
name: "#{model}[featured_links_attributes][#{featured_link_form.index}][title]", | ||
id: "#{model}_featured_links[#{featured_link_form.index}]_title", | ||
}, | ||
details: { | ||
text: featured_link_form.object.title, | ||
}, | ||
} %> | ||
<%= render "components/translated_input", { | ||
input: { | ||
label: { | ||
text: "URL", | ||
}, | ||
heading_size: "m", | ||
value: featured_link_form.object.url, | ||
name: "#{model}[featured_links_attributes][#{featured_link_form.index}][url]", | ||
id: "#{model}_featured_links[#{featured_link_form.index}]_url", | ||
}, | ||
details: { | ||
text: featured_link_form.object.url, | ||
}, | ||
} %> | ||
<% else %> | ||
<%= render "govuk_publishing_components/components/input", { | ||
label: { | ||
text: "Title", | ||
}, | ||
heading_size: "m", | ||
value: featured_link_form.object.title, | ||
name: "#{model}[featured_links_attributes][#{featured_link_form.index}][title]", | ||
id: "#{model}_featured_links[#{featured_link_form.index}]_title", | ||
} %> | ||
<%= render "govuk_publishing_components/components/input", { | ||
label: { | ||
text: "URL", | ||
}, | ||
heading_size: "m", | ||
value: featured_link_form.object.url, | ||
name: "#{model}[featured_links_attributes][#{featured_link_form.index}][url]", | ||
id: "#{model}_featured_links[#{featured_link_form.index}]_url", | ||
} %> | ||
<% end %> | ||
</div> | ||
<%= render "govuk_publishing_components/components/input", { | ||
label: { | ||
text: "URL", | ||
}, | ||
heading_size: "m", | ||
value: featured_link_form.object.url, | ||
name: "#{model}[featured_links_attributes][#{index}][url]", | ||
id: "#{model}_featured_links[#{index}]_url", | ||
} %> | ||
<% end %> | ||
</div> | ||
<% 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,30 @@ | ||
<% | ||
featured_links = form.object.featured_links | ||
new_featured_link = LocalisedModel.new(FeaturedLink.new, I18n.default_locale) | ||
model = form.object.model_name.singular | ||
|
||
if form.object.respond_to?(:visible_featured_links_count) | ||
visible_links = form.object.visible_featured_links_count | ||
else | ||
visible_links = FeaturedLink::DEFAULT_SET_SIZE | ||
end | ||
|
||
remove_banner ||= false | ||
%> | ||
<% unless remove_banner %> | ||
<%= render "govuk_publishing_components/components/inset_text", { | ||
text: "Only the first #{visible_links} links will be shown on the public site.", | ||
} %> | ||
<% end %> | ||
<%= render "govuk_publishing_components/components/add_another", { | ||
add_button_text: "Add another featured link", | ||
items: featured_links.each_with_index.map do |featured_link, index| | ||
{ | ||
fields: render(partial: "admin/shared/featured_link_fields", locals: { form:, featured_link:, index:, model: }), | ||
destroy_checkbox: render("govuk_publishing_components/components/checkboxes", { name: "#{model}[featured_links_attributes][#{index}[_destroy]", items: [{label: "Delete", value: "1" }]}) | ||
} | ||
end, | ||
empty: render(partial: "admin/shared/featured_link_fields", locals: { form:, featured_link: new_featured_link, index: featured_links.length, model: }), | ||
} %> |
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