]> source.dussan.org Git - gitea.git/commitdiff
Don't warn users about *every* dirty form (#3707)
authorGerben <gerben@treora.com>
Fri, 23 Mar 2018 14:10:42 +0000 (15:10 +0100)
committerLunny Xiao <xiaolunwen@gmail.com>
Fri, 23 Mar 2018 14:10:42 +0000 (22:10 +0800)
The choice regarding which forms should or should not trigger a warning
is subjective. I tried to be consistent and not warn about forms that:
 - run an action, rather than edit data: search, send an email.
 - delete data: a warning about losing data would be confusing

Note that forms on sign-in pages were already ignored (using a selector,
rather than an explicit class on the form element).

Fixes #3698.

15 files changed:
public/js/index.js
templates/admin/base/search.tmpl
templates/admin/config.tmpl
templates/explore/code.tmpl
templates/explore/search.tmpl
templates/org/settings/delete.tmpl
templates/repo/commits_table.tmpl
templates/repo/home.tmpl
templates/repo/issue/search.tmpl
templates/repo/search.tmpl
templates/user/auth/activate.tmpl
templates/user/auth/forgot_passwd.tmpl
templates/user/auth/reset_passwd.tmpl
templates/user/settings/applications.tmpl
templates/user/settings/delete.tmpl

