2024-05-20 17:12:53 +00:00
|
|
|
-#
|
|
|
|
El formulario del artículo, con HTMX activado.
|
|
|
|
|
|
|
|
@param :site [Site]
|
|
|
|
@param :post [Post]
|
|
|
|
@param :locale [Symbol, String]
|
|
|
|
@param :dir [Symbol, String]
|
2024-06-03 20:50:48 +00:00
|
|
|
|
|
|
|
@param [ActionController::StrongParameters] params
|
|
|
|
@option params [String] :inverse La relación inversa (opcional)
|
|
|
|
@option params [String] :form El ID del formulario actual, si tiene botones externos, tiene que estar compartido
|
|
|
|
@option params [String] :swap Método de intercambio del resultado (HTMX)
|
|
|
|
@option params [String] :target Elemento donde se carga el resultado (HTMX)
|
|
|
|
@option params [String] :hide ID del modal a esconder vía evento
|
|
|
|
@option params [String] :show ID del modal a mostrar vía evento
|
|
|
|
@option params [String] :base La base del formulario, que luego se envía como parámetro a PostService
|
|
|
|
@option params [String] :attribute El tipo de atributo, para saber qué respuesta generar
|
2024-05-20 17:12:53 +00:00
|
|
|
:ruby
|
2024-05-23 21:19:59 +00:00
|
|
|
except = %i[date]
|
|
|
|
|
2024-07-10 20:04:59 +00:00
|
|
|
if (inverse = pluck_param(:inverse, optional: true))
|
2024-05-23 21:19:59 +00:00
|
|
|
except << inverse.to_sym
|
|
|
|
end
|
|
|
|
|
2024-05-20 17:12:53 +00:00
|
|
|
options = {
|
2024-07-10 20:04:59 +00:00
|
|
|
id: pluck_param(:form),
|
2024-05-20 17:12:53 +00:00
|
|
|
multipart: true,
|
|
|
|
class: 'form post ',
|
2024-07-10 20:04:59 +00:00
|
|
|
'hx-swap': pluck_param(:swap),
|
|
|
|
'hx-target': "##{pluck_param(:target)}",
|
2024-06-19 21:20:05 +00:00
|
|
|
'hx-validate': true,
|
|
|
|
data: {
|
|
|
|
controller: 'form-validation',
|
2024-06-19 21:21:44 +00:00
|
|
|
action: 'form-validation#submit',
|
2024-07-10 20:04:59 +00:00
|
|
|
'form-validation-submitting-id-value': pluck_param(:submitting, optional: true),
|
|
|
|
'form-validation-invalid-id-value': pluck_param(:invalid, optional: true),
|
2024-06-19 21:20:05 +00:00
|
|
|
}
|
2024-05-20 17:12:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if post.new?
|
|
|
|
url = options[:'hx-post'] = site_posts_path(site, locale: locale)
|
|
|
|
options[:class] += 'new'
|
|
|
|
else
|
|
|
|
url = options[:'hx-patch'] = site_post_path(site, post.id, locale: locale)
|
|
|
|
options[:method] = :patch
|
|
|
|
options[:class] += 'edit'
|
|
|
|
end
|
|
|
|
|
|
|
|
= form_tag url, **options do
|
2024-07-10 20:08:47 +00:00
|
|
|
= render 'errors', post: post
|
2024-05-27 18:13:11 +00:00
|
|
|
|
2024-05-20 17:12:53 +00:00
|
|
|
-# Parámetros para HTMX
|
2024-07-10 20:04:59 +00:00
|
|
|
%input{ type: 'hidden', name: 'hide', value: pluck_param((post.errors.empty? ? :show : :hide), optional: true) }
|
|
|
|
%input{ type: 'hidden', name: 'show', value: pluck_param((post.errors.empty? ? :hide : :show), optional: true) }
|
|
|
|
%input{ type: 'hidden', name: 'name', value: pluck_param(:name) }
|
|
|
|
%input{ type: 'hidden', name: 'base', value: pluck_param(:base) }
|
2024-05-27 18:13:11 +00:00
|
|
|
%input{ type: 'hidden', name: 'form', value: options[:id] }
|
|
|
|
%input{ type: 'hidden', name: 'dir', value: dir }
|
|
|
|
%input{ type: 'hidden', name: 'locale', value: locale }
|
2024-07-10 20:04:59 +00:00
|
|
|
%input{ type: 'hidden', name: 'attribute', value: pluck_param(:attribute) }
|
|
|
|
%input{ type: 'hidden', name: 'target', value: pluck_param(:target) }
|
|
|
|
%input{ type: 'hidden', name: 'swap', value: pluck_param(:swap) }
|
2024-05-27 18:13:11 +00:00
|
|
|
- if params[:inverse].present?
|
2024-07-10 20:04:59 +00:00
|
|
|
%input{ type: 'hidden', name: 'inverse', value: pluck_param(:inverse) }
|
2024-06-19 21:21:44 +00:00
|
|
|
- if params[:saved].present?
|
2024-07-10 20:04:59 +00:00
|
|
|
%input{ type: 'hidden', name: 'saved', value: pluck_param(:saved) }
|
2024-05-20 17:12:53 +00:00
|
|
|
|
|
|
|
= hidden_field_tag "#{base}[layout]", post.layout.name
|
|
|
|
|
2024-07-02 16:02:32 +00:00
|
|
|
-# Dibuja cada atributo, excepto algunos
|
2024-05-23 21:19:59 +00:00
|
|
|
= render 'posts/attributes', site: site, post: post, dir: dir, base: base, locale: locale, except: except
|
2024-05-24 16:10:55 +00:00
|
|
|
|
2024-07-02 16:02:32 +00:00
|
|
|
-#
|
|
|
|
Enviamos valores vacíos o arrastrados desde el formulario anterior
|
|
|
|
para los atributos ignorados
|
2024-05-27 18:28:17 +00:00
|
|
|
- except.each do |attr|
|
2024-07-10 20:04:59 +00:00
|
|
|
%input{ type: 'hidden', name: "#{base}[#{attr}]", value: pluck_param(attr, optional: true) }
|
2024-05-27 18:28:17 +00:00
|
|
|
|
2024-05-24 16:10:55 +00:00
|
|
|
= yield(:post_form)
|