From 34aa8822f29254e21bf316f092fe578a665367b0 Mon Sep 17 00:00:00 2001 From: f Date: Wed, 19 Jun 2024 18:21:44 -0300 Subject: [PATCH] feat: avisar que se guardaron los cambios --- app/controllers/posts_controller.rb | 8 ++++++-- app/views/posts/_htmx_form.haml | 6 +++++- app/views/posts/attributes/_new_has_one.haml | 8 +++++++- config/locales/en.yml | 2 ++ config/locales/es.yml | 2 ++ 5 files changed, 22 insertions(+), 4 deletions(-) diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index 0f3c24d5..70ba2e54 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -128,7 +128,9 @@ class PostsController < ApplicationController # condiciones. if htmx? if post.persisted? - swap_modals + triggers = { 'notification:show' => { 'id' => params.permit(:saved).values.first } } + + swap_modals(triggers) @value = post.title.value @uuid = post.uuid.value @@ -169,7 +171,9 @@ class PostsController < ApplicationController if htmx? if post.persisted? - swap_modals + triggers = { 'notification:show' => params.permit(:saved).values.first } + + swap_modals(triggers) @value = post.title.value @uuid = post.uuid.value diff --git a/app/views/posts/_htmx_form.haml b/app/views/posts/_htmx_form.haml index 7a23445b..1a8c0597 100644 --- a/app/views/posts/_htmx_form.haml +++ b/app/views/posts/_htmx_form.haml @@ -31,7 +31,9 @@ 'hx-validate': true, data: { controller: 'form-validation', - action: 'form-validation#submit' + action: 'form-validation#submit', + 'form-validation-submitting-id-value': params.permit(:submitting).values.first, + 'form-validation-invalid-id-value': params.permit(:invalid).values.first, } } @@ -78,6 +80,8 @@ %input{ type: 'hidden', name: 'swap', value: params.require(:swap) } - if params[:inverse].present? %input{ type: 'hidden', name: 'inverse', value: params.require(:inverse) } + - if params[:saved].present? + %input{ type: 'hidden', name: 'saved', value: params.require(:saved) } = hidden_field_tag "#{base}[layout]", post.layout.name diff --git a/app/views/posts/attributes/_new_has_one.haml b/app/views/posts/attributes/_new_has_one.haml index 58e098b6..87ef0440 100644 --- a/app/views/posts/attributes/_new_has_one.haml +++ b/app/views/posts/attributes/_new_has_one.haml @@ -19,6 +19,9 @@ 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 %div{ data: { controller: 'modal' }} .form-group @@ -43,10 +46,13 @@ = 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 - .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), 'hx-trigger': 'load' } + .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), 'hx-trigger': 'load' } %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') = 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' diff --git a/config/locales/en.yml b/config/locales/en.yml index c0ad36d2..52f002e6 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -965,3 +965,5 @@ en: save: "Save" card: edit: "Edit" + alert: + saved: "Changes were saved!" diff --git a/config/locales/es.yml b/config/locales/es.yml index 1fd397e4..8fe09758 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -975,3 +975,5 @@ es: save: "Guardar" card: edit: "Editar" + alert: + saved: "¡Cambios guardados!"