From c6f0bfb212e0002b589b674ccd6e926ca45f77eb Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Mon, 12 Jun 2023 21:24:40 +0800 Subject: [PATCH 1/4] fix --- templates/admin/user/edit.tmpl | 2 +- templates/base/head_script.tmpl | 12 ++- templates/org/settings/options.tmpl | 2 +- templates/org/team/members.tmpl | 12 +-- templates/org/team/repositories.tmpl | 52 +++------- templates/repo/branch/list.tmpl | 2 +- templates/repo/settings/options.tmpl | 2 +- templates/user/settings/profile.tmpl | 2 +- tests/integration/branches_test.go | 2 +- web_src/css/org.css | 23 ----- web_src/js/features/common-global.js | 140 ++++++++++++--------------- 11 files changed, 93 insertions(+), 158 deletions(-) diff --git a/templates/admin/user/edit.tmpl b/templates/admin/user/edit.tmpl index 4e982234de644..63703d78371b6 100644 --- a/templates/admin/user/edit.tmpl +++ b/templates/admin/user/edit.tmpl @@ -186,7 +186,7 @@
- {{$.locale.Tr "settings.delete_current_avatar"}}{{/* TODO: Convert links without href to buttons for a11y */}} +
diff --git a/templates/base/head_script.tmpl b/templates/base/head_script.tmpl index 4e1dffa474a2c..b6475a83cdba8 100644 --- a/templates/base/head_script.tmpl +++ b/templates/base/head_script.tmpl @@ -32,11 +32,13 @@ If you introduce mistakes in it, Gitea JavaScript code wouldn't run correctly. mermaidMaxSourceCharacters: {{MermaidMaxSourceCharacters}}, {{/* this global i18n object should only contain general texts. for specialized texts, it should be provided inside the related modules by: (1) API response (2) HTML data-attribute (3) PageData */}} i18n: { - copy_success: '{{.locale.Tr "copy_success"}}', - copy_error: '{{.locale.Tr "copy_error"}}', - error_occurred: '{{.locale.Tr "error.occurred"}}', - network_error: '{{.locale.Tr "error.network_error"}}', - remove_label_str: '{{.locale.Tr "remove_label_str"}}', + copy_success: {{.locale.Tr "copy_success"}}, + copy_error: {{.locale.Tr "copy_error"}}, + error_occurred: {{.locale.Tr "error.occurred"}}, + network_error: {{.locale.Tr "error.network_error"}}, + remove_label_str: {{.locale.Tr "remove_label_str"}}, + modal_confirm: {{.locale.Tr "modal.confirm"}}, + modal_cancel: {{.locale.Tr "modal.cancel"}}, }, }; {{/* in case some pages don't render the pageData, we make sure it is an object to prevent null access */}} diff --git a/templates/org/settings/options.tmpl b/templates/org/settings/options.tmpl index 21b14200ff0c5..12a24bff08999 100644 --- a/templates/org/settings/options.tmpl +++ b/templates/org/settings/options.tmpl @@ -90,7 +90,7 @@
- {{$.locale.Tr "settings.delete_current_avatar"}} +
diff --git a/templates/org/team/members.tmpl b/templates/org/team/members.tmpl index f1ccbc012488a..ce3c22f2bafe3 100644 --- a/templates/org/team/members.tmpl +++ b/templates/org/team/members.tmpl @@ -9,17 +9,15 @@ {{template "org/team/navbar" .}} {{if .IsOrganizationOwner}}
-
+ {{.CsrfTokenHtml}} -
- {{end}} diff --git a/templates/org/team/repositories.tmpl b/templates/org/team/repositories.tmpl index 9263caf48c97f..2941a0fcb70ce 100644 --- a/templates/org/team/repositories.tmpl +++ b/templates/org/team/repositories.tmpl @@ -9,25 +9,19 @@ {{template "org/team/navbar" .}} {{$canAddRemove := and $.IsOrganizationOwner (not $.Team.IncludesAllRepositories)}} {{if $canAddRemove}} -
-
-
- {{.CsrfTokenHtml}} -
- +
+ + {{.CsrfTokenHtml}} + -
-
- - -
+
+ + +
+ +
{{end}} @@ -64,26 +58,4 @@
- - - - {{template "base/footer" .}} diff --git a/templates/repo/branch/list.tmpl b/templates/repo/branch/list.tmpl index 8617bcafafaaa..d68feb43b7893 100644 --- a/templates/repo/branch/list.tmpl +++ b/templates/repo/branch/list.tmpl @@ -165,7 +165,7 @@ {{end}} {{if and $.IsWriter (not $.IsMirror) (not $.Repository.IsArchived) (not .IsProtected)}} {{if .IsDeleted}} - - {{$.locale.Tr "settings.delete_current_avatar"}} +
diff --git a/templates/user/settings/profile.tmpl b/templates/user/settings/profile.tmpl index a581b13bd57fc..350f8a0275a18 100644 --- a/templates/user/settings/profile.tmpl +++ b/templates/user/settings/profile.tmpl @@ -125,7 +125,7 @@
- +
diff --git a/tests/integration/branches_test.go b/tests/integration/branches_test.go index efb3798bd7777..99d7eef706912 100644 --- a/tests/integration/branches_test.go +++ b/tests/integration/branches_test.go @@ -34,7 +34,7 @@ func TestDeleteBranch(t *testing.T) { func TestUndoDeleteBranch(t *testing.T) { onGiteaRun(t, func(t *testing.T, u *url.URL) { deleteBranch(t) - htmlDoc, name := branchAction(t, ".undo-button") + htmlDoc, name := branchAction(t, ".restore-branch-button") assert.Contains(t, htmlDoc.doc.Find(".ui.positive.message").Text(), translation.NewLocale("en-US").Tr("repo.branch.restore_success", name), diff --git a/web_src/css/org.css b/web_src/css/org.css index 7b73d8e57296e..400f4fbbd9719 100644 --- a/web_src/css/org.css +++ b/web_src/css/org.css @@ -205,29 +205,6 @@ margin: 0; } -.organization.teams #add-repo-form input, -.organization.teams #repo-multiple-form input, -.organization.teams #add-member-form input { - margin-left: 0; -} - -.organization.teams #add-repo-form .ui.button, -.organization.teams #repo-multiple-form .ui.button, -.organization.teams #add-member-form .ui.button { - margin-left: 5px; - margin-top: -3px; -} - -.organization.teams #repo-top-segment { - height: 60px; -} - -@media (max-width: 767.98px) { - .organization.teams #repo-top-segment { - height: 100px; - } -} - .org-team-navbar .active.item { background: var(--color-box-body) !important; } diff --git a/web_src/js/features/common-global.js b/web_src/js/features/common-global.js index cb50ebcae0000..93112eb06f0d1 100644 --- a/web_src/js/features/common-global.js +++ b/web_src/js/features/common-global.js @@ -9,7 +9,7 @@ import {svg} from '../svg.js'; import {hideElem, showElem, toggleElem} from '../utils/dom.js'; import {htmlEscape} from 'escape-goat'; -const {appUrl, csrfToken} = window.config; +const {appUrl, csrfToken, i18n} = window.config; export function initGlobalFormDirtyLeaveConfirm() { // Warn users that try to leave a page after entering data into a form. @@ -186,6 +186,68 @@ export function initGlobalDropzone() { } } +function linkAction(e) { + e.preventDefault(); + + // A "link-action" can post AJAX request to its "data-url" + // Then the browser is redirect to: the "redirect" in response, or "data-redirect" attribute, or current URL by reloading. + // If the "link-action" has "data-modal-confirm(-html)" attribute, a confirm modal dialog will be shown before taking action. + + const $this = $(e.target); + const redirect = $this.attr('data-redirect'); + + const request = () => { + $this.prop('disabled', true); + $.post($this.attr('data-url'), { + _csrf: csrfToken + }).done((data) => { + if (data && data.redirect) { + window.location.href = data.redirect; + } else if (redirect) { + window.location.href = redirect; + } else { + window.location.reload(); + } + }).always(() => { + $this.prop('disabled', false); + }); + }; + + let modalConfirmHtml = $this.attr('data-modal-confirm-html'); + if (!modalConfirmHtml) { + modalConfirmHtml = htmlEscape($this.attr('data-modal-confirm') || ''); + } + if (!modalConfirmHtml) { + request(); + return; + } + + const modalHtml = ` + +`; + + const $modal = $(modalHtml); + if ($this.hasClass('red') || $this.hasClass('yellow') || $this.hasClass('orange') || $this.hasClass('negative')) { + $modal.find('.ui.ok.button').removeClass('green').addClass('orange'); + } + + $modal.appendTo(document.body); + $modal.modal({ + onApprove() { + request(); + }, + onHidden() { + $modal.remove(); + }, + }).modal('show'); +} + export function initGlobalLinkActions() { function showDeletePopup(e) { e.preventDefault(); @@ -231,75 +293,9 @@ export function initGlobalLinkActions() { }).modal('show'); } - function showAddAllPopup(e) { - e.preventDefault(); - const $this = $(this); - let filter = ''; - if ($this.attr('data-modal-id')) { - filter += `#${$this.attr('data-modal-id')}`; - } - - const dialog = $(`.addall.modal${filter}`); - dialog.find('.name').text($this.data('name')); - - dialog.modal({ - closable: false, - onApprove() { - if ($this.data('type') === 'form') { - $($this.data('form')).trigger('submit'); - return; - } - - $.post($this.data('url'), { - _csrf: csrfToken, - id: $this.data('id') - }).done((data) => { - window.location.href = data.redirect; - }); - } - }).modal('show'); - } - - function linkAction(e) { - e.preventDefault(); - const $this = $(this); - const redirect = $this.data('redirect'); - $this.prop('disabled', true); - $.post($this.data('url'), { - _csrf: csrfToken - }).done((data) => { - if (data.redirect) { - window.location.href = data.redirect; - } else if (redirect) { - window.location.href = redirect; - } else { - window.location.reload(); - } - }).always(() => { - $this.prop('disabled', false); - }); - } - // Helpers. $('.delete-button').on('click', showDeletePopup); $('.link-action').on('click', linkAction); - - // FIXME: this function is only used once, and not common, not well designed. should be refactored later - $('.add-all-button').on('click', showAddAllPopup); - - // FIXME: this is only used once, and should be replace with `link-action` instead - $('.undo-button').on('click', function () { - const $this = $(this); - $this.prop('disabled', true); - $.post($this.data('url'), { - _csrf: csrfToken, - id: $this.data('id') - }).done((data) => { - window.location.href = data.redirect; - }).always(() => { - $this.prop('disabled', false); - }); - }); } export function initGlobalButtons() { @@ -360,16 +356,6 @@ export function initGlobalButtons() { initCompColorPicker(); } }); - - $('.delete-post.button').on('click', function (e) { - e.preventDefault(); - const $this = $(this); - $.post($this.attr('data-request-url'), { - _csrf: csrfToken - }).done(() => { - window.location.href = $this.attr('data-done-url'); - }); - }); } /** From 31652977c27f6f93210d3e6add76e5a4bd8ca5ef Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Tue, 13 Jun 2023 01:10:59 +0800 Subject: [PATCH 2/4] Update web_src/js/features/common-global.js Co-authored-by: silverwind --- web_src/js/features/common-global.js | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/web_src/js/features/common-global.js b/web_src/js/features/common-global.js index 93112eb06f0d1..5e4b8aead53ad 100644 --- a/web_src/js/features/common-global.js +++ b/web_src/js/features/common-global.js @@ -222,20 +222,17 @@ function linkAction(e) { return; } - const modalHtml = ` + const okButtonColor = $this.hasClass('red') || $this.hasClass('yellow') || $this.hasClass('orange') || $this.hasClass('negative') ? 'orange' : 'green'; + + const $modal = $(` -`; - - const $modal = $(modalHtml); - if ($this.hasClass('red') || $this.hasClass('yellow') || $this.hasClass('orange') || $this.hasClass('negative')) { - $modal.find('.ui.ok.button').removeClass('green').addClass('orange'); - } +`); $modal.appendTo(document.body); $modal.modal({ From a94285e55ccb35d77e220a4af436e35411ab6f52 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Tue, 13 Jun 2023 01:13:14 +0800 Subject: [PATCH 3/4] fix --- web_src/js/features/common-global.js | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/web_src/js/features/common-global.js b/web_src/js/features/common-global.js index 5e4b8aead53ad..24e0232360ffa 100644 --- a/web_src/js/features/common-global.js +++ b/web_src/js/features/common-global.js @@ -213,17 +213,14 @@ function linkAction(e) { }); }; - let modalConfirmHtml = $this.attr('data-modal-confirm-html'); - if (!modalConfirmHtml) { - modalConfirmHtml = htmlEscape($this.attr('data-modal-confirm') || ''); - } + const modalConfirmHtml = htmlEscape($this.attr('data-modal-confirm') || ''); if (!modalConfirmHtml) { request(); return; } const okButtonColor = $this.hasClass('red') || $this.hasClass('yellow') || $this.hasClass('orange') || $this.hasClass('negative') ? 'orange' : 'green'; - + const $modal = $(`