Extract components to edit and add cards
This way we'll be able to reuse it in the SDG Management section while reusing the `title` method to set the page title.
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
<%= back_link_to index_path %>
|
||||
<%= header %>
|
||||
<%= render "admin/widget/cards/form", card: card %>
|
||||
19
app/components/admin/widget/cards/edit_component.rb
Normal file
19
app/components/admin/widget/cards/edit_component.rb
Normal file
@@ -0,0 +1,19 @@
|
||||
class Admin::Widget::Cards::EditComponent < ApplicationComponent
|
||||
include Header
|
||||
attr_reader :card, :index_path
|
||||
|
||||
def initialize(card, index_path:)
|
||||
@card = card
|
||||
@index_path = index_path
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def title
|
||||
if card.header?
|
||||
t("admin.homepage.edit.header_title")
|
||||
else
|
||||
t("admin.homepage.edit.card_title")
|
||||
end
|
||||
end
|
||||
end
|
||||
3
app/components/admin/widget/cards/new_component.html.erb
Normal file
3
app/components/admin/widget/cards/new_component.html.erb
Normal file
@@ -0,0 +1,3 @@
|
||||
<%= back_link_to index_path %>
|
||||
<%= header %>
|
||||
<%= render "admin/widget/cards/form", card: card %>
|
||||
19
app/components/admin/widget/cards/new_component.rb
Normal file
19
app/components/admin/widget/cards/new_component.rb
Normal file
@@ -0,0 +1,19 @@
|
||||
class Admin::Widget::Cards::NewComponent < ApplicationComponent
|
||||
include Header
|
||||
attr_reader :card, :index_path
|
||||
|
||||
def initialize(card, index_path:)
|
||||
@card = card
|
||||
@index_path = index_path
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def title
|
||||
if card.header?
|
||||
t("admin.homepage.new.header_title")
|
||||
else
|
||||
t("admin.homepage.new.card_title")
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,3 +1,4 @@
|
||||
class ApplicationComponent < ViewComponent::Base
|
||||
include SettingsHelper
|
||||
delegate :back_link_to, to: :helpers
|
||||
end
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
class SDG::Goals::ShowComponent < ApplicationComponent
|
||||
attr_reader :goal
|
||||
delegate :back_link_to, to: :helpers
|
||||
|
||||
def initialize(goal)
|
||||
@goal = goal
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
class SDGManagement::LocalTargets::FormComponent < ApplicationComponent
|
||||
delegate :back_link_to, to: :helpers
|
||||
include Header
|
||||
include TranslatableFormHelper
|
||||
include GlobalizeHelper
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<%= render "shared/globalize_locales", resource: @card %>
|
||||
<%= render "shared/globalize_locales", resource: card %>
|
||||
|
||||
<%= translatable_form_for [:admin, @page, @card] do |f| %>
|
||||
<%= render "shared/errors", resource: @card %>
|
||||
<%= translatable_form_for [namespace, card.cardable, card] do |f| %>
|
||||
<%= render "shared/errors", resource: card %>
|
||||
|
||||
<div class="row">
|
||||
<%= f.translatable_fields do |translations_form| %>
|
||||
@@ -30,7 +30,7 @@
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<% unless @card.header? %>
|
||||
<% unless card.header? %>
|
||||
<div class="column">
|
||||
<%= f.label :columns %>
|
||||
<p class="help-text"><%= t("admin.site_customization.pages.cards.columns_help") %></p>
|
||||
@@ -41,16 +41,16 @@
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<%= f.hidden_field :header, value: @card.header? %>
|
||||
<%= f.hidden_field :header, value: card.header? %>
|
||||
<div class="row">
|
||||
<div class="image-form">
|
||||
<div class="image small-12 column">
|
||||
<%= render "images/nested_image", imageable: @card, f: f %>
|
||||
<%= render "images/nested_image", imageable: card, f: f %>
|
||||
</div>
|
||||
</div>
|
||||
<div class="column">
|
||||
<%= f.submit(
|
||||
t("admin.homepage.#{admin_submit_action(@card)}.#{@card.header? ? "submit_header" : "submit_card"}"),
|
||||
t("admin.homepage.#{admin_submit_action(card)}.#{card.header? ? "submit_header" : "submit_card"}"),
|
||||
class: "button success"
|
||||
) %>
|
||||
</div>
|
||||
|
||||
@@ -1,11 +1 @@
|
||||
<%= back_link_to index_path %>
|
||||
|
||||
<h2>
|
||||
<% if @card.header? %>
|
||||
<%= t("admin.homepage.edit.header_title") %>
|
||||
<% else %>
|
||||
<%= t("admin.homepage.edit.card_title") %>
|
||||
<% end %>
|
||||
</h2>
|
||||
|
||||
<%= render "admin/widget/cards/form" %>
|
||||
<%= render Admin::Widget::Cards::EditComponent.new(@card, index_path: index_path) %>
|
||||
|
||||
@@ -1,11 +1 @@
|
||||
<%= back_link_to index_path %>
|
||||
|
||||
<h2>
|
||||
<% if @card.header? %>
|
||||
<%= t("admin.homepage.new.header_title") %>
|
||||
<% else %>
|
||||
<%= t("admin.homepage.new.card_title") %>
|
||||
<% end %>
|
||||
</h2>
|
||||
|
||||
<%= render "admin/widget/cards/form" %>
|
||||
<%= render Admin::Widget::Cards::NewComponent.new(@card, index_path: index_path) %>
|
||||
|
||||
Reference in New Issue
Block a user