39:28ad6d3e2618
Anton Shestakov <av6@dwimlabs.net>, Wed, 23 Mar 2016 16:55:52 +0800
index: maintain only one contact with type 'self' This isn't done in an event handler of contacts collection because doing it in 'add' handler would trigger 'sort' event after the model has been added, but before its 'add' event has propagated, and that's dumb.

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)