From 0f4b0cf8922ef1016fc8230fb0f9df883f03d1e0 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Tue, 26 Nov 2024 23:36:55 +0800 Subject: [PATCH] Refactor some frontend problems (#32646) 1. correct the modal usage on "admin email list" page (then `web_src/js/features/admin/emails.ts` is removed) 2. use `addDelegatedEventListener` instead of `jQuery().on` 3. more jQuery related changes and remove jQuery from `web_src/js/features/common-button.ts` 4. improve `confirmModal` to make it support header, and remove incorrect double-escaping 5. fix more typescript related types 6. fine tune devtest pages and add more tests --- routers/web/admin/emails.go | 2 +- routers/web/devtest/devtest.go | 4 +- templates/admin/emails/list.tmpl | 55 ++---- templates/devtest/devtest-footer.tmpl | 3 + templates/devtest/devtest-header.tmpl | 2 + .../devtest/{list.tmpl => devtest-list.tmpl} | 6 +- templates/devtest/fetch-action.tmpl | 5 +- templates/devtest/flex-list.tmpl | 5 +- templates/devtest/fomantic-dropdown.tmpl | 5 +- templates/devtest/fomantic-modal.tmpl | 28 ++- templates/devtest/gitea-ui.tmpl | 5 +- templates/devtest/global-button.tmpl | 16 ++ templates/devtest/label.tmpl | 5 +- templates/devtest/tmplerr.tmpl | 4 +- templates/devtest/toast.tmpl | 8 +- web_src/js/features/admin/emails.ts | 13 -- web_src/js/features/common-button.ts | 176 +++++++++--------- web_src/js/features/common-fetch-action.ts | 37 ++-- web_src/js/features/comp/ConfirmModal.ts | 4 +- web_src/js/features/repo-issue-list.ts | 2 +- web_src/js/index.ts | 4 - web_src/js/utils/dom.ts | 2 +- 22 files changed, 200 insertions(+), 191 deletions(-) create mode 100644 templates/devtest/devtest-footer.tmpl create mode 100644 templates/devtest/devtest-header.tmpl rename templates/devtest/{list.tmpl => devtest-list.tmpl} (65%) create mode 100644 templates/devtest/global-button.tmpl delete mode 100644 web_src/js/features/admin/emails.ts diff --git a/routers/web/admin/emails.go b/routers/web/admin/emails.go index 49338fbd7c..e9c97d8b8f 100644 --- a/routers/web/admin/emails.go +++ b/routers/web/admin/emails.go @@ -154,7 +154,7 @@ func ActivateEmail(ctx *context.Context) { // DeleteEmail serves a POST request for delete a user's email func DeleteEmail(ctx *context.Context) { - u, err := user_model.GetUserByID(ctx, ctx.FormInt64("Uid")) + u, err := user_model.GetUserByID(ctx, ctx.FormInt64("uid")) if err != nil || u == nil { ctx.ServerError("GetUserByID", err) return diff --git a/routers/web/devtest/devtest.go b/routers/web/devtest/devtest.go index 8c343197d9..0068c9fe88 100644 --- a/routers/web/devtest/devtest.go +++ b/routers/web/devtest/devtest.go @@ -24,12 +24,12 @@ func List(ctx *context.Context) { var subNames []string for _, tmplName := range templateNames { subName := strings.TrimSuffix(tmplName, ".tmpl") - if subName != "list" { + if !strings.HasPrefix(subName, "devtest-") { subNames = append(subNames, subName) } } ctx.Data["SubNames"] = subNames - ctx.HTML(http.StatusOK, "devtest/list") + ctx.HTML(http.StatusOK, "devtest/devtest-list") } func FetchActionTest(ctx *context.Context) { diff --git a/templates/admin/emails/list.tmpl b/templates/admin/emails/list.tmpl index 835b77ea17..0dc1fb9d03 100644 --- a/templates/admin/emails/list.tmpl +++ b/templates/admin/emails/list.tmpl @@ -50,10 +50,10 @@ {{svg (Iif .IsPrimary "octicon-check" "octicon-x")}} {{if .CanChange}} - + {{svg (Iif .IsActivated "octicon-check" "octicon-x")}} {{else}} @@ -61,9 +61,10 @@ {{end}} -
- {{svg "octicon-trash"}} -
+ {{svg "octicon-trash"}} {{end}} @@ -77,40 +78,24 @@
{{ctx.Locale.Tr "admin.emails.change_email_header"}}
-
+

{{ctx.Locale.Tr "admin.emails.change_email_text"}}

- - {{$.CsrfTokenHtml}} + {{$.CsrfTokenHtml}} - - - - + + + + - - - - + + + + -
- {{template "base/modal_actions_confirm" .}} -
-
-
+ {{template "base/modal_actions_confirm" .}} + - - - {{template "admin/layout_footer" .}} diff --git a/templates/devtest/devtest-footer.tmpl b/templates/devtest/devtest-footer.tmpl new file mode 100644 index 0000000000..1c755508a5 --- /dev/null +++ b/templates/devtest/devtest-footer.tmpl @@ -0,0 +1,3 @@ +{{/* TODO: the devtest.js is isolated from index.js, so no module is shared and many index.js functions do not work in devtest.ts */}} + +{{template "base/footer" dict}} diff --git a/templates/devtest/devtest-header.tmpl b/templates/devtest/devtest-header.tmpl new file mode 100644 index 0000000000..a5910b96e6 --- /dev/null +++ b/templates/devtest/devtest-header.tmpl @@ -0,0 +1,2 @@ +{{template "base/head" dict}} + diff --git a/templates/devtest/list.tmpl b/templates/devtest/devtest-list.tmpl similarity index 65% rename from templates/devtest/list.tmpl rename to templates/devtest/devtest-list.tmpl index 90b1fcc9d0..71ee6807f0 100644 --- a/templates/devtest/list.tmpl +++ b/templates/devtest/devtest-list.tmpl @@ -1,5 +1,4 @@ -{{template "base/head" .}} - +{{template "devtest/devtest-header"}}