summaryrefslogtreecommitdiff
path: root/users/app/assets/javascripts/users.js
diff options
context:
space:
mode:
authorjessib <jessib@riseup.net>2013-12-17 12:02:07 -0800
committerjessib <jessib@riseup.net>2013-12-17 12:02:07 -0800
commit98a247acb4d1be484c2982d48ec038eed3de3d55 (patch)
treef176092fa43145b9d8ce00a180fab70cf62da456 /users/app/assets/javascripts/users.js
parent634db9875cc8f6f6b9a4a83dfc6b8d53728eb2b5 (diff)
parent83cd3d95b78b6df9ac33a8ee169e570f4d3e2eeb (diff)
Merge branch 'develop' into feature/billing-no-authenticated-payments
Conflicts: billing/config/locales/en.yml
Diffstat (limited to 'users/app/assets/javascripts/users.js')
-rw-r--r--users/app/assets/javascripts/users.js51
1 files changed, 35 insertions, 16 deletions
diff --git a/users/app/assets/javascripts/users.js b/users/app/assets/javascripts/users.js
index aaeba6e..8486756 100644
--- a/users/app/assets/javascripts/users.js
+++ b/users/app/assets/javascripts/users.js
@@ -46,6 +46,13 @@
$(form).find('input[type="submit"]').button('loading');
};
+ resetButtons = function(submitEvent) {
+ var form = $('form.submitted')
+ // bootstrap loading state:
+ $(form).find('input[type="submit"]').button('reset');
+ $(form).removeClass('submitted')
+ };
+
//
// PUBLIC FUNCTIONS
//
@@ -70,24 +77,36 @@
//
srp.error = function(message) {
clear_errors();
- var element, error, field;
+ var errors = extractErrors(message);
+ displayErrors(errors);
+ resetButtons();
+ }
+
+ function extractErrors(message) {
if ($.isPlainObject(message) && message.errors) {
- for (field in message.errors) {
- if (field == 'base') {
- alert_message(message.errors[field]);
- continue;
- }
- error = message.errors[field];
- element = $('form input[name$="[' + field + ']"]');
- if (!element) {
- continue;
- }
- element.trigger('element:validate:fail.ClientSideValidations', error).data('valid', false);
- }
- } else if (message.error) {
- alert_message(message.error);
+ return message.errors;
} else {
- alert_message(JSON.stringify(message));
+ return {
+ base: (message.error || JSON.stringify(message))
+ };
+ }
+ }
+
+ function displayErrors(errors) {
+ for (var field in errors) {
+ var error = errors[field];
+ if (field === 'base') {
+ alert_message(error);
+ } else {
+ displayFieldError(field, error);
+ }
+ }
+ }
+
+ function displayFieldError(field, error) {
+ var element = $('form input[name$="[' + field + ']"]');
+ if (element) {
+ element.trigger('element:validate:fail.ClientSideValidations', error).data('valid', false);
}
};