From 070ef62806e4f48b96b1a129acabb6c71a76e707 Mon Sep 17 00:00:00 2001 From: f Date: Wed, 24 Feb 2021 16:31:57 -0300 Subject: [PATCH] las imagenes requeridas solo se pueden reemplazar --- app/helpers/application_helper.rb | 7 ++++--- app/views/posts/attributes/_image.haml | 12 +++++++----- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 23b4c99..8bb2d3b 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -92,10 +92,11 @@ module ApplicationHelper end # Busca la traducción de una etiqueta en los metadatos de un post - def post_label_t(*attribute, post:) - label = post_t(*attribute, post: post, type: :label) + def post_label_t(*attribute, post:, **extra) + required = extra.key?(:required) ? extra[:required] : post[attribute.first].required - label += I18n.t('posts.attributes.required.label') if post.send(attribute.first).required + label = post_t(*attribute, post: post, type: :label) + label += I18n.t('posts.attributes.required.label') if required label end diff --git a/app/views/posts/attributes/_image.haml b/app/views/posts/attributes/_image.haml index 2824b4c..c11f419 100644 --- a/app/views/posts/attributes/_image.haml +++ b/app/views/posts/attributes/_image.haml @@ -7,9 +7,11 @@ -# Mantener el valor si no enviamos ninguna imagen = hidden_field_tag "#{base}[#{attribute}][path]", metadata.value['path'] - .custom-control.custom-switch - = check_box_tag "#{base}[#{attribute}][path]", '', false, id: "#{base}_#{attribute}_destroy", class: 'custom-control-input' - = label_tag "#{base}_#{attribute}_destroy", t('posts.attributes.image.destroy'), class: 'custom-control-label' + -# Las imágenes requeridas solo se pueden reemplazar + - unless metadata.required + .custom-control.custom-switch + = check_box_tag "#{base}[#{attribute}][path]", '', false, id: "#{base}_#{attribute}_destroy", class: 'custom-control-input' + = label_tag "#{base}_#{attribute}_destroy", t('posts.attributes.image.destroy'), class: 'custom-control-label' - else = image_tag '', alt: metadata.value['description'], @@ -18,7 +20,7 @@ .custom-file = file_field(*field_name_for(base, attribute, :path), - **field_options(attribute, metadata), + **field_options(attribute, metadata, required: (metadata.required && !metadata.path?)), class: "custom-file-input #{invalid(post, attribute)}", accept: 'image/*', data: { preview: "#{attribute}-preview" }) = label_tag "#{base}_#{attribute}_path", @@ -28,7 +30,7 @@ .form-group = label_tag "#{base}_#{attribute}_description", - post_label_t(attribute, :description, post: post) + post_label_t(attribute, :description, post: post, required: false) = text_field(*field_name_for(base, attribute, :description), value: metadata.value['description'], dir: dir, lang: locale,