23:98a9a4b85104
Anton Shestakov <av6@dwimlabs.net>, Mon, 21 Mar 2016 19:50:21 +0800
index: disconnect button

next change 25:bab5df239765
previous change 22:dba8124befc3

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')
$('[data-step="main"]').addClass('uk-hidden')
X.on 'connected attached', ->
$('[data-step="login"]').addClass('uk-hidden')
$('[data-step="main"]').removeClass('uk-hidden')
$('button[data-disconnect]').on 'click', ->
X.disconnect('Logged out')
$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())