From 9ca98191a500e1cc4262d2b1b1084467fc64bd35 Mon Sep 17 00:00:00 2001 From: Renato Date: Tue, 15 Oct 2024 06:40:29 -0300 Subject: [PATCH 1/4] fix: redirect user to the intented page --- .../decidim/append_redirect_url_to_modals.js | 33 ++++++++++++------- 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/decidim-core/app/packs/src/decidim/append_redirect_url_to_modals.js b/decidim-core/app/packs/src/decidim/append_redirect_url_to_modals.js index 558c011efdc8f..33f10c6f044be 100644 --- a/decidim-core/app/packs/src/decidim/append_redirect_url_to_modals.js +++ b/decidim-core/app/packs/src/decidim/append_redirect_url_to_modals.js @@ -53,20 +53,29 @@ $(() => { } $(document).on("click.zf.trigger", (event) => { - const target = `#${$(event.target).data("open")}`; - const redirectUrl = $(event.target).data("redirectUrl"); + // Try to get the directly or find the closest parent + let $target = $(event.target); + if (!$target.is('a')) { + $target = $target.closest('a'); // Find the closest parent if the click is not directly on an + } + + // Check if an was found + if ($target.length) { + const dialogTarget = `#${$target.data("dialog-open")}`; + const redirectUrl = $target.data("redirectUrl"); - if (target && redirectUrl) { - $(""). - attr("id", "redirect_url"). - attr("name", "redirect_url"). - attr("value", redirectUrl). - appendTo(`${target} form`); + if (dialogTarget && redirectUrl) { + $("") + .attr("id", "redirect_url") + .attr("name", "redirect_url") + .attr("value", redirectUrl) + .appendTo(`${dialogTarget} form`); - $(`${target} a`).attr("href", (index, href) => { - const querystring = jQuery.param({"redirect_url": redirectUrl}); - return href + (href.match(/\?/) ? "&" : "?") + querystring; - }); + $(`${dialogTarget} a`).attr("href", (index, href) => { + const querystring = jQuery.param({"redirect_url": redirectUrl}); + return href + (href.match(/\?/) ? "&" : "?") + querystring; + }); + } } }); From 25170058cdea0aabc1dcc450f4f72b60ee916d75 Mon Sep 17 00:00:00 2001 From: Renato Date: Wed, 16 Oct 2024 11:24:16 -0300 Subject: [PATCH 2/4] fix: removing duplicate lines in the code --- .../decidim/append_redirect_url_to_modals.js | 48 +++++++++---------- 1 file changed, 23 insertions(+), 25 deletions(-) diff --git a/decidim-core/app/packs/src/decidim/append_redirect_url_to_modals.js b/decidim-core/app/packs/src/decidim/append_redirect_url_to_modals.js index 381a5124b48e3..4f87a68d5ade7 100644 --- a/decidim-core/app/packs/src/decidim/append_redirect_url_to_modals.js +++ b/decidim-core/app/packs/src/decidim/append_redirect_url_to_modals.js @@ -53,32 +53,30 @@ $(() => { } $(document).on("click.zf.trigger", (event) => { - $(document).on("click.zf.trigger", (event) => { - // Try to get the directly or find the closest parent - let $target = $(event.target); - if (!$target.is('a')) { - $target = $target.closest('a'); // Find the closest parent if the click is not directly on an - } - - // Check if an was found - if ($target.length) { - const dialogTarget = `#${$target.data("dialog-open")}`; - const redirectUrl = $target.data("redirectUrl"); - - if (dialogTarget && redirectUrl) { - $("") - .attr("id", "redirect_url") - .attr("name", "redirect_url") - .attr("value", redirectUrl) - .appendTo(`${dialogTarget} form`); - - $(`${dialogTarget} a`).attr("href", (index, href) => { - const querystring = jQuery.param({"redirect_url": redirectUrl}); - return href + (href.match(/\?/) ? "&" : "?") + querystring; - }); - } + // Try to get the directly or find the closest parent + let $target = $(event.target); + if (!$target.is('a')) { + $target = $target.closest('a'); // Find the closest parent if the click is not directly on an + } + + // Check if an was found + if ($target.length) { + const dialogTarget = `#${$target.data("dialog-open")}`; + const redirectUrl = $target.data("redirectUrl"); + + if (dialogTarget && redirectUrl) { + $("") + .attr("id", "redirect_url") + .attr("name", "redirect_url") + .attr("value", redirectUrl) + .appendTo(`${dialogTarget} form`); + + $(`${dialogTarget} a`).attr("href", (index, href) => { + const querystring = jQuery.param({"redirect_url": redirectUrl}); + return href + (href.match(/\?/) ? "&" : "?") + querystring; + }); } - }); + } }); $(document).on("closed.zf.reveal", (event) => { From 7b631657e5ed06b54dbcd457cdad50f3a60b0196 Mon Sep 17 00:00:00 2001 From: Renato Date: Wed, 16 Oct 2024 11:44:06 -0300 Subject: [PATCH 3/4] fix: npm lint errors --- .../decidim/append_redirect_url_to_modals.js | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/decidim-core/app/packs/src/decidim/append_redirect_url_to_modals.js b/decidim-core/app/packs/src/decidim/append_redirect_url_to_modals.js index 4f87a68d5ade7..37d4aac0acf3d 100644 --- a/decidim-core/app/packs/src/decidim/append_redirect_url_to_modals.js +++ b/decidim-core/app/packs/src/decidim/append_redirect_url_to_modals.js @@ -55,8 +55,9 @@ $(() => { $(document).on("click.zf.trigger", (event) => { // Try to get the directly or find the closest parent let $target = $(event.target); - if (!$target.is('a')) { - $target = $target.closest('a'); // Find the closest parent if the click is not directly on an + if (!$target.is("a")) { + // Find the closest parent if the click is not directly on an + $target = $target.closest("a"); } // Check if an was found @@ -65,15 +66,15 @@ $(() => { const redirectUrl = $target.data("redirectUrl"); if (dialogTarget && redirectUrl) { - $("") - .attr("id", "redirect_url") - .attr("name", "redirect_url") - .attr("value", redirectUrl) - .appendTo(`${dialogTarget} form`); + $(""). + attr("id", "redirect_url"). + attr("name", "redirect_url"). + attr("value", redirectUrl). + appendTo(`${dialogTarget} form`); $(`${dialogTarget} a`).attr("href", (index, href) => { - const querystring = jQuery.param({"redirect_url": redirectUrl}); - return href + (href.match(/\?/) ? "&" : "?") + querystring; + const querystring = jQuery.param({"redirect_url": redirectUrl}); + return href + (href.match(/\?/) ? "&" : "?") + querystring; }); } } From bab5ee32aeceeea7b717dc275ae13ee30b2ad578 Mon Sep 17 00:00:00 2001 From: Renato Date: Sat, 19 Oct 2024 06:52:44 -0300 Subject: [PATCH 4/4] fix: minor code improvements for clarity --- .../decidim/append_redirect_url_to_modals.js | 41 ++++++++++--------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/decidim-core/app/packs/src/decidim/append_redirect_url_to_modals.js b/decidim-core/app/packs/src/decidim/append_redirect_url_to_modals.js index 37d4aac0acf3d..87e2bfcf77ae6 100644 --- a/decidim-core/app/packs/src/decidim/append_redirect_url_to_modals.js +++ b/decidim-core/app/packs/src/decidim/append_redirect_url_to_modals.js @@ -54,30 +54,31 @@ $(() => { $(document).on("click.zf.trigger", (event) => { // Try to get the directly or find the closest parent - let $target = $(event.target); - if (!$target.is("a")) { - // Find the closest parent if the click is not directly on an - $target = $target.closest("a"); - } + const $target = $(event.target).closest("a"); // Check if an was found - if ($target.length) { - const dialogTarget = `#${$target.data("dialog-open")}`; - const redirectUrl = $target.data("redirectUrl"); - - if (dialogTarget && redirectUrl) { - $(""). - attr("id", "redirect_url"). - attr("name", "redirect_url"). - attr("value", redirectUrl). - appendTo(`${dialogTarget} form`); + if (!$target) { + return; + } + + + const dialogTarget = `#${$target.data("dialog-open")}`; + const redirectUrl = $target.data("redirectUrl"); - $(`${dialogTarget} a`).attr("href", (index, href) => { - const querystring = jQuery.param({"redirect_url": redirectUrl}); - return href + (href.match(/\?/) ? "&" : "?") + querystring; - }); - } + if (!dialogTarget || !redirectUrl) { + return; } + + $(""). + attr("id", "redirect_url"). + attr("name", "redirect_url"). + attr("value", redirectUrl). + appendTo(`${dialogTarget} form`); + + $(`${dialogTarget} a`).attr("href", (index, href) => { + const querystring = jQuery.param({"redirect_url": redirectUrl}); + return href + (href.match(/\?/) ? "&" : "?") + querystring; + }); }); $(document).on("closed.zf.reveal", (event) => {