index 1e795a5044a28321d870f0d8b8c4ffbd1b04b743..8b3d7c3d7d441be70d5ea72e42833a7f89a76459 100644 (file)
@@ -1663,8 +1663,11 @@ function selectRange($list, $select, $from) {
 }
 
 $(function () {
-    if ($('.user.signin').length > 0) return;
-    $('form').areYouSure();
+    // Warn users that try to leave a page after entering data into a form.
+    // Except on sign-in pages, and for forms marked as 'ignore-dirty'.
+    if ($('.user.signin').length === 0) {
+      $('form:not(.ignore-dirty)').areYouSure();
+    }
 
     // Parse SSH Key
     $("#ssh-key-content").on('change paste keyup',function(){
index 749e42af2dc782c6ac6a269dbfad333495432325..7d23e51c890a4a9b809585dae7a6c1751bd05178 100644 (file)
@@ -17,7 +17,7 @@
                </div>
        </div>
 </div>
-<form class="ui form"  style="max-width: 90%">
+<form class="ui form ignore-dirty"  style="max-width: 90%">
        <div class="ui fluid action input">
          <input name="q" value="{{.Keyword}}" placeholder="{{.i18n.Tr "explore.search"}}..." autofocus>
          <button class="ui blue button">{{.i18n.Tr "explore.search"}}</button>
index fd9f4f3303a5c684cd3bee1f555692e4eb3e0b5d..7c353ad3010f55e1b07f0e42f58082650bb344d6 100644 (file)
                                        {{end}}
                                        <dt>{{.i18n.Tr "admin.config.mailer_user"}}</dt>
                                        <dd>{{if .Mailer.User}}{{.Mailer.User}}{{else}}(empty){{end}}</dd><br>
-                                       <form class="ui form" action="{{AppSubUrl}}/admin/config/test_mail" method="post">
+                                       <form class="ui form ignore-dirty" action="{{AppSubUrl}}/admin/config/test_mail" method="post">
                                                {{.CsrfTokenHtml}}
                                                <div class="inline field ui left">
                                                        <div class="ui input">
index 60034862135d32019597bc3e1bdf65f64d4aef7a..742ed59442a1a6bd9fab401d4134e3ec7b271d76 100644 (file)
@@ -2,7 +2,7 @@
 <div class="explore users">
        {{template "explore/navbar" .}}
        <div class="ui container">
-               <form class="ui form" style="max-width: 100%">
+               <form class="ui form ignore-dirty" style="max-width: 100%">
             <div class="ui fluid action input">
                 <input name="q" value="{{.Keyword}}" placeholder="{{.i18n.Tr "explore.search"}}..." autofocus>
                 <input type="hidden" name="tab" value="{{$.TabName}}">
index 6f37bcb23630def14b66e85d31dab1f57694214b..906dd06cafab7e312d25644194aab053d077232c 100644 (file)
@@ -15,7 +15,7 @@
                </div>
        </div>
 </div>
-<form class="ui form" style="max-width: 90%">
+<form class="ui form ignore-dirty" style="max-width: 90%">
        <div class="ui fluid action input">
          <input name="q" value="{{.Keyword}}" placeholder="{{.i18n.Tr "explore.search"}}..." autofocus>
          <input type="hidden" name="tab" value="{{$.TabName}}">
index dc1858e5c4c0eb99db7d4687eb70f0de74d6cb3d..3b0ee09b17ec0af053178ee7dfdec0ce5ee1a18d 100644 (file)
@@ -13,7 +13,7 @@
                                        <div class="ui red message">
                                                <p class="text left"><i class="octicon octicon-alert"></i> {{.i18n.Tr "org.settings.delete_prompt" | Str2html}}</p>
                                        </div>
-                                       <form class="ui form" id="delete-form" action="{{.Link}}" method="post">
+                                       <form class="ui form ignore-dirty" id="delete-form" action="{{.Link}}" method="post">
                                                {{.CsrfTokenHtml}}
                                                <input class="fake" type="password">
                                                <div class="inline required field {{if .Err_Password}}error{{end}}">
index 4503976e0ec9ebef4b3c95fd3ff0809bb7f75420..8a8e2c369e1853b88d3185f5e2d13f82e8066d8b 100644 (file)
@@ -5,7 +5,7 @@
                </div>
                <div class="ten wide right aligned column">
                        {{if .PageIsCommits}}
-                               <form action="{{.RepoLink}}/commits/{{.BranchNameSubURL}}/search">
+                               <form class="ignore-dirty" action="{{.RepoLink}}/commits/{{.BranchNameSubURL}}/search">
                                        <div class="ui tiny search input">
                                                <input name="q" placeholder="{{.i18n.Tr "repo.commits.search"}}" value="{{.Keyword}}" autofocus>
                                        </div>
index 91db56c98f8e3905e862dcc926ca568b50513822..9f705c967cfab889699c1f165fc2c2f13be97fd6 100644 (file)
@@ -10,7 +10,7 @@
                        </div>
                        {{if .RepoSearchEnabled}}
                                <div class="ui repo-search">
-                                       <form class="ui form" action="{{.RepoLink}}/search" method="get">
+                                       <form class="ui form ignore-dirty" action="{{.RepoLink}}/search" method="get">
                                                <div class="field">
                                                        <div class="ui action input">
                                                                <input name="q" value="{{.Keyword}}" placeholder="{{.i18n.Tr "repo.search.search_repo"}}">
index 5e0f9a562d8742e9e7ea1195b4687c14c9827844..522bced3cf66c81b6d98bfc0fcb85e7c7454ec22 100644 (file)
@@ -1,4 +1,4 @@
-<form class="ui form">
+<form class="ui form ignore-dirty">
        <div class="ui fluid action input">
                <input type="hidden" name="type" value="{{$.ViewType}}"/>
                <input type="hidden" name="state" value="{{$.State}}"/>
index 3ddc5de86c986b6ec4232dbdc345b63a29ecd1f5..c4413e7884e60bce1d940faa495c3a1dccbc7174 100644 (file)
@@ -3,7 +3,7 @@
        {{template "repo/header" .}}
        <div class="ui container">
                <div class="ui repo-search">
-                       <form class="ui form" method="get">
+                       <form class="ui form ignore-dirty" method="get">
                                <div class="ui fluid action input">
                                        <input name="q" value="{{.Keyword}}" placeholder="{{.i18n.Tr "repo.search.search_repo"}}">
                                        <button class="ui button" type="submit">
index 9805067ae18b9b929b27319c1031e2c57c7182d0..92b85a13738ddcbb6b4dd2394a4a189de96c7584 100644 (file)
@@ -2,7 +2,7 @@
 <div class="user activate">
        <div class="ui middle very relaxed page grid">
                <div class="column">
-                       <form class="ui form" action="{{AppSubUrl}}/user/activate" method="post">
+                       <form class="ui form ignore-dirty" action="{{AppSubUrl}}/user/activate" method="post">
                                {{.CsrfTokenHtml}}
                                <h2 class="ui top attached header">
                                        {{.i18n.Tr "auth.active_your_account"}}
index 2aeee300f076516c9ec754aef71eeeea5d5ceae0..1e061763a54189ef6d9e6f29d9cf633f919eba4b 100644 (file)
@@ -2,7 +2,7 @@
 <div class="user forgot password">
        <div class="ui middle very relaxed page grid">
                <div class="column">
-                       <form class="ui form" action="{{.Link}}" method="post">
+                       <form class="ui form ignore-dirty" action="{{.Link}}" method="post">
                                {{.CsrfTokenHtml}}
                                <h2 class="ui top attached header">
                                        {{.i18n.Tr "auth.forgot_password_title"}}
index 2408d39a7c9d13fabca3b3122e28bc73265d8cd9..19a7c8eea8a1ba2fc9e965f2ad7ca595fb3ba799 100644 (file)
@@ -2,7 +2,7 @@
 <div class="user reset password">
        <div class="ui middle very relaxed page grid">
                <div class="column">
-                       <form class="ui form" action="{{.Link}}" method="post">
+                       <form class="ui form ignore-dirty" action="{{.Link}}" method="post">
                                {{.CsrfTokenHtml}}
                                <input name="code" type="hidden" value="{{.Code}}">
                                <h2 class="ui top attached header">
index 93b2f992df154af21bafbbcf49ab4f3d687f95c1..66a011ac9ac3f2eac2e901cb55a2e280fd1c478a 100644 (file)
@@ -38,7 +38,7 @@
                                {{.i18n.Tr "settings.generate_new_token"}}
                        </h4>
                        <div class="ui attached segment">
-                               <form class="ui form" action="{{.Link}}" method="post">
+                               <form class="ui form ignore-dirty" action="{{.Link}}" method="post">
                                        {{.CsrfTokenHtml}}
                                        <p>{{.i18n.Tr "settings.new_token_desc"}}</p>
                                        <div class="field {{if .Err_Name}}error{{end}}">
index 77ddda837bbdd58ea9facdb42d3f9f7e116aa7f2..76ac7233bd55365552c7f1966da2558a01b63878 100644 (file)
@@ -10,7 +10,7 @@
                        <div class="ui red message">
                                <p class="text left"><i class="octicon octicon-alert"></i> {{.i18n.Tr "settings.delete_prompt" | Str2html}}</p>
                        </div>
-                       <form class="ui form" id="delete-form" action="{{.Link}}" method="post">
+                       <form class="ui form ignore-dirty" id="delete-form" action="{{.Link}}" method="post">
                                {{.CsrfTokenHtml}}
                                <input class="fake" type="password">
                                <div class="required field {{if .Err_Password}}error{{end}}">