diff options
author | wxiaoguang <wxiaoguang@gmail.com> | 2023-06-13 20:10:10 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-13 12:10:10 +0000 |
commit | 6bbccdd177bcbac600e3019062c96339a121851a (patch) | |
tree | 92d53bbdd976b6b8657b10ccda910a08d094dc81 /templates | |
parent | a51b115b0ad755562c71f6a382326c59868dfb96 (diff) | |
download | gitea-6bbccdd177bcbac600e3019062c96339a121851a.tar.gz gitea-6bbccdd177bcbac600e3019062c96339a121851a.zip |
Improve AJAX link and modal confirm dialog (#25210)
Clarify the "link-action" behavior:
> // 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.
And enhance the "link-action" to support showing a modal dialog for
confirm. A similar general approach could also help PRs like
https://github.com/go-gitea/gitea/pull/22344#discussion_r1062883436
> // If the "link-action" has "data-modal-confirm(-html)" attribute, a
confirm modal dialog will be shown before taking action.
And a lot of duplicate code can be removed now. A good framework design
can help to avoid code copying&pasting.
---------
Co-authored-by: silverwind <me@silverwind.io>
Diffstat (limited to 'templates')
-rw-r--r-- | templates/admin/user/edit.tmpl | 2 | ||||
-rw-r--r-- | templates/base/head_script.tmpl | 12 | ||||
-rw-r--r-- | templates/org/settings/options.tmpl | 2 | ||||
-rw-r--r-- | templates/org/team/members.tmpl | 10 | ||||
-rw-r--r-- | templates/org/team/repositories.tmpl | 52 | ||||
-rw-r--r-- | templates/repo/branch/list.tmpl | 2 | ||||
-rw-r--r-- | templates/repo/settings/options.tmpl | 2 | ||||
-rw-r--r-- | templates/user/settings/profile.tmpl | 2 |
8 files changed, 28 insertions, 56 deletions
diff --git a/templates/admin/user/edit.tmpl b/templates/admin/user/edit.tmpl index 4e982234de..63703d7837 100644 --- a/templates/admin/user/edit.tmpl +++ b/templates/admin/user/edit.tmpl @@ -186,7 +186,7 @@ <div class="field"> <button class="ui green button">{{$.locale.Tr "settings.update_avatar"}}</button> - <a class="ui red button delete-post" data-request-url="{{.Link}}/avatar/delete" data-done-url="{{.Link}}">{{$.locale.Tr "settings.delete_current_avatar"}}</a>{{/* TODO: Convert links without href to buttons for a11y */}} + <button class="ui red button link-action" data-url="{{.Link}}/avatar/delete" data-redirect="{{.Link}}">{{$.locale.Tr "settings.delete_current_avatar"}}</button> </div> </form> </div> diff --git a/templates/base/head_script.tmpl b/templates/base/head_script.tmpl index 4e1dffa474..b6475a83cd 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 21b14200ff..12a24bff08 100644 --- a/templates/org/settings/options.tmpl +++ b/templates/org/settings/options.tmpl @@ -90,7 +90,7 @@ <div class="field"> <button class="ui green button">{{$.locale.Tr "settings.update_avatar"}}</button> - <a class="ui red button delete-post" data-request-url="{{.Link}}/avatar/delete" data-done-url="{{.Link}}">{{$.locale.Tr "settings.delete_current_avatar"}}</a> + <button class="ui red button link-action" data-url="{{.Link}}/avatar/delete" data-redirect="{{.Link}}">{{$.locale.Tr "settings.delete_current_avatar"}}</button> </div> </form> </div> diff --git a/templates/org/team/members.tmpl b/templates/org/team/members.tmpl index f1ccbc0124..6bd258955d 100644 --- a/templates/org/team/members.tmpl +++ b/templates/org/team/members.tmpl @@ -9,14 +9,12 @@ {{template "org/team/navbar" .}} {{if .IsOrganizationOwner}} <div class="ui attached segment"> - <form class="ui form ignore-dirty" id="add-member-form" action="{{$.OrgLink}}/teams/{{$.Team.LowerName | PathEscape}}/action/add" method="post"> + <form class="ui form ignore-dirty gt-df gt-fw gt-gap-3" action="{{$.OrgLink}}/teams/{{$.Team.LowerName | PathEscape}}/action/add" method="post"> {{.CsrfTokenHtml}} <input type="hidden" name="uid" value="{{.SignedUser.ID}}"> - <div class="inline field ui left"> - <div id="search-user-box" class="ui search"{{if .IsEmailInviteEnabled}} data-allow-email="true" data-allow-email-description="{{.locale.Tr "org.teams.invite_team_member" $.Team.Name}}"{{end}}> - <div class="ui input"> - <input class="prompt" name="uname" placeholder="{{.locale.Tr "repo.settings.search_user_placeholder"}}" autocomplete="off" required> - </div> + <div id="search-user-box" class="ui search gt-mr-3"{{if .IsEmailInviteEnabled}} data-allow-email="true" data-allow-email-description="{{.locale.Tr "org.teams.invite_team_member" $.Team.Name}}"{{end}}> + <div class="ui input"> + <input class="prompt" name="uname" placeholder="{{.locale.Tr "repo.settings.search_user_placeholder"}}" autocomplete="off" required> </div> </div> <button class="ui green button">{{.locale.Tr "org.teams.add_team_member"}}</button> diff --git a/templates/org/team/repositories.tmpl b/templates/org/team/repositories.tmpl index 9263caf48c..83e238016a 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}} - <div class="ui attached segment" id="repo-top-segment"> - <div class="inline ui field left"> - <form class="ui form ignore-dirty" id="add-repo-form" action="{{$.OrgLink}}/teams/{{$.Team.LowerName | PathEscape}}/action/repo/add" method="post"> - {{.CsrfTokenHtml}} - <div class="inline field ui left"> - <div id="search-repo-box" data-uid="{{.Org.ID}}" class="ui search"> - <div class="ui input"> - <input class="prompt" name="repo_name" placeholder="{{.locale.Tr "org.teams.search_repo_placeholder"}}" autocomplete="off" required> - </div> - </div> + <div class="ui attached segment gt-df gt-fw gt-gap-3"> + <form class="ui form ignore-dirty gt-f1 gt-dif" action="{{$.OrgLink}}/teams/{{$.Team.LowerName | PathEscape}}/action/repo/add" method="post"> + {{.CsrfTokenHtml}} + <div id="search-repo-box" data-uid="{{.Org.ID}}" class="ui search"> + <div class="ui input"> + <input class="prompt" name="repo_name" placeholder="{{.locale.Tr "org.teams.search_repo_placeholder"}}" autocomplete="off" required> </div> - <button class="ui green button">{{.locale.Tr "add"}}</button> - </form> - </div> - <div class="inline ui field right"> - <form class="ui form" id="repo-multiple-form" action="{{$.OrgLink}}/teams/{{$.Team.LowerName | PathEscape}}/repositories" method="post"> - <button class="ui green button add-all-button" data-modal-id="org-team-add-all-repo" data-url="{{$.OrgLink}}/teams/{{$.Team.LowerName | PathEscape}}/action/repo/addall">{{.locale.Tr "add_all"}}</button> - <button class="ui red button delete-button" data-modal-id="org-team-remove-all-repo" data-url="{{$.OrgLink}}/teams/{{$.Team.LowerName | PathEscape}}/action/repo/removeall">{{.locale.Tr "remove_all"}}</button> - </form> + </div> + <button class="ui green button gt-ml-3">{{.locale.Tr "add"}}</button> + </form> + <div class="gt-dib"> + <button class="ui green button link-action" data-modal-confirm="{{.locale.Tr "org.teams.add_all_repos_desc"}}" data-url="{{$.OrgLink}}/teams/{{$.Team.LowerName | PathEscape}}/action/repo/addall">{{.locale.Tr "add_all"}}</button> + <button class="ui red button link-action" data-modal-confirm="{{.locale.Tr "org.teams.remove_all_repos_desc"}}" data-url="{{$.OrgLink}}/teams/{{$.Team.LowerName | PathEscape}}/action/repo/removeall">{{.locale.Tr "remove_all"}}</button> </div> </div> {{end}} @@ -64,26 +58,4 @@ </div> </div> -<div class="ui g-modal-confirm delete modal" id="org-team-remove-all-repo"> - <div class="header"> - {{svg "octicon-trash"}} - {{.locale.Tr "org.teams.remove_all_repos_title"}} - </div> - <div class="content"> - <p>{{.locale.Tr "org.teams.remove_all_repos_desc"}}</p> - </div> - {{template "base/modal_actions_confirm" .}} -</div> - -<div class="ui g-modal-confirm addall modal" id="org-team-add-all-repo"> - <div class="header"> - {{svg "octicon-globe"}} - {{.locale.Tr "org.teams.add_all_repos_title"}} - </div> - <div class="content"> - <p>{{.locale.Tr "org.teams.add_all_repos_desc"}}</p> - </div> - {{template "base/modal_actions_confirm" .}} -</div> - {{template "base/footer" .}} diff --git a/templates/repo/branch/list.tmpl b/templates/repo/branch/list.tmpl index 8617bcafaf..d68feb43b7 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}} - <button class="btn interact-bg gt-p-3 undo-button" data-url="{{$.Link}}/restore?branch_id={{.DeletedBranch.ID}}&name={{.DeletedBranch.Name}}&page={{$.Page.Paginater.Current}}" data-tooltip-content="{{$.locale.Tr "repo.branch.restore" (.Name)}}"> + <button class="btn interact-bg gt-p-3 link-action restore-branch-button" data-url="{{$.Link}}/restore?branch_id={{.DeletedBranch.ID}}&name={{.DeletedBranch.Name}}&page={{$.Page.Paginater.Current}}" data-tooltip-content="{{$.locale.Tr "repo.branch.restore" (.Name)}}"> <span class="text blue"> {{svg "octicon-reply"}} </span> diff --git a/templates/repo/settings/options.tmpl b/templates/repo/settings/options.tmpl index 1e940c581b..a1fe1ad5af 100644 --- a/templates/repo/settings/options.tmpl +++ b/templates/repo/settings/options.tmpl @@ -61,7 +61,7 @@ <div class="field"> <button class="ui green button">{{$.locale.Tr "settings.update_avatar"}}</button> - <a class="ui red button delete-post" data-request-url="{{.Link}}/avatar/delete" data-done-url="{{.Link}}">{{$.locale.Tr "settings.delete_current_avatar"}}</a> + <button class="ui red button link-action" data-url="{{.Link}}/avatar/delete" data-redirect="{{.Link}}">{{$.locale.Tr "settings.delete_current_avatar"}}</button> </div> </form> diff --git a/templates/user/settings/profile.tmpl b/templates/user/settings/profile.tmpl index a581b13bd5..350f8a0275 100644 --- a/templates/user/settings/profile.tmpl +++ b/templates/user/settings/profile.tmpl @@ -125,7 +125,7 @@ <div class="field"> <button class="ui green button">{{$.locale.Tr "settings.update_avatar"}}</button> - <button class="ui red button delete-post" data-request-url="{{.Link}}/avatar/delete" data-done-url="{{.Link}}">{{$.locale.Tr "settings.delete_current_avatar"}}</button> + <button class="ui red button link-action" data-url="{{.Link}}/avatar/delete" data-redirect="{{.Link}}">{{$.locale.Tr "settings.delete_current_avatar"}}</button> </div> </form> </div> |