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]
|
|
|
|
:ruby
|
2024-05-23 21:19:59 +00:00
|
|
|
except = %i[date]
|
|
|
|
|
|
|
|
if (inverse = params.permit(:inverse).try(:[], :inverse).presence)
|
|
|
|
except << inverse.to_sym
|
|
|
|
end
|
|
|
|
|
2024-05-20 17:12:53 +00:00
|
|
|
options = {
|
2024-05-27 18:12:03 +00:00
|
|
|
id: params.require(:form),
|
2024-05-20 17:12:53 +00:00
|
|
|
multipart: true,
|
|
|
|
class: 'form post ',
|
|
|
|
'hx-swap': params.require(:swap),
|
|
|
|
'hx-target': "##{params.require(:target)}"
|
|
|
|
}
|
|
|
|
|
|
|
|
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-05-27 18:13:11 +00:00
|
|
|
- unless post.errors.empty?
|
|
|
|
- title = t('.errors.title')
|
|
|
|
- help = t('.errors.help')
|
|
|
|
= render 'bootstrap/alert' do
|
|
|
|
%h4= title
|
|
|
|
%p= help
|
|
|
|
|
|
|
|
%ul
|
|
|
|
- post.errors.each do |attribute, errors|
|
|
|
|
- if errors.size > 1
|
|
|
|
%li
|
|
|
|
%strong= post_label_t attribute, post: post
|
|
|
|
%ul
|
|
|
|
- errors.each do |error|
|
|
|
|
%li= error
|
|
|
|
- else
|
|
|
|
%li
|
|
|
|
%strong= post_label_t attribute, post: post
|
|
|
|
= errors.first
|
|
|
|
|
2024-05-20 17:12:53 +00:00
|
|
|
-# Parámetros para HTMX
|
2024-05-27 18:13:11 +00:00
|
|
|
%input{ type: 'hidden', name: 'hide', value: params.require((post.errors.empty? ? :show : :hide)) }
|
|
|
|
%input{ type: 'hidden', name: 'show', value: params.require((post.errors.empty? ? :hide : :show)) }
|
2024-05-20 17:12:53 +00:00
|
|
|
%input{ type: 'hidden', name: 'name', value: params.require(:name) }
|
|
|
|
%input{ type: 'hidden', name: 'base', value: params.require(: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-05-27 18:15:55 +00:00
|
|
|
%input{ type: 'hidden', name: 'attribute', value: params.require(:attribute) }
|
2024-05-27 18:13:11 +00:00
|
|
|
%input{ type: 'hidden', name: 'target', value: params.require(:target) }
|
|
|
|
%input{ type: 'hidden', name: 'swap', value: params.require(:swap) }
|
|
|
|
- if params[:inverse].present?
|
|
|
|
%input{ type: 'hidden', name: 'inverse', value: params.require(:inverse) }
|
2024-05-20 17:12:53 +00:00
|
|
|
|
|
|
|
= hidden_field_tag "#{base}[layout]", post.layout.name
|
|
|
|
|
|
|
|
-# Dibuja cada atributo
|
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-05-27 18:28:17 +00:00
|
|
|
-# Enviamos valores vacíos para los atributos ocultos
|
|
|
|
- except.each do |attr|
|
|
|
|
%input{ type: 'hidden', name: "#{base}[#{attr}]", value: "" }
|
|
|
|
|
2024-05-24 16:10:55 +00:00
|
|
|
= yield(:post_form)
|