From 62a46e44c2e5c4e65dc43030aef58b97ba1e3d45 Mon Sep 17 00:00:00 2001 From: sillyguodong <33891828+sillyguodong@users.noreply.github.com> Date: Fri, 24 Mar 2023 16:37:56 +0800 Subject: [PATCH 1/2] Fix cancel button in the page of project edit not work (#23655) Before, in project edit page, the cancel button is not work. https://user-images.githubusercontent.com/33891828/227182731-6478e29f-0e52-48c4-beb0-6a7d1dda6a1d.mov 1. The wrong classname `cancel` was added to the `` tag. That classname caused the default click event of `` tag to be cancelled. Because we have the following settings in the global. So I remove the classname `cancel`. https://github.com/go-gitea/gitea/blob/9be90a58754061171bbd5025d85d2b891364efd3/web_src/js/features/common-global.js#L325-L327 2. Another change is that page will redirect to the previous page. https://user-images.githubusercontent.com/33891828/227187326-c653c6d6-9715-440f-a732-ba0a6f012c81.mov # Conflicts: # templates/projects/new.tmpl # templates/repo/projects/new.tmpl # web_src/js/features/common-global.js --- routers/web/org/projects.go | 2 ++ routers/web/repo/projects.go | 1 + templates/projects/new.tmpl | 2 +- templates/repo/projects/new.tmpl | 2 +- web_src/js/features/common-global.js | 10 +++++++++- 5 files changed, 14 insertions(+), 3 deletions(-) diff --git a/routers/web/org/projects.go b/routers/web/org/projects.go index c9d63fec5df0c..080388f01f8c1 100644 --- a/routers/web/org/projects.go +++ b/routers/web/org/projects.go @@ -232,9 +232,11 @@ func EditProject(ctx *context.Context) { return } + ctx.Data["projectID"] = p.ID ctx.Data["title"] = p.Title ctx.Data["content"] = p.Description ctx.Data["redirect"] = ctx.FormString("redirect") + ctx.Data["HomeLink"] = ctx.ContextUser.HomeLink() ctx.HTML(http.StatusOK, tplProjectsNew) } diff --git a/routers/web/repo/projects.go b/routers/web/repo/projects.go index e15f548a38dc3..91e17dee295f4 100644 --- a/routers/web/repo/projects.go +++ b/routers/web/repo/projects.go @@ -232,6 +232,7 @@ func EditProject(ctx *context.Context) { return } + ctx.Data["projectID"] = p.ID ctx.Data["title"] = p.Title ctx.Data["content"] = p.Description ctx.Data["card_type"] = p.CardType diff --git a/templates/projects/new.tmpl b/templates/projects/new.tmpl index 85ceddec6055d..1314884da6a03 100644 --- a/templates/projects/new.tmpl +++ b/templates/projects/new.tmpl @@ -48,7 +48,7 @@ {{if .PageIsEditProjects}} - + {{.locale.Tr "repo.milestones.cancel"}} diff --git a/templates/repo/projects/new.tmpl b/templates/repo/projects/new.tmpl index 25959be7a3bfe..b0b5ed024f58c 100644 --- a/templates/repo/projects/new.tmpl +++ b/templates/repo/projects/new.tmpl @@ -72,7 +72,7 @@ {{if .PageIsEditProjects}} - + {{.locale.Tr "repo.milestones.cancel"}} diff --git a/web_src/js/features/common-global.js b/web_src/js/features/common-global.js index 508749de0069d..3c150fdb6e5fa 100644 --- a/web_src/js/features/common-global.js +++ b/web_src/js/features/common-global.js @@ -314,7 +314,15 @@ export function initGlobalLinkActions() { } export function initGlobalButtons() { - $('.show-panel.button').on('click', function () { + // There are many "cancel button" elements in modal dialogs, Fomantic UI expects they are button-like elements but never submit a form. + // However, Gitea misuses the modal dialog and put the cancel buttons inside forms, so we must prevent the form submission. + // There are a few cancel buttons in non-modal forms, and there are some dynamically created forms (eg: the "Edit Issue Content") + $(document).on('click', 'form button.ui.cancel.button', (e) => { + e.preventDefault(); + }); + + $('.show-panel.button').on('click', function (e) { + e.preventDefault(); showElem($(this).data('panel')); }); From 74b4909c130e623068a9bc7e873c5612ca9bbca5 Mon Sep 17 00:00:00 2001 From: sillyguodong Date: Thu, 30 Mar 2023 16:05:40 +0800 Subject: [PATCH 2/2] revert --- web_src/js/features/common-global.js | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/web_src/js/features/common-global.js b/web_src/js/features/common-global.js index 3c150fdb6e5fa..508749de0069d 100644 --- a/web_src/js/features/common-global.js +++ b/web_src/js/features/common-global.js @@ -314,15 +314,7 @@ export function initGlobalLinkActions() { } export function initGlobalButtons() { - // There are many "cancel button" elements in modal dialogs, Fomantic UI expects they are button-like elements but never submit a form. - // However, Gitea misuses the modal dialog and put the cancel buttons inside forms, so we must prevent the form submission. - // There are a few cancel buttons in non-modal forms, and there are some dynamically created forms (eg: the "Edit Issue Content") - $(document).on('click', 'form button.ui.cancel.button', (e) => { - e.preventDefault(); - }); - - $('.show-panel.button').on('click', function (e) { - e.preventDefault(); + $('.show-panel.button').on('click', function () { showElem($(this).data('panel')); });