Anton Shestakov <av6@dwimlabs.net>, Sun, 27 Mar 2016 11:21:22 +0800
register: redo form validation using rivets
js/index.js
Permissions: -rw-r--r--
// Generated by CoffeeScript 1.10.0 var $form, getContact, getContactProfile, getText, getVersion, onConnected, onDisconnected, onGetVersion, onPresence, onProfileUpdate; Strophe.addNamespace('VCARD_UPDATE', 'vcard-temp:x:update'); if (window.contacts == null) { window.contacts = new Tram.Contacts(); if (window.contactsApp == null) { window.contactsApp = new Tram.ContactsApp({ el: $('[data-app="contacts"]'), if (window.messages == null) { window.messages = new Tram.Messages(); if (window.logApp == null) { window.logApp = new Tram.LogApp({ el: $('[data-app="log"]'), if (window.favstate == null) { window.favstate = new Tram.FavState(); if (window.faviconApp == null) { window.faviconApp = new Tram.FaviconApp({ contacts.on('change:show', function(model) { if (model.get('type') === 'self') { return favstate.set('show', model.get('show')); onConnected = function() { X.conn.addHandler(onPresence, null, 'presence'); X.conn.addHandler(onProfileUpdate, Strophe.NS.VCARD_UPDATE, 'presence'); X.conn.addHandler(onGetVersion, Strophe.NS.VERSION, 'iq', 'get'); X.conn.send($pres().c('priority').t('1').up().c('status').t('Online').tree()); onDisconnected = function() { return favstate.set('show', 'offline'); var i, len, node, ref, str; if (el.childNodes.length === 0 && el.nodeType === Strophe.ElementType.TEXT) { for (i = 0, len = ref.length; i < len; i++) { if (node.nodeType === Strophe.ElementType.TEXT) { getVersion = function() { id: X.conn.getUniqueId('version'), xmlns: Strophe.NS.VERSION okcb = function(stanza) { var delay, name, os, stamp, 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 = delay ? new Date(delay.getAttribute('stamp')) : new Date(); id: stanza.getAttribute('id'), type: stanza.getAttribute('type'), from: stanza.getAttribute('from'), text: "connected to " + name + " " + version + " on " + os failcb = function(stanza) { return console.error("couldn't get version", stanza != null ? stanza.innerHTML : void 0); return X.conn.sendIQ(iq.tree(), okcb, failcb, 5000); onGetVersion = function(stanza) { id = stanza.getAttribute('id'); from = stanza.getAttribute('from'); xmlns: Strophe.NS.VERSION }).c('name').t(Tram.info.client).up().c('version').t(Tram.info.version); getContact = function(from) { contact = contacts.get(from); self = from === X.conn.jid; contacts.each(function(model) { return model.set('type', 'contact'); bjid: Strophe.getBareJidFromJid(from), type: self ? 'self' : 'contact' getContactProfile(contact); getContactProfile = function(contact) { okcb = function(stanza) { vcard = stanza.getElementsByTagName('vCard')[0]; console.warn("no vcard in response", stanza); nickname: getText(vcard.querySelector('NICKNAME')), fullname: getText(vcard.querySelector('FN')), firstname: getText(vcard.querySelector('N > GIVEN')), lastname: getText(vcard.querySelector('N > FAMILY')) mime = getText(vcard.querySelector('PHOTO > TYPE')); data = getText(vcard.querySelector('PHOTO > BINVAL')); return contact.set('avatar', { return contact.unset('avatar'); failcb = function(stanza) { return console.warn("couldn't get vcard", stanza); bjid = contact.get('bjid'); if (bjid === Strophe.getBareJidFromJid(X.conn.jid)) { return X.conn.vcard.get(okcb, bjid, failcb); onPresence = function(stanza) { var contact, delay, from, priority, ref, show, stamp, status, type; type = (ref = stanza.getAttribute('type')) != null ? ref : 'available'; console.warn("not handling <presence type=\"" + type + "\">", stanza); console.error('got <presence type="error">', stanza); from = stanza.getAttribute('from'); contact = getContact(from); show = getText(stanza.getElementsByTagName('show')[0]); status = getText(stanza.getElementsByTagName('status')[0]); priority = getText(stanza.getElementsByTagName('priority')[0]); if ((type === 'available' || type === 'unavailable') && contact.get('type') !== 'self') { delay = stanza.getElementsByTagName('delay')[0]; stamp = delay != null ? new Date(delay.getAttribute('stamp')) : new Date(); id: stanza.getAttribute('id'), text: status != null ? status : "is now " + show onProfileUpdate = function(stanza) { from = stanza.getAttribute('from'); contact = getContact(from); getContactProfile(contact); window.X = new Tram.XMPPInterface(); X.on('connecting', function() { return $('[data-msg^="a/"]').addClass('uk-hidden'); X.on('authfail', function() { return $('[data-msg="a/fail"]').removeClass('uk-hidden'); X.on('disconnected', function() { $('[data-step="login"]').removeClass('uk-hidden'); $('[data-step="main"]').addClass('uk-hidden'); X.on('connected attached', function() { $('[data-step="login"]').addClass('uk-hidden'); $('[data-step="main"]').removeClass('uk-hidden'); $('button[data-disconnect]').on('click', function() { return X.disconnect('Logged out'); $(window).on('beforeunload unload', function() { return X.disconnect('Window closed'); $form = $('[data-form="connect"]'); $form.find('input').on('keydown', function(e) { if ((!this.required || this.value !== '') && e.keyCode === 13) { index = $form.find('input').index(this); $next = $form.find('input').eq(index + 1); if ($next.length !== 0) { return $form.find('button').trigger('click'); $form.find('button').on('click', function(e) { Tram.validation.unsetError($('#username, #password')); ok &= Tram.validation.validateRequired($('#username'), true); ok &= Tram.validation.validateRequired($('#password')); return X.connect($('#username').val().trim(), $('#password').val()); window.setInterval(function() { return $('time[datetime]').each(function() { return $this.text(moment($this.attr('datetime')).fromNow()); //# sourceMappingURL=index.js.map