Anton Shestakov <av6@dwimlabs.net>, Mon, 21 Mar 2016 20:10:19 +0800
index: get version info from server on connect, show it in a message log
coffee/index.coffee
Permissions: -rw-r--r--
window.messages ?= new Tram.Messages() window.logApp ?= new Tram.LogApp(el: $('[data-app="log"]'), collection: messages) if el.childNodes.length is 0 and el.nodeType is Strophe.ElementType.TEXT for node in el.childNodes if node.nodeType is Strophe.ElementType.TEXT iq = $iq(type: 'get', id: X.conn.getUniqueId('version'), to: Tram.config.domain).c('query', xmlns: Strophe.NS.VERSION) name = getText stanza.getElementsByTagName('name')[0] version = getText stanza.getElementsByTagName('version')[0] os = getText stanza.getElementsByTagName('os')[0] delay = stanza.getElementsByTagName('delay')[0] stamp = if delay then new Date(delay.getAttribute('stamp')) else new Date() id: stanza.getAttribute('id') type: stanza.getAttribute('type') from: stanza.getAttribute('from') text: "connected to #{ name } #{ version } on #{ os }" console.error("couldn't get version", stanza?.innerHTML) X.conn.sendIQ(iq.tree(), okcb, failcb, 5000) window.X = new Tram.XMPPInterface() $('[data-msg^="a/"]').addClass('uk-hidden') $('[data-msg="a/fail"]').removeClass('uk-hidden') $('[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 index = $form.find('input').index(@) $next = $form.find('input').eq(index + 1) $form.find('button').trigger('click') $form.find('button').on 'click', (e) -> Tram.validation.unsetError($('#username, #password')) ok &= Tram.validation.validateRequired($('#username'), true) ok &= Tram.validation.validateRequired($('#password')) X.connect($('#username').val().trim(), $('#password').val())