2024-05-17 20:12:05 +00:00
|
|
|
-#
|
|
|
|
Genera un listado de checkboxes entre los que se puede elegir para
|
|
|
|
guardar, pero no se pueden agregar nuevos.
|
|
|
|
|
|
|
|
:ruby
|
2024-05-23 20:47:02 +00:00
|
|
|
id = id_for(base, attribute)
|
2024-05-17 20:12:05 +00:00
|
|
|
name = "#{base}[#{attribute}][]"
|
2024-06-03 20:45:23 +00:00
|
|
|
form_id = random_id
|
2024-05-17 20:12:05 +00:00
|
|
|
|
|
|
|
%div{ data: { controller: 'modal array', 'array-original-value': metadata.value.to_json, 'array-new-array-value': site_posts_new_array_value_path(site) } }
|
2024-05-27 19:40:09 +00:00
|
|
|
%template{ data: { target: 'array.placeholder' } }
|
|
|
|
.col.mb-3{ 'aria-hidden': 'true' }
|
|
|
|
%span.placeholder.w-100
|
|
|
|
|
2024-05-17 20:12:05 +00:00
|
|
|
.form-group
|
|
|
|
= hidden_field_tag name, ''
|
2024-05-27 19:38:56 +00:00
|
|
|
.d-flex.align-items-center.justify-content-between
|
|
|
|
= label_tag id, post_label_t(attribute, post: post)
|
|
|
|
= render 'bootstrap/btn', content: t('.edit'), action: 'modal#show'
|
2024-05-17 20:12:05 +00:00
|
|
|
|
2024-05-27 19:38:56 +00:00
|
|
|
-# Mostramos la lista de valores actuales.
|
2024-05-17 20:12:05 +00:00
|
|
|
|
2024-05-27 19:38:56 +00:00
|
|
|
Al aceptar el modal, se vacía el listado y se completa en base a
|
|
|
|
renderizaciones con HTMX. Para poder hacer eso, tenemos que poder
|
|
|
|
acceder a todos los items dentro del modal (como array.item) y
|
|
|
|
enviar el valor al endpoint que devuelve uno por uno. Esto lo
|
|
|
|
tenemos disponible en Stimulus, pero queremos usar HTMX o técnica
|
|
|
|
similar para poder renderizar del lado del servidor.
|
2024-05-17 20:12:05 +00:00
|
|
|
|
2024-05-27 19:38:56 +00:00
|
|
|
Para poder cancelar, mantenemos el estado original y desactivamos
|
|
|
|
o activamos los ítemes según estén incluidos en esa lista o no.
|
2024-06-17 14:10:27 +00:00
|
|
|
%ul.placeholder-glow{ data: { target: 'array.current' } }
|
2024-05-27 19:38:56 +00:00
|
|
|
- metadata.values.slice(*metadata.value).each_key do |value|
|
|
|
|
= render 'posts/new_array_value', value: value
|
2024-05-17 20:12:05 +00:00
|
|
|
|
2024-06-05 21:00:55 +00:00
|
|
|
= render 'bootstrap/modal', id: id, modal_content_attributes: { class: 'h-100' }, hide_actions: ['array#cancel'], keydown_actions: %w[keydown->array#cancelWithEscape] do
|
2024-05-17 20:12:05 +00:00
|
|
|
- content_for :"#{id}_header" do
|
|
|
|
.form-group.flex-grow-1.mb-0
|
|
|
|
= label_tag id, post_label_t(attribute, post: post)
|
|
|
|
%input.form-control{ data: { target: 'array.search', action: 'input->array#search' }, type: 'search', placeholder: t('.filter') }
|
|
|
|
|
|
|
|
- content_for :"#{id}_body" do
|
|
|
|
.form-group.mb-0{ id: "#{id}_body" }
|
|
|
|
-# Eliminamos las tildes para poder buscar independientemente de cómo se escriba
|
|
|
|
- metadata.values.each_pair do |value, key|
|
|
|
|
.mb-2{ data: { target: 'array.item', 'searchable-value': value.remove_diacritics.downcase, value: value } }
|
2024-06-03 20:45:23 +00:00
|
|
|
= render 'bootstrap/custom_checkbox', name: name, id: random_id, value: key, checked: metadata.value.include?(key), content: value
|
2024-05-17 20:12:05 +00:00
|
|
|
|
|
|
|
- content_for :"#{id}_footer" do
|
|
|
|
-# Alinear los botones a la derecha
|
|
|
|
.flex-grow-1
|
|
|
|
= render 'bootstrap/btn', content: t('.accept'), action: 'array#accept modal#hide', class: 'm-0 mr-1'
|
|
|
|
= render 'bootstrap/btn', content: t('.cancel'), action: 'array#cancel modal#hide', class: 'm-0'
|