Skip to content

Commit

Permalink
Add color field and custom logo
Browse files Browse the repository at this point in the history
  • Loading branch information
Kagemaru committed Jun 13, 2024
1 parent 9de85d6 commit 2ebcf86
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 44 deletions.
23 changes: 8 additions & 15 deletions app/cells/decidim_zuerich/newsletter_templates/test/show.erb
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
<% if organization_primary_color %>
<style>
table.button table td {
background: <%= organization_primary_color %> !important
}
.decidim-bar {
background_color: <%= color %>
}
</style>
<% end %>

<table class="main container">
<tr>
<td class="decidim-bar">
<td class="decidim-bar" style="background-color: <%= color %>;">
<table class="row collapse">
<tr>
<th class="small-3 large-3 first columns decidim-bar">
<th class="small-3 large-3 first columns decidim-bar" style="background-color: <%= color %>;">
<table>
<tr>
<th>
</th>
</tr>
</table>
</th>
<th class="small-6 large-6 columns decidim-bar">
<th class="small-6 large-6 columns decidim-bar" style="background-color: <%= color %>;">
<table>
<tr>
<th>
Expand All @@ -30,7 +27,7 @@ table.button table td {
</tr>
</table>
</th>
<th class="small-3 large-3 last columns decidim-bar">
<th class="small-3 large-3 last columns decidim-bar" style="background-color: <%= color %>;">
<table>
<tr>
<th>
Expand Down Expand Up @@ -94,11 +91,7 @@ table.button table td {
<%= body %>
<br />
<% fields.each do |field| %>
<%= field %>
<br />
<% end %>
<%= color %>

</th>
<th class="expander"></th>
Expand Down
20 changes: 10 additions & 10 deletions app/cells/decidim_zuerich/newsletter_templates/test_cell.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,6 @@ def body
parse_interpolations(uninterpolated_body, recipient_user, newsletter.id)
end

def fields
%i[boolean integer string text].map do |type|
field = model.settings.send("field_#{type}")
translated = translated_attribute(field)
parse_interpolations(translated, recipient_user, newsletter.id)
end
end

def uninterpolated_body
translated_attribute(model.settings.body)
end
Expand All @@ -43,6 +35,10 @@ def cta_text
)
end

def color
model.settings.color
end

def cta_url
translated_attribute(model.settings.cta_url)
end
Expand All @@ -59,8 +55,12 @@ def main_image_url
newsletter.template.images_container.attached_uploader(:main_image).url(host: organization.host)
end

def organization_primary_color
organization.colors["primary"]
def custom_logo
image_tag custom_logo_url
end

def custom_logo_url
newsletter.template.images_container.attached_uploader(:custom_logo).url(host: organization.host)
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@
<%= settings_fields.text_field :cta_url, label: t(".cta_url") %>
<%= settings_fields.translated :editor, :body, label: t(".body") %>
<%= settings_fields.color_field :color, label: t(".color") %>
<%= settings_fields.check_box :field_boolean, label: "Boolean" %>
<%= settings_fields.number_field :field_integer, label: "Integer" %>
<%= settings_fields.translated :text_field, :field_string, label: "String" %>
<%= settings_fields.translated :editor, :field_text, label: "Text" %>
<%= settings_fields.translated :editor, :body, label: t(".body") %>
<% end %>
<% form.fields_for :images, form.object.images do |images_fields| %>
<%= images_fields.upload :custom_logo, label: t(".custom_logo") %>
<%= images_fields.upload :main_image, label: t(".main_image") %>
<% end %>

Expand Down
23 changes: 10 additions & 13 deletions config/initializers/newsletter_templates/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
content_block.public_name_key = "decidim_zuerich.newsletter_templates.test.name"

content_block.images = [
{
name: :custom_logo,
uploader: "Decidim::NewsletterTemplateImageUploader",
preview: -> { organization.logo }
},
{
name: :main_image,
uploader: "Decidim::NewsletterTemplateImageUploader",
Expand All @@ -15,18 +20,10 @@
opts = -> (map) { {type: :text, translated: true, preview: "-"}.merge(map) }

content_block.settings do |settings|
settings.attribute(:introduction, opts.(preview: -> { t.("introduction_preview") }))
settings.attribute(:body, opts.(preview: -> { t.("body_preview") } ))
settings.attribute(:cta_text, opts.(preview: -> { t.("cta_text_preview") } ))
settings.attribute(:cta_url, opts.(preview: "http://google.com" ))
settings.attribute(:field_boolean, opts.(type: :boolean, preview: "Wahrheit" ))
settings.attribute(:field_integer, opts.(type: :integer, preview: "Zahl" ))
settings.attribute(:field_string, opts.(type: :string, preview: "String" ))
settings.attribute(:field_text, opts.(type: :text, preview: "Text" ))
settings.attribute(:field_array, opts.(type: :array, preview: "Array" ))
settings.attribute(:field_enum, opts.(type: :enum, preview: "Enum" ))
settings.attribute(:field_select, opts.(type: :select, preview: "Select" ))
settings.attribute(:field_scope, opts.(type: :scope, preview: "Scope" ))
settings.attribute(:field_time, opts.(type: :time, preview: "Zeit" ))
settings.attribute(:introduction, opts.(preview: -> { t.("introduction_preview") }))
settings.attribute(:body, opts.(preview: -> { t.("body_preview") } ))
settings.attribute(:cta_text, opts.(preview: -> { t.("cta_text_preview") } ))
settings.attribute(:cta_url, opts.(preview: "http://google.com", translated: false ))
settings.attribute(:color, opts.(preview: "Farbe", translated: false ))
end
end
2 changes: 1 addition & 1 deletion config/locales/de.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ de:
not_found:
content_doesnt_exist: Diese Seite wurde leider nicht gefunden. Wir bitten um Verständnis.
title: Ups!
decidim:
decidim:
admin:
menu:
clean: Datenbereinigung
Expand Down

0 comments on commit 2ebcf86

Please sign in to comment.