20:aa1eeed14fff
Anton Shestakov <av6@dwimlabs.net>, Mon, 21 Mar 2016 10:29:04 +0800
register: move onConnect to XMPPInterface

next change 21:e43ed046f909
previous change 18:be40f584efc1

coffee/register.coffee

Permissions: -rw-r--r--

Other formats: Feeds:
window.X = new Tram.XMPPInterface()
X.startRegistration()
$('[data-form="registration"], [data-form="vcard"]').each ->
$form = $(@)
$form.find('input').on 'keydown', (e) ->
if (not @required or @value isnt '') and e.keyCode is 13
e.preventDefault()
index = $form.find('input').index(@)
$next = $form.find('input').eq(index + 1)
if $next.length isnt 0
$next.focus()
else
$form.find('button').trigger('click')
$('[data-form="registration"] button').on 'click', ->
ok = true
Tram.validation.unsetError($('#username, #password1, #password2'))
ok &= Tram.validation.validateRequired($('#username'), true)
ok &= Tram.validation.validatePasswords($('#password1'), $('#password2'))
ok &= Tram.validation.validateRequired($('#password1'))
ok &= Tram.validation.validateRequired($('#password2'))
if ok
X.register($('#username').val().trim(), $('#password1').val())
$('[data-form="vcard"] button').on 'click', ->
file = $('#avatar').get(0).files[0]
if file
reader = new FileReader()
reader.onloadend = ->
X.savevCard
fullname: $('#fullname').val()
nickname: $('#nickname').val()
avatar: @result
reader.readAsDataURL(file)
else
X.savevCard
fullname: $('#fullname').val()
nickname: $('#nickname').val()
X.on 'r/start', ->
$('[data-step="registration"]').removeClass('uk-hidden')
X.on 'r/done', ->
X.finishRegistration()
$('[data-step="registration"]').addClass('uk-hidden')
X.on 'r/closed', ->
$('[data-msg="r/closed"]').removeClass('uk-hidden')
X.on 'r/conflict', ->
Tram.validation.setError($('#username'), 'A user with this username already exists.')
X.on 'r/failed', ->
$('[data-msg="r/failed"]').removeClass('uk-hidden')
X.on 'v/start', ->
$('#nickname').val($('#username').val())
$('[data-step="vcard"]').removeClass('uk-hidden')
$('#fullname').focus()
X.on 'v/done', ->
$('[data-step="vcard"]').addClass('uk-hidden')
location.href = '/'
X.on 'v/failed', ->
$('[data-msg="v/failed"]').removeClass('uk-hidden')