mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-26 04:26:21 +00:00
56 lines
2 KiB
Text
56 lines
2 KiB
Text
|
-#
|
||
|
|
||
|
Genera un modal completo con el formulario del post y sus botones de
|
||
|
guardado.
|
||
|
|
||
|
Se comporta como "HTMX".
|
||
|
|
||
|
|
||
|
:ruby
|
||
|
post = @post
|
||
|
site = post.site
|
||
|
locale = @locale
|
||
|
base = random_id
|
||
|
dir = t("locales.#{locale}.dir")
|
||
|
modal_id = pluck_param(:modal_id)
|
||
|
result_id = pluck_param(:result_id)
|
||
|
form_id = random_id
|
||
|
except = %i[date]
|
||
|
options = {
|
||
|
id: form_id,
|
||
|
multipart: true,
|
||
|
class: 'form post'
|
||
|
}
|
||
|
|
||
|
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
|
||
|
|
||
|
%div{ id: modal_id, data: { controller: 'modal' }}
|
||
|
= render 'bootstrap/modal', id: modal_id, modal_content_attributes: { class: 'h-100' } do
|
||
|
- content_for :"#{modal_id}_body" do
|
||
|
= form_tag url, **options do
|
||
|
= hidden_field_tag 'base', base
|
||
|
= hidden_field_tag 'result_id', result_id
|
||
|
= hidden_field_tag 'modal_id', modal_id
|
||
|
= hidden_field_tag "#{base}[layout]", post.layout.name
|
||
|
|
||
|
= 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) }
|
||
|
|
||
|
- content_for :"#{modal_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')
|
||
|
= render 'bootstrap/btn', form: form_id, content: t('.save'), type: 'submit', class: 'm-0 mt-1 mr-1'
|
||
|
= render 'bootstrap/btn', content: t('.close'), action: 'modal#hide', class: 'm-0 mt-1 mr-1'
|
||
|
= yield(:post_form)
|