22:dba8124befc3
Anton Shestakov <av6@dwimlabs.net>, Mon, 21 Mar 2016 15:47:51 +0800
index: wire up login form

next change 23:98a9a4b85104

coffee/index.coffee

Permissions: -rw-r--r--

Other formats: Feeds:
window.X = new Tram.XMPPInterface()
X.on 'connecting', ->
$('[data-msg^="a/"]').addClass('uk-hidden')
X.on 'authfail', ->
$('[data-msg="a/fail"]').removeClass('uk-hidden')
X.on 'disconnected', ->
$('[data-step="login"]').removeClass('uk-hidden')
X.on 'connected attached', ->
$('[data-step="login"]').addClass('uk-hidden')
$form = $('[data-form="connect"]')
$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')
$form.find('button').on 'click', (e) ->
e.preventDefault()
ok = true
Tram.validation.unsetError($('#username, #password'))
ok &= Tram.validation.validateRequired($('#username'), true)
ok &= Tram.validation.validateRequired($('#password'))
if ok
X.connect($('#username').val().trim(), $('#password').val())