summaryrefslogtreecommitdiff
path: root/users/app/assets/javascripts/users.js.coffee
diff options
context:
space:
mode:
authorjessib <jessib@leap.se>2012-11-19 13:33:23 -0800
committerjessib <jessib@leap.se>2012-11-19 13:33:23 -0800
commit347eb4b20cbe740485dd9d1d7220c01eef659920 (patch)
treeb004aaede235d7c6d2bbd63b8bed5f42d2bce290 /users/app/assets/javascripts/users.js.coffee
parent341da14b031c3c27e687c82f479624217c1dbddd (diff)
parent172317b35d9c7ae26a6bf4836feace7b509644a6 (diff)
Merge branch 'develop' into help_develop
Conflicts: app/assets/javascripts/application.js ui_dependencies.rb
Diffstat (limited to 'users/app/assets/javascripts/users.js.coffee')
-rw-r--r--users/app/assets/javascripts/users.js.coffee56
1 files changed, 29 insertions, 27 deletions
diff --git a/users/app/assets/javascripts/users.js.coffee b/users/app/assets/javascripts/users.js.coffee
index 24302fe..ab437f6 100644
--- a/users/app/assets/javascripts/users.js.coffee
+++ b/users/app/assets/javascripts/users.js.coffee
@@ -1,45 +1,47 @@
-# Place all the behaviors and hooks related to the matching controller here.
-# All this logic will automatically be available in application.js.
-# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
-#
+preventDefault = (event) ->
+ event.preventDefault()
-validate_password = (event) ->
-
- password = $('#srp_password').val()
- confirmation = $('#srp_password_confirmation').val()
- login = $('#srp_username').val()
-
- if password != confirmation
- alert "Password and Confirmation do not match!"
- $('#srp_password').focus()
- return false
- if password == login
- alert "Password and Login may not match!"
- $('#srp_password').focus()
- return false
- if password.length < 8
- alert "Password needs to be at least 8 characters long!"
- $('#srp_password').focus()
- return false
+validOrAbort = (event) ->
+ errors = {}
+
+ abortIfErrors = ->
+ return if $.isEmptyObject(errors)
+ # we're relying on client_side_validations here instead of printing
+ # our own errors. This gets us translatable error messages.
+ $('.control-group.error input, .control-group.error select, control-group.error textarea').first().focus()
+ event.stopImmediatePropagation()
+
+ validatePassword = ->
+ password = $('#srp_password').val()
+ confirmation = $('#srp_password_confirmation').val()
+ login = $('#srp_username').val()
+
+ if password != confirmation
+ errors.password_confirmation = "Confirmation does not match!"
+ if password == login
+ errors.password = "Password and Login may not match!"
+ if password.length < 8
+ errors.password = "Password needs to be at least 8 characters long!"
+
+ validatePassword()
+ abortIfErrors()
- return true
-
signup = (event) ->
srp = new SRP(jqueryRest())
srp.register ->
window.location = '/'
- false
login = (event) ->
srp = new SRP(jqueryRest())
srp.identify ->
window.location = '/'
- false
$(document).ready ->
- $('#new_user').submit validate_password
+ $('#new_user').submit preventDefault
+ $('#new_user').submit validOrAbort
$('#new_user').submit signup
+ $('#new_session').submit preventDefault
$('#new_session').submit login