216:b9b340a89616
Anton Shestakov <av6@dwimlabs.net>, Fri, 12 Aug 2016 18:18:47 +0800
pipelines: check provisioning

previous change 170:584e37c0b89c

coffee/register.coffee

Permissions: -rw-r--r--

Other formats: Feeds:
window.clientState = new Tram.ClientState()
window.progressApp = new Tram.ProgressApp(el: $('[data-app="progress"]'), model: clientState)
window.regForm = new Tram.RegistrationForm()
window.profileForm = new Tram.ProfileForm()
registerfn = ->
if regForm.isValid()
clientState.set('progress', 0)
X.register(regForm.get('username').trim(), regForm.get('password1'))
savefn = ->
if not profileForm.isValid()
return
data =
fullname: profileForm.get('fullname').trim()
nickname: profileForm.get('nickname').trim()
okcb = ->
clientState.set('progress', 100)
$('[data-step="profile"]').addClass('uk-hidden')
location.href = '/'
failcb = ->
clientState.unset('progress')
console.warn('profile 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)
clientState.set('progress', 0)
X.savevCard(data, okcb, failcb)
reader.readAsDataURL(file)
else
clientState.set('progress', 0)
X.savevCard(data, okcb, failcb)
cancelfn = ->
X.unregister()
window.regRivet = rivets.bind($('[data-form="registration"]'), form: regForm, register: registerfn)
window.profileRivet = rivets.bind($('[data-form="profile"]'), form: profileForm, save: savefn, cancel: cancelfn)
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', ->
regForm.set('username-errors', ['A user with this username already exists.'])
X.on 'notacceptable', ->
$('[data-msg="registration-failed"]').removeClass('uk-hidden')
X.on 'connected', ->
profileForm.set('nickname', regForm.get('username').trim())
$('[data-step="profile"]').removeClass('uk-hidden')
$('#fullname').focus()
X.on 'disconnected', ->
location.reload()
X.on 'status', (status) ->
switch status
when Strophe.Status.REGISTERED
clientState.set('progress', 50)
when Strophe.Status.CONNECTED
clientState.set('progress', 100)
else
clientState.unset('progress')
X.startRegistration()
$('[data-form="registration"], [data-form="profile"]').streamline()