From 69712a306e131e48f6c7416002e2e8f1f1cee515 Mon Sep 17 00:00:00 2001 From: f Date: Mon, 25 Jul 2022 16:01:08 -0300 Subject: [PATCH] equiparar file con image #7076 --- app/views/posts/attributes/_file.haml | 16 +++++++++------- app/views/posts/attributes/_image.haml | 3 +-- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/app/views/posts/attributes/_file.haml b/app/views/posts/attributes/_file.haml index 19175b9c..54f9f81a 100644 --- a/app/views/posts/attributes/_file.haml +++ b/app/views/posts/attributes/_file.haml @@ -1,7 +1,5 @@ .form-group - if metadata.static_file - = hidden_field_tag "#{base}[#{attribute}][path]", metadata.value['path'] - - case metadata.static_file.blob.content_type - when %r{\Avideo/} = video_tag url_for(metadata.static_file), @@ -14,13 +12,17 @@ - else = link_to t('posts.attribute_ro.file.download'), url_for(metadata.static_file) - .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.file.destroy'), class: 'custom-control-label' + -# Mantener el valor si no enviamos ninguna imagen + = hidden_field_tag "#{base}[#{attribute}][path]", metadata.value['path'] + -# Los archivos requeridos 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.file.destroy'), class: 'custom-control-label' .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)}", data: { preview: "#{attribute}-preview" }) = label_tag "#{base}_#{attribute}_path", @@ -30,7 +32,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, diff --git a/app/views/posts/attributes/_image.haml b/app/views/posts/attributes/_image.haml index c11f4196..f4d9bb3d 100644 --- a/app/views/posts/attributes/_image.haml +++ b/app/views/posts/attributes/_image.haml @@ -1,5 +1,5 @@ .form-group - - if metadata.uploaded? + - if metadata.static_file = image_tag url_for(metadata.static_file), alt: metadata.value['description'], class: 'img-fluid', @@ -37,4 +37,3 @@ **field_options(attribute, metadata, required: false)) = render 'posts/attribute_feedback', post: post, attribute: [attribute, :description], metadata: metadata -