diff --git a/app/javascript/controllers/array_controller.js b/app/javascript/controllers/array_controller.js index 7b0ba8c4..5540e839 100644 --- a/app/javascript/controllers/array_controller.js +++ b/app/javascript/controllers/array_controller.js @@ -6,7 +6,11 @@ export default class extends Controller { connect() { // TODO: Stimulus >1 this.newArrayValueURL = new URL(window.location.origin); - this.newArrayValueURL.pathname = this.element.dataset.arrayNewArrayValue; + + const [ pathname, search ] = this.element.dataset.arrayNewArrayValue.split("?"); + + this.newArrayValueURL.pathname = pathname; + this.newArrayValueURL.search = `?${search}`; this.originalValue = JSON.parse(this.element.dataset.arrayOriginalValue); } diff --git a/app/models/metadata_new_predefined_value.rb b/app/models/metadata_new_predefined_value.rb index ff839759..929934b2 100644 --- a/app/models/metadata_new_predefined_value.rb +++ b/app/models/metadata_new_predefined_value.rb @@ -1,4 +1,8 @@ # frozen_string_literal: true # Nueva interfaz -class MetadataNewPredefinedValue < MetadataPredefinedValue; end +class MetadataNewPredefinedValue < MetadataPredefinedValue + def values + @values ||= (required ? {} : { I18n.t('posts.attributes.new_predefined_value.empty') => '' }).merge(super) + end +end diff --git a/app/views/posts/_new_related_post.haml b/app/views/posts/_new_related_post.haml index 7dcb264f..236abc42 100644 --- a/app/views/posts/_new_related_post.haml +++ b/app/views/posts/_new_related_post.haml @@ -26,6 +26,7 @@ - form_params[:modal_id] = form_params[:show] = modal_id = random_id -# Asociar un modal con una tarjeta - form_params[:result_id] = card_id + - form_params[:inverse] = local_assigns[:inverse] -# @todo Poder indicar en qué elemento queremos asociar lo descargado = render 'bootstrap/btn', content: t('.edit'), data: { controller: 'htmx', action: 'modal#showAnother htmx#getUrlOnce', 'modal-show-value': modal_id, 'htmx-get-url-param': site_posts_modal_path(post.site, **form_params) }, id: random_id diff --git a/app/views/posts/attributes/_new_array.haml b/app/views/posts/attributes/_new_array.haml index 56899fe3..1ed82e98 100644 --- a/app/views/posts/attributes/_new_array.haml +++ b/app/views/posts/attributes/_new_array.haml @@ -19,7 +19,7 @@ como obligatorio al validar el formulario. .d-flex.align-items-center.justify-content-between %div - = label_tag id, post_label_t(attribute, post: post), class: 'mb-0' + = label_tag id, post_label_t(attribute, post: post), class: 'mb-0 h3' = render 'posts/required_checkbox', required: metadata.required, name: name, initial: metadata.empty? = render 'bootstrap/btn', content: t('.edit'), action: 'modal#show' -# Mostramos la lista de valores actuales. diff --git a/app/views/posts/attributes/_new_belongs_to.haml b/app/views/posts/attributes/_new_belongs_to.haml index 7f9a66dd..849b3eff 100644 --- a/app/views/posts/attributes/_new_belongs_to.haml +++ b/app/views/posts/attributes/_new_belongs_to.haml @@ -46,7 +46,7 @@ .row.no-gutters.placeholder-glow{ data: { 'array-target': 'current' } } -# @todo issue-7537 - if !metadata.empty? && (indexed_post = site.indexed_posts.find_by(post_id: metadata.value)) - = render 'posts/new_related_post', post: indexed_post, attribute: metadata.type + = render 'posts/new_related_post', post: indexed_post, attribute: metadata.type, inverse: metadata.inverse = render 'bootstrap/modal', id: id, modal_content_attributes: { class: 'h-100' }, hide_actions: ['array#cancel'], keydown_actions: %w[keydown->array#cancelWithEscape] do - content_for :"#{id}_header" do diff --git a/app/views/posts/attributes/_new_has_and_belongs_to_many.haml b/app/views/posts/attributes/_new_has_and_belongs_to_many.haml index 0859ae33..6959ecf7 100644 --- a/app/views/posts/attributes/_new_has_and_belongs_to_many.haml +++ b/app/views/posts/attributes/_new_has_and_belongs_to_many.haml @@ -20,7 +20,7 @@ controllers = %w[modal array] controllers << 'required-checkbox' if metadata.required -%div{ id: modal_id, data: { controller: controllers.join(' '), 'array-original-value': metadata.value.to_json, 'array-new-array-value': site_posts_new_related_post_path(site) } } +%div{ id: modal_id, data: { controller: controllers.join(' '), 'array-original-value': metadata.value.to_json, 'array-new-array-value': site_posts_new_related_post_path(site, inverse: metadata.inverse) } } %template{ data: { 'array-target': 'placeholder' } } .col.p-3{ 'aria-hidden': 'true' } %span.placeholder.w-100 @@ -29,7 +29,7 @@ = hidden_field_tag name, '' .d-flex.align-items-center.justify-content-between %div - = label_tag id, post_label_t(attribute, post: post) + = label_tag id, post_label_t(attribute, post: post), class: 'h3' = render 'posts/required_checkbox', required: metadata.required, name: name, initial: metadata.empty? = render 'bootstrap/btn', content: t('.edit'), action: 'modal#show' @@ -48,7 +48,7 @@ -# @todo issue-7537 - metadata.value.each do |uuid| - if (indexed_post = site.indexed_posts.find_by(post_id: uuid)) - = render 'posts/new_related_post', post: indexed_post, attribute: metadata.type + = render 'posts/new_related_post', post: indexed_post, attribute: metadata.type, inverse: metadata.inverse = render 'bootstrap/modal', id: id, modal_content_attributes: { class: 'h-100' }, hide_actions: ['array#cancel'], keydown_actions: %w[keydown->array#cancelWithEscape] do - content_for :"#{id}_header" do @@ -91,6 +91,7 @@ para que sea externo al formulario actual. - content_for :post_form do %form{ id: post_form_id, 'hx-get': site_posts_form_path(site), 'hx-target': "##{post_form_loaded_id}" } + %input{ type: 'hidden', name: 'modal_id', value: modal_id } %input{ type: 'hidden', name: 'show', value: post_modal_id } %input{ type: 'hidden', name: 'hide', value: modal_id } %input{ type: 'hidden', name: 'target', value: value_list_id } diff --git a/app/views/posts/attributes/_new_has_many.haml b/app/views/posts/attributes/_new_has_many.haml index ff657359..e2d9d758 100644 --- a/app/views/posts/attributes/_new_has_many.haml +++ b/app/views/posts/attributes/_new_has_many.haml @@ -47,7 +47,7 @@ -# @todo issue-7537 - metadata.value.each do |uuid| - if (indexed_post = site.indexed_posts.find_by(post_id: uuid)) - = render 'posts/new_related_post', post: indexed_post, attribute: metadata.type + = render 'posts/new_related_post', post: indexed_post, attribute: metadata.type, inverse: metadata.inverse = render 'bootstrap/modal', id: id, modal_content_attributes: { class: 'h-100' }, hide_actions: ['array#cancel'], keydown_actions: %w[keydown->array#cancelWithEscape] do - content_for :"#{id}_header" do diff --git a/app/views/posts/attributes/_new_predefined_array.haml b/app/views/posts/attributes/_new_predefined_array.haml index 68856daa..0afa253d 100644 --- a/app/views/posts/attributes/_new_predefined_array.haml +++ b/app/views/posts/attributes/_new_predefined_array.haml @@ -18,7 +18,7 @@ = hidden_field_tag name, '' .d-flex.align-items-center.justify-content-between %div - = label_tag id, post_label_t(attribute, post: post) + = label_tag id, post_label_t(attribute, post: post), class: 'h3' = render 'posts/required_checkbox', required: metadata.required, name: name, initial: metadata.empty? = render 'bootstrap/btn', content: t('.edit'), action: 'modal#show' diff --git a/app/views/posts/attributes/_new_predefined_value.haml b/app/views/posts/attributes/_new_predefined_value.haml index 2eb11335..20bd5d0b 100644 --- a/app/views/posts/attributes/_new_predefined_value.haml +++ b/app/views/posts/attributes/_new_predefined_value.haml @@ -29,7 +29,7 @@ = hidden_field_tag name, '' .d-flex.align-items-center.justify-content-between %div - = label_tag id, post_label_t(attribute, post: post) + = label_tag id, post_label_t(attribute, post: post), class: 'h3' = render 'posts/required_checkbox', required: metadata.required, name: name, initial: metadata.empty?, type: 'radio' = render 'bootstrap/btn', content: t('.edit'), action: 'modal#show' diff --git a/app/views/posts/modal.haml b/app/views/posts/modal.haml index 14836118..e589dfa8 100644 --- a/app/views/posts/modal.haml +++ b/app/views/posts/modal.haml @@ -16,6 +16,11 @@ result_id = pluck_param(:result_id) form_id = random_id except = %i[date] + + if (inverse = pluck_param(:inverse, optional: true)) + except << inverse.to_sym + end + options = { id: form_id, multipart: true, @@ -45,12 +50,17 @@ = hidden_field_tag 'result_id', result_id = hidden_field_tag 'modal_id', modal_id = hidden_field_tag "#{base}[layout]", post.layout.name + = hidden_field_tag 'hide', pluck_param((post.errors.empty? ? :show : :hide), optional: true) || pluck_param(:modal_id, optional: true) + = hidden_field_tag 'show', pluck_param((post.errors.empty? ? :hide : :show), optional: true) + - if inverse + = hidden_field_tag 'inverse', inverse = render 'errors', post: post = render 'posts/attributes', site: site, post: post, dir: dir, base: base, locale: locale, except: except -# @todo Volver obligatorios? - except.each do |attr| - %input{ type: 'hidden', name: "#{base}[#{attr}]", value: pluck_param(attr, optional: true) } + - if (value = pluck_param(attr, optional: true)) + = hidden_field_tag "#{base}[#{attr}]", value - content_for :"#{modal_id}_footer" do -# = render 'posts/validation', site: site, invalid: { id: invalid_id }, submitting: { id: submitting_id } diff --git a/app/views/posts/new_related_post.haml b/app/views/posts/new_related_post.haml index 11fdf3af..1b173fa9 100644 --- a/app/views/posts/new_related_post.haml +++ b/app/views/posts/new_related_post.haml @@ -1 +1 @@ -= render 'posts/new_related_post', post: @indexed_post, modal_id: pluck_param(:modal_id, optional: true) += render 'posts/new_related_post', post: @indexed_post, modal_id: pluck_param(:modal_id, optional: true), inverse: pluck_param(:inverse, optional: true) diff --git a/config/locales/en.yml b/config/locales/en.yml index ee8ec9f9..7ec6cf31 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -769,6 +769,8 @@ en: edit: "Edit" new_predefined_array: edit: "Edit" + new_predefined_value: + empty: "(Empty)" new_array: edit: "Edit" new_has_one: diff --git a/config/locales/es.yml b/config/locales/es.yml index dad7c2f2..12aef7ed 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -776,8 +776,10 @@ es: new_has_and_belongs_to_many: edit: "Editar" new_predefined_array: + empty: "(Vacío)" edit: "Editar" new_predefined_value: + empty: "(Vacío)" edit: "Editar" new_array: edit: "Editar"