From d5d2d3f5244c5feeba637edf5fc704950e318be7 Mon Sep 17 00:00:00 2001
From: Arnaud Levy <contact@arnaudlevy.com>
Date: Thu, 13 Jul 2023 15:33:05 +0200
Subject: [PATCH] Fix #1154

---
 app/models/communication/block.rb              |  2 +-
 .../communication/block/template/contact.rb    |  2 ++
 .../blocks/templates/contact/_edit.html.erb    | 16 ++++++++++------
 .../blocks/templates/contact/_show.html.erb    | 14 +++++++++++++-
 config/locales/communication/en.yml            | 15 ++++++++++++---
 config/locales/communication/fr.yml            | 18 ++++++++++++------
 6 files changed, 50 insertions(+), 17 deletions(-)

diff --git a/app/models/communication/block.rb b/app/models/communication/block.rb
index f180bd78c..e3484e18e 100644
--- a/app/models/communication/block.rb
+++ b/app/models/communication/block.rb
@@ -87,7 +87,7 @@ class Communication::Block < ApplicationRecord
     basic: [:chapter, :image, :video, :sound, :datatable],
     storytelling: [:key_figures, :features, :gallery, :call_to_action, :testimonials, :timeline],
     references: [:pages, :posts, :organization_chart, :partners, :programs],
-    utilities: [:files, :definitions, :embed, :contact]
+    utilities: [:files, :definitions, :contact, :embed]
   }
 
   scope :published, -> { where(published: true) }
diff --git a/app/models/communication/block/template/contact.rb b/app/models/communication/block/template/contact.rb
index 4ddd562dd..b180c8a54 100644
--- a/app/models/communication/block/template/contact.rb
+++ b/app/models/communication/block/template/contact.rb
@@ -3,9 +3,11 @@ class Communication::Block::Template::Contact < Communication::Block::Template::
   has_component :description, :rich_text
   has_component :name, :string
   has_component :address, :text
+  has_component :information, :rich_text
   has_component :zipcode, :string
   has_component :city, :string
   has_component :country, :string
+  has_component :url, :string
   has_component :phone_numbers, :array
   has_component :emails, :array
 
diff --git a/app/views/admin/communication/blocks/templates/contact/_edit.html.erb b/app/views/admin/communication/blocks/templates/contact/_edit.html.erb
index 39326a4d5..1e1cf40d5 100644
--- a/app/views/admin/communication/blocks/templates/contact/_edit.html.erb
+++ b/app/views/admin/communication/blocks/templates/contact/_edit.html.erb
@@ -1,12 +1,13 @@
 <div class="row pure__row--small">
-  <div class="col-xl-6">
+  <div class="col-xxl-6">
     <%= block_component_edit block, :description %>
   </div>
 </div>
 <div class="row pure__row--small mb-4">
-  <div class="col-xl-6">
+  <div class="col-xxl-6">
     <%= osuny_panel t('.contacts') do %>
       <%= block_component_edit block, :name %>
+      <%= block_component_edit block, :information %>
       <%= block_component_edit block, :address %>
       <div class="row pure__row--small">
         <div class="col-md-4">
@@ -19,7 +20,10 @@
       <%= block_component_edit block, :country %>
     <% end %>
   </div>
-  <div class="col-xl-6">
+  <div class="col-xxl-6">
+    <%= osuny_panel t('.website') do %>
+      <%= block_component_edit block, :url %>
+    <% end %>
     <% 
     action = "<a class=\"#{ button_classes }\" v-on:click=\"data.phone_numbers.push('')\">#{ t('.add') }</a>"
     placeholder = t '.phones.placeholder'
@@ -68,13 +72,13 @@
     </div>
     <div class="flex-fill">
       <div class="row pure__row--small mb-n3">
-        <div class="col-xl-4">
+        <div class="col-xxl-4">
           <%= block_component_edit block, :title, template: @element %>
         </div>
-        <div class="col-xl-4 col-md-6">
+        <div class="col-xxl-4 col-md-6">
           <%= block_component_edit block, :time_slot_morning, template: @element %>
         </div>
-        <div class="col-xl-4 col-md-6">
+        <div class="col-xxl-4 col-md-6">
           <%= block_component_edit block, :time_slot_afternoon, template: @element %>
         </div>
       </div>
