From b37679ed8eed83775f51e6fa6a48bbb9075d41e2 Mon Sep 17 00:00:00 2001
From: Arnaud Levy <contact@arnaudlevy.com>
Date: Fri, 3 Jun 2022 17:49:06 +0200
Subject: [PATCH] to js problem

---
 app/models/communication/block/template/base.rb      |  4 ++--
 app/models/communication/block/template/gallery.rb   |  4 ++++
 .../communication/block/template/gallery/image.rb    | 12 ++++++++++++
 .../blocks/templates/gallery/_edit.html.erb          |  3 ++-
 4 files changed, 20 insertions(+), 3 deletions(-)
 create mode 100644 app/models/communication/block/template/gallery/image.rb

diff --git a/app/models/communication/block/template/base.rb b/app/models/communication/block/template/base.rb
index 66ac3cfe2..f6081d597 100644
--- a/app/models/communication/block/template/base.rb
+++ b/app/models/communication/block/template/base.rb
@@ -95,14 +95,14 @@ class Communication::Block::Template::Base
     university.active_storage_blobs.find id
   end
 
-  protected
-
   def default_data
     {
       'elements' => []
     }
   end
 
+  protected
+
   def load_data
     return if @data_loaded
     # Accessing the data loads it from database
diff --git a/app/models/communication/block/template/gallery.rb b/app/models/communication/block/template/gallery.rb
index a74d7d5b8..9e2d66ee8 100644
--- a/app/models/communication/block/template/gallery.rb
+++ b/app/models/communication/block/template/gallery.rb
@@ -4,6 +4,10 @@ class Communication::Block::Template::Gallery < Communication::Block::Template::
 
   # has_select :layout, options: LAYOUTS, default: LAYOUTS.first
 
+  def element
+    Communication::Block::Template::Gallery::Image.new block
+  end
+
   def build_git_dependencies
     add_dependency active_storage_blobs
   end
diff --git a/app/models/communication/block/template/gallery/image.rb b/app/models/communication/block/template/gallery/image.rb
new file mode 100644
index 000000000..9308ff92c
--- /dev/null
+++ b/app/models/communication/block/template/gallery/image.rb
@@ -0,0 +1,12 @@
+class Communication::Block::Template::Gallery::Image < Communication::Block::Template::Base
+  has_image :image
+  has_rich_text :text
+
+  def default_data
+    {
+      'alt' => '',
+      'credit' => '',
+      'file' => {}
+    }
+  end
+end
diff --git a/app/views/admin/communication/blocks/templates/gallery/_edit.html.erb b/app/views/admin/communication/blocks/templates/gallery/_edit.html.erb
index 716de6c95..5817d1c3e 100644
--- a/app/views/admin/communication/blocks/templates/gallery/_edit.html.erb
+++ b/app/views/admin/communication/blocks/templates/gallery/_edit.html.erb
@@ -2,8 +2,9 @@
             layouts: Communication::Block::Template::Gallery::LAYOUTS,
             horizontal: true %>
 
+
 <a  class="<%= button_classes('mb-4') %>"
-    v-on:click="data.elements.push({alt: '', credit: '', file: {}})">
+    v-on:click="data.elements.push(<%= raw @block.template.element.default_data.to_s %>)">
     <%= t '.add_image' %>
 </a>
 
-- 
GitLab