diff --git a/app/models/communication/block/template/base.rb b/app/models/communication/block/template/base.rb index 66ac3cfe2bad3104fc0338ad7ff400fe3bd7cffa..f6081d597f1c94566aabe1a44dc4ba549b11f9aa 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 a74d7d5b8dc5aa9e096de874fb25f75df46b4466..9e2d66ee8ff9475db3f59d63f07c30b3f8376458 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 0000000000000000000000000000000000000000..9308ff92cc183dda80068213386adefba0e43bd6 --- /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 716de6c95ed889d0c88f483d518e26aee6446288..5817d1c3e3a7f3e7181e926c60e23985acf173aa 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>