diff --git a/app/views/admin/communication/blocks/templates/contact/_show.html.erb b/app/views/admin/communication/blocks/templates/contact/_show.html.erb
index ff0377df3..071cc99c0 100644
--- a/app/views/admin/communication/blocks/templates/contact/_show.html.erb
+++ b/app/views/admin/communication/blocks/templates/contact/_show.html.erb
@@ -26,6 +26,9 @@ end
           <% unless block.template.name.blank? %>
             <p><%= block_component_show block, :name %></p>
           <% end %>
+          <% if block.template.information.present? %>
+            <%= block_component_show block, :information %>
+          <% end %>
           <div itemprop="address" itemscope itemtype="https://schema.org/PostalAddress">
             <span itemprop="streetAddress">
               <%= block_component_show block, :address %>
@@ -41,6 +44,13 @@ end
             </span>
           </div>
 
+          <% if block.template.url.present? %>
+            <% url = block.template.url %>
+            <a href="<%= social_website_to_url url %>" target="_blank" rel="noreferrer">
+              <%= social_website_to_s url %>
+            </a>
+          <% end %>
+
           <p>
             <% block.template.phone_numbers.each do |phone_number| %>
               <a itemprop="telephone" href="tel:<%= phone_number %>%>"><%= phone_number %></a><br>
@@ -54,7 +64,9 @@ end
           <% block.template.elements.each do |element| %>
             <li>
               <span><%= block_component_show block, :title, template: element %></span>
-              <span><time datetime="<%= block_component_show block, :time_slot_morning, template: element %>"><%= block_component_show block, :time_slot_morning, template: element %></time></span>
+              <% if element.time_slot_morning['to'].present? %>
+                <span><time datetime="<%= block_component_show block, :time_slot_morning, template: element %>"><%= block_component_show block, :time_slot_morning, template: element %></time></span>
+              <% end %>
               <span><time datetime="<%= block_component_show block, :time_slot_afternoon, template: element %>"><%= block_component_show block, :time_slot_afternoon, template: element %></time></span>
             </li>
           <% end %>
diff --git a/config/locales/communication/en.yml b/config/locales/communication/en.yml
index 144a82fb5..ac788040f 100644
--- a/config/locales/communication/en.yml
+++ b/config/locales/communication/en.yml
@@ -332,12 +332,14 @@ en:
                   label: Morning (if necessary)
                 time_slot_afternoon:
                   label: Afternoon (or full day)
+              information:
+                label: Additional data
+              mails:
+                label: Mails
+                placeholder: Enter the mail
               name:
                 label: Name (person, organization...)
                 placeholder: Enter the text
-              zipcode:
-                label: Zipcode
-                placeholder: Enter the zipcode
               mails:
                 label: Mails
                 placeholder: Enter the mail
@@ -345,6 +347,13 @@ en:
                 label: Telephone numbers
                 placeholder: Enter the number
               slots: Opening times
+              url:
+                label: URL
+                placeholder: https://...
+              website: Website
+              zipcode:
+                label: Zipcode
+                placeholder: Enter the zipcode
           datatable:
             description: A table of data, as responsive and accessible as possible.
             edit:
diff --git a/config/locales/communication/fr.yml b/config/locales/communication/fr.yml
index 63f58839b..9f52cbd60 100644
--- a/config/locales/communication/fr.yml
+++ b/config/locales/communication/fr.yml
@@ -332,19 +332,25 @@ fr:
                   label: Matin (si nécessaire)
                 time_slot_afternoon:
                   label: Après-midi (ou jour complet)
-              name:
-                label: Nom (personne, établissement...)
-                placeholder: Entrer le texte
-              zipcode:
-                label: Code postal
-                placeholder: Entrer le code postal
+              information:
+                label: Informations complémentaires
               mails:
                 label: Mails
                 placeholder: Entrer le mail
+              name:
+                label: Nom (personne, établissement...)
+                placeholder: Entrer le texte
               phones:
                 label: Téléphones
                 placeholder: Entrer le numéro
               slots: Horaires
+              url:
+                label: URL
+                placeholder: https://...
+              website: Site Web
+              zipcode:
+                label: Code postal
+                placeholder: Entrer le code postal
           datatable:
             description: Un tableau de données, aussi responsive et accessible que possible.
             edit:
-- 
GitLab