38:91e692b46f92
Anton Shestakov <av6@dwimlabs.net>, Tue, 22 Mar 2016 20:54:38 +0800
provision: run as user 'vagrant' by default to remove synced_folder hack

next change 46:e3696f4866fc
previous change 21:e43ed046f909

coffee/register.coffee

Permissions: -rw-r--r--

Other formats: Feeds:
window.X = new Tram.XMPPInterface()
X.on 'register', ->
$('[data-step="registration"]').removeClass('uk-hidden')
X.on 'registered', ->
X.finishRegistration()
$('[data-step="registration"]').addClass('uk-hidden')
X.on 'regifail', ->
$('[data-msg="registration-closed"]').removeClass('uk-hidden')
X.on 'conflict', ->
Tram.validation.setError($('#username'), 'A user with this username already exists.')
X.on 'notacceptable', ->
$('[data-msg="registration-failed"]').removeClass('uk-hidden')
X.on 'connected', ->
$('#nickname').val($('#username').val())
$('[data-step="vcard"]').removeClass('uk-hidden')
$('#fullname').focus()
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', ->
data =
fullname: $('#fullname').val()
nickname: $('#nickname').val()
okcb = ->
console.debug('vcard is set!', arguments)
$('[data-step="vcard"]').addClass('uk-hidden')
location.href = '/'
failcb = ->
console.warn('vcard is NOT set!', arguments)
$('[data-msg="save-failed"]').removeClass('uk-hidden')
file = $('#avatar').get(0).files[0]
if file
reader = new FileReader()
reader.onloadend = ->
_(data).extend(avatar: reader.result)
X.savevCard(data, okcb, failcb)
reader.readAsDataURL(file)
else
X.savevCard(data, okcb, failcb)