summaryrefslogtreecommitdiff
path: root/users
diff options
context:
space:
mode:
authorAzul <azul@leap.se>2013-09-25 10:12:08 +0200
committerAzul <azul@leap.se>2013-09-25 10:12:08 +0200
commit4f8414298750193b6de3daff08364ec745a6a761 (patch)
treef13b9b550d0179f6b82227345f02f97e3949ad6c /users
parent193bf6446b384dce1699e8fb82be6f16cb8cb5f6 (diff)
visual feedback when submitting forms (#3164)
This also helps with the failing integration test. We needed a way to tell the ajax request was back. Observing the button state now works for that.
Diffstat (limited to 'users')
-rw-r--r--users/app/assets/javascripts/users.js13
-rw-r--r--users/app/views/users/_edit.html.haml2
-rw-r--r--users/test/integration/browser/account_test.rb7
3 files changed, 18 insertions, 4 deletions
diff --git a/users/app/assets/javascripts/users.js b/users/app/assets/javascripts/users.js
index 9d1a0f0..aaeba6e 100644
--- a/users/app/assets/javascripts/users.js
+++ b/users/app/assets/javascripts/users.js
@@ -28,12 +28,22 @@
var form = submitEvent.target;
var token = form.dataset.token;
var url = form.action;
- return $.ajax({
+ var req = $.ajax({
url: url,
type: 'PUT',
headers: { Authorization: 'Token token="' + token + '"' },
data: $(form).serialize()
});
+ req.done( function() {
+ $(form).find('input[type="submit"]').button('reset');
+ });
+ };
+
+ markAsSubmitted = function(submitEvent) {
+ var form = submitEvent.target;
+ $(form).addClass('submitted')
+ // bootstrap loading state:
+ $(form).find('input[type="submit"]').button('loading');
};
//
@@ -86,6 +96,7 @@
//
$(document).ready(function() {
+ $('form').submit(markAsSubmitted);
$('#new_user').submit(prevent_default);
$('#new_user').submit(srp.signup);
$('#new_session').submit(prevent_default);
diff --git a/users/app/views/users/_edit.html.haml b/users/app/views/users/_edit.html.haml
index ae3f32d..9d2473b 100644
--- a/users/app/views/users/_edit.html.haml
+++ b/users/app/views/users/_edit.html.haml
@@ -35,7 +35,7 @@
= f.input :public_key, :as => :text, :hint => t(:use_ascii_key), :input_html => {:class => "full-width", :rows => 4}
.control-group
.controls
- = f.submit t(:save), :class => 'btn'
+ = f.submit t(:save), :class => 'btn', :data => {"loading-text" => "Saving..."}
-#
-# DESTROY ACCOUNT
diff --git a/users/test/integration/browser/account_test.rb b/users/test/integration/browser/account_test.rb
index 3434557..1deda45 100644
--- a/users/test/integration/browser/account_test.rb
+++ b/users/test/integration/browser/account_test.rb
@@ -52,8 +52,11 @@ class AccountTest < BrowserIntegrationTest
fill_in 'Public key', with: pgp_key
click_on 'Save'
end
- debugger
- assert user = User.find_by_login(username)
+ page.assert_selector 'input[value="Saving..."]'
+ # at some point we're done:
+ page.assert_no_selector 'input[value="Saving..."]'
+ assert page.has_field? 'Public key', with: pgp_key
+ user = User.find_by_login(username)
assert_equal pgp_key, user.public_key
user.account.destroy
end