5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2025-02-20 01:01:48 +00:00
panel/app/views/posts/attributes/_new_has_one.haml

62 lines
3 KiB
Text
Raw Normal View History

2024-06-03 20:52:53 +00:00
-#
Genera un listado de radios entre los que se puede elegir solo uno para
guardar. Podemos elegir entre los artículos ya cargados o agregar uno
nuevo.
Al agregar uno nuevo, se abre un segundo modal que carga el formulario
correspondiente vía HTMX. El formulario tiene que cargarse por fuera
del formulario principal porque no se pueden anidar.
:ruby
id = random_id
name = "#{base}[#{attribute}]"
target_id = random_id
form_id = random_id
modal_id = random_id
post_id = random_id
post_form_id = random_id
post_modal_id = random_id
post_form_loaded_id = random_id
value_list_id = random_id
layout = metadata.filter[:layout]
invalid_id = random_id
submitting_id = random_id
saved_id = random_id
2024-06-03 20:52:53 +00:00
%div{ data: { controller: 'modal' }}
.form-group
= hidden_field_tag name, ''
.d-flex.align-items-center.justify-content-between
= label_tag id, post_label_t(attribute, post: post), class: 'h3'
2024-06-26 17:02:44 +00:00
= render 'bootstrap/btn', content: t('.edit'), data: { action: 'modal#showAnother', 'modal-show-value': modal_id }, id: random_id
2024-06-03 20:52:53 +00:00
-# Aquí se reemplaza por la tarjeta y el UUID luego de guardar
2024-06-25 19:59:15 +00:00
.row.no-gutters.placeholder-glow{ id: target_id }
2024-06-03 20:52:53 +00:00
-# @todo issue-7537
- if !metadata.empty? && (indexed_post = site.indexed_posts.find_by(post_id: metadata.value))
= render 'posts/new_has_one', post: indexed_post, name: name, value: metadata.value, modal_id: modal_id
2024-06-03 20:52:53 +00:00
-#
El modal se genera por fuera del formulario, para poder enviar los
datos y recibir su UUID en respuesta.
- content_for :post_form do
%div{ id: modal_id, data: { controller: 'modal' }}
2024-06-04 20:11:32 +00:00
-# Si hay un solo layout o el post asociado ya existía
- if layout.is_a?(String) || metadata.has_one.present?
2024-06-03 20:52:53 +00:00
= render 'bootstrap/modal', id: id, modal_content_attributes: { class: 'h-100' } do
- content_for :"#{id}_body" do
-# @todo ocultar el modal después de guardar
2024-07-02 16:02:32 +00:00
.placeholder-glow{ 'hx-get': site_posts_form_path(site, layout: layout, base: id, name: name, form: form_id, swap: 'innerHTML', target: target_id, attribute: 'new_has_one', hide: modal_id, uuid: metadata.value, invalid: invalid_id, submitting: submitting_id, saved: saved_id, inverse: metadata.inverse, metadata.inverse => post.uuid.value), 'hx-trigger': 'load' }
2024-06-03 20:52:53 +00:00
%span.placeholder.w-100.h-100
- content_for :"#{id}_footer" do
= render 'posts/validation', site: site, invalid: { id: invalid_id }, submitting: { id: submitting_id }
= render 'bootstrap/alert', class: 'm-0 d-none fade', id: saved_id, data: { controller: 'notification', action: 'notification:show@window->notification#show', 'notification-hide-class': 'hide', 'notification-show-class': 'show' } do
= t('.saved')
2024-06-03 20:52:53 +00:00
= render 'bootstrap/btn', form: form_id, content: t('.save'), type: 'submit', class: 'm-0 mt-1 mr-1'
2024-06-04 20:11:32 +00:00
= render 'bootstrap/btn', content: t('.close'), action: 'modal#hide', class: 'm-0 mt-1 mr-1'
2024-06-03 20:52:53 +00:00
- else
2024-06-04 20:11:32 +00:00
-# @todo Implementar selección de layout para cargar el formulario correcto
2024-06-03 20:52:53 +00:00
Nada