diff --git a/app/helpers/admin/blocks_helper.rb b/app/helpers/admin/blocks_helper.rb index 387ff3e0129c4160299e8b6fc0b11c63e2c859d5..cbec783b00bfe67c78d91e6a1d4d935ca9792166 100644 --- a/app/helpers/admin/blocks_helper.rb +++ b/app/helpers/admin/blocks_helper.rb @@ -1,26 +1,28 @@ module Admin::BlocksHelper def block_component_edit(property, **options) - component = block_component property + component = block_component property, options[:element] partial = "admin/communication/blocks/components/#{component.kind}/edit" render partial, property: property, **options end def block_component_preview(property, **options) - component = block_component property + component = block_component property, options[:element] partial = "admin/communication/blocks/components/#{component.kind}/preview" render partial, property: property, **options end def block_component_static(property, **options) - component = block_component property + component = block_component property, options[:element] partial = "admin/communication/blocks/components/#{component.kind}/static" render partial, property: property, **options end protected - def block_component(property) - @block.template.public_send "#{property}_component" + def block_component(property, element) + template = element.nil? ? @block.template + : element + template.public_send "#{property}_component" end end diff --git a/app/models/communication/block/template/gallery/image.rb b/app/models/communication/block/template/gallery/image.rb index 9308ff92cc183dda80068213386adefba0e43bd6..40f0931306dc779ac7dc1bbab680e26e3913bf5b 100644 --- a/app/models/communication/block/template/gallery/image.rb +++ b/app/models/communication/block/template/gallery/image.rb @@ -1,5 +1,7 @@ class Communication::Block::Template::Gallery::Image < Communication::Block::Template::Base has_image :image + has_string :alt + has_rich_text :credit has_rich_text :text def default_data diff --git a/app/views/admin/communication/blocks/components/add_element/_edit.html.erb b/app/views/admin/communication/blocks/components/add_element/_edit.html.erb index a3c6095455af3ed8fd446f6bef3cabfe6a10671e..4f2a0da8acf7051ecbc894786f482dce39c3b28f 100644 --- a/app/views/admin/communication/blocks/components/add_element/_edit.html.erb +++ b/app/views/admin/communication/blocks/components/add_element/_edit.html.erb @@ -1,4 +1,4 @@ <a class="<%= button_classes('mb-4') %>" - v-on:click="data.elements.push(defaultElement)"> + v-on:click="data.elements.push(Object.assign({}, defaultElement))"> <%= label %> </a> diff --git a/app/views/admin/communication/blocks/components/rich_text/_edit.html.erb b/app/views/admin/communication/blocks/components/rich_text/_edit.html.erb index 77158e0ef35fc80ee31a8beb0d208e2c91f816d4..4de0040c6d3f3e74b790a07ab528b385375c8bf7 100644 --- a/app/views/admin/communication/blocks/components/rich_text/_edit.html.erb +++ b/app/views/admin/communication/blocks/components/rich_text/_edit.html.erb @@ -1,10 +1,28 @@ -<label class="form-label" for="<%= property %>"> - <%= t "admin.communication.blocks.templates.#{@block.template_kind}.edit.#{property}.label" %> +<% +template_kind = @block.template_kind +i18n_template = "admin.communication.blocks.templates.#{template_kind}.edit" +if element + model = 'element' + dom_id = "'element-' + index + '-#{property}'" + i18n_component = "#{i18n_template}.element.#{property}" +else + model = 'data' + dom_id = property + i18n_component = "#{i18n_template}.#{property}" +end +label ||= t "#{i18n_component}.label" +placeholder ||= t "#{i18n_component}.placeholder" +%> + +<label class="form-label" + aria-label="<%= label %>" + :for="<%= dom_id.html_safe %>"> + <%= label %> </label> <div class="summernote mb-3"> - <textarea id="<%= property %>" + <textarea :id="<%= dom_id.html_safe %>" class="form-control summernote-vue" - v-model="data.<%= property %>" + v-model="<%= model %>.<%= property %>" data-summernote-config="mini-list" - placeholder="<%= t "admin.communication.blocks.templates.#{@block.template_kind}.edit.#{property}.placeholder" %>"></textarea> + placeholder="<%= placeholder %>"></textarea> </div> diff --git a/app/views/admin/communication/blocks/components/string/_edit.html.erb b/app/views/admin/communication/blocks/components/string/_edit.html.erb index bd975931e8e4be7bf4726676deab08e5f48162e6..7aaad01b026388820d0291f9becafbda72acf7fb 100644 --- a/app/views/admin/communication/blocks/components/string/_edit.html.erb +++ b/app/views/admin/communication/blocks/components/string/_edit.html.erb @@ -1,16 +1,26 @@ <% template_kind = @block.template_kind -namespace = "admin.communication.blocks.templates.#{template_kind}.edit.#{property}" -label ||= t "#{namespace}.label" -placeholder ||= t "#{namespace}.placeholder" +i18n_template = "admin.communication.blocks.templates.#{template_kind}.edit" +if element + model = 'element' + dom_id = "'element-' + index + '-#{property}'" + i18n_component = "#{i18n_template}.element.#{property}" +else + model = 'data' + dom_id = property + i18n_component = "#{i18n_template}.#{property}" +end +label ||= t "#{i18n_component}.label" +placeholder ||= t "#{i18n_component}.placeholder" %> -<label class="form-label" for="<%= property %>"> + +<label class="form-label" + aria-label="<%= label %>" + :for="<%= dom_id.html_safe %>"> <%= label%> </label> -<div class="mb-3"> - <input id="<%= property %>" - class="form-control mb-3" - v-model="data.<%= property %>" - placeholder="<%= placeholder %>" - type="text" /> -</div> +<input :id="<%= dom_id.html_safe %>" + class="form-control mb-3" + v-model="<%= model %>.<%= property %>" + placeholder="<%= placeholder %>" + type="text" /> diff --git a/app/views/admin/communication/blocks/components/text/_edit.html.erb b/app/views/admin/communication/blocks/components/text/_edit.html.erb index c364efadbf97cf0a27855a98f607fa0c42cd756d..8d96456403af7b224cd0f77b6786f0674837b33b 100644 --- a/app/views/admin/communication/blocks/components/text/_edit.html.erb +++ b/app/views/admin/communication/blocks/components/text/_edit.html.erb @@ -1,13 +1,27 @@ <% +template_kind = @block.template_kind +i18n_template = "admin.communication.blocks.templates.#{template_kind}.edit" +if element + model = 'element' + dom_id = "'element-' + index + '-#{property}'" + i18n_component = "#{i18n_template}.element.#{property}" +else + model = 'data' + dom_id = property + i18n_component = "#{i18n_template}.#{property}" +end +label ||= t "#{i18n_component}.label" +placeholder ||= t "#{i18n_component}.placeholder" rows ||= 3 %> -<label class="form-label" for="<%= property %>"> - <%= t "admin.communication.blocks.templates.#{@block.template_kind}.edit.#{property}.label" %> + +<label class="form-label" + aria-label="<%= label %>" + :for="<%= dom_id.html_safe %>"> + <%= label %> </label> -<div class="mb-3"> - <textarea id="<%= property %>" - class="form-control" - rows="<%= rows %>" - v-model="data.<%= property %>" - placeholder="<%= t "admin.communication.blocks.templates.#{@block.template_kind}.edit.#{property}.placeholder" %>"></textarea> -</div> +<textarea :id="<%= dom_id.html_safe %>" + class="form-control mb-3" + rows="<%= rows %>" + v-model="<%= model %>.<%= property %>" + placeholder="<%= placeholder %>"></textarea> 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 a8c9c1003ca38b2ff79cdfb400bb267753c19e9d..66fe346e63185c149446dfd713129abce422abdd 100644 --- a/app/views/admin/communication/blocks/templates/gallery/_edit.html.erb +++ b/app/views/admin/communication/blocks/templates/gallery/_edit.html.erb @@ -1,3 +1,6 @@ +<% +element = @block.template.default_element +%> <%= render 'admin/communication/blocks/components/layouts/edit', horizontal: true %> @@ -5,7 +8,9 @@ label: t('.add_image') %> <draggable :list="data.elements" handle=".imageHandle" class="row"> - <div v-for="(image, imageIndex) in data.elements" class="col-xxl-2 col-xl-3 col-md-4 col-6"> + <div v-for="(element, index) in data.elements" + :key="index" + class="col-xxl-2 col-xl-3 col-md-4 col-6"> <div class="card"> <div class="card-header border-bottom"> <a class="btn ps-0 pt-0 imageHandle"> @@ -13,56 +18,27 @@ </a> <div class="float-end"> <a class="btn btn-sm btn-danger" - v-on:click="data.elements.splice(data.elements.indexOf(image), 1)" + v-on:click="data.elements.splice(data.elements.indexOf(element), 1)" title="<%= t '.remove_image' %>"> <i class="fas fa-times"></i> </a> </div> </div> - <img :src="getImageUrl(image.file)" class="img-fluid d-block" v-if="image.file.id" /> + <img :src="getImageUrl(element.file)" class="img-fluid d-block" v-if="element.file.id" /> <div class="card-body"> <label class="form-label" - :for="'image-file-' + imageIndex"> + :for="'element-' + index + '-file'"> <%= t '.image_label' %> </label> <input class="form-control mb-3" type="file" accept="image/*" - @change="onFileImageChange( $event, image, 'file' )" - :id="'image-file-' + imageIndex"> + @change="onFileImageChange( $event, element, 'file' )" + :id="'element-' + index + '-file'"> - <div class="mb-3"> - <label class="form-label" - aria-label="<%= t '.alt_label' %>" - :for="'image-alt-' + imageIndex"> - <%= t '.alt_label' %> - </label> - <input class="form-control mb-2" - type="text" - v-model="image.alt" - placeholder="<%= t '.alt_placeholder' %>" - :id="'image-alt-' + imageIndex"> - - <label class="form-label" - aria-label="<%= t '.text_label' %>" - :for="'image-text-' + imageIndex"> - <%= t '.text_label' %> - </label> - <textarea class="form-control mb-2" - v-model="image.text" - placeholder="<%= t '.text_placeholder' %>" - :id="'image-text-' + imageIndex"></textarea> - - <label class="form-label" - :for="'image-credit-' + imageIndex"> - <%= t '.credit_label' %> - </label> - <input type="text" - class="form-control" - v-model="image.credit" - :id="'image-credit-' + imageIndex" - placeholder="<%= t '.credit_placeholder' %>" /> - </div> + <%= block_component_edit :alt, element: element %> + <%= block_component_edit :credit, element: element %> + <%= block_component_edit :text, element: element %> </div> </div> </div> diff --git a/config/locales/communication/fr.yml b/config/locales/communication/fr.yml index 0da3340d68ea6e76f0e232ea4c070a0f4a4c5199..e29128dff5924d4af76de7345fca20cddae132a1 100644 --- a/config/locales/communication/fr.yml +++ b/config/locales/communication/fr.yml @@ -222,6 +222,16 @@ fr: label: Carrousel description: Les images sont présentées en grand, avec une navigation suivant / précédent. edit: + element: + text: + label: Texte + placeholder: Entrer le texte + alt: + label: Texte alternatif + placeholder: Entrer la description textuelle + credit: + label: Crédit + placeholder: Entrer le crédit de l'image ici add_image: Ajouter une image image_label: Image (.png, .jpg) alt_label: Texte alternatif