blob: c9cc18268ee692967195b7612d85b1e961ef6852 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
preventDefault = (event) ->
event.preventDefault()
srp.session = new srp.Session()
srp.signedUp = ->
srp.login()
srp.loggedIn = ->
window.location = '/'
#// TODO: not sure this is what we want.
srp.updated = ->
window.location = '/'
srp.error = (message) ->
if $.isPlainObject(message) && message.errors
display_errors(message.errors)
else
alert(message)
display_errors = (errors) ->
clear_errors();
for field, error of errors
if field == 'base'
display_base_error(error);
else
display_field_error(field, error);
clear_errors = ->
$('#messages').empty();
display_field_error = (field, error) ->
element = $('form input[name$="['+field+']"]')
return unless element
element.trigger('element:validate:fail.ClientSideValidations', error).data('valid', false)
display_base_error = (message) ->
messages = $('#messages')
messages.append "<div class=\"alert alert-error\">" + message + "</div></div>"
pollUsers = (query, process) ->
$.get( "/users.json", query: query).done(process)
followLocationHash = ->
location = window.location.hash
if location
href_select = 'a[href="' + location + '"]'
link = $(href_select)
link.tab('show') if link
$(document).ready ->
followLocationHash()
$('#new_user').submit preventDefault
$('#new_user').submit srp.signup
$('#new_session').submit preventDefault
$('#new_session').submit srp.login
$('.user.form.update_login_and_password').submit srp.update
$('.user.form.update_login_and_password').submit preventDefault
$('.user.typeahead').typeahead({source: pollUsers});
$('a[data-toggle="tab"]').on('shown', ->
$(ClientSideValidations.selectors.forms).validate()
)
|