Anton Shestakov <av6@dwimlabs.net>, Sun, 20 Mar 2016 23:42:22 +0800
register: autofocus on the first form field
coffee/register.coffee
Permissions: -rw-r--r--
onConnect = (status, error) -> when Strophe.Status.CONNECTING console.debug('Strophe is connecting.') when Strophe.Status.AUTHENTICATING console.debug('Strophe is authenticating.') when Strophe.Status.AUTHFAIL console.debug('Strophe failed to authenticate:', error) when Strophe.Status.ERROR console.debug('Strophe received an error:', error) when Strophe.Status.CONNFAIL console.debug('Strophe failed to connect:', error) when Strophe.Status.DISCONNECTING console.debug('Strophe is disconnecting.') when Strophe.Status.DISCONNECTED console.debug('Strophe is disconnected.') when Strophe.Status.CONNECTED console.debug('Strophe is connected.') console.info('My jid:', X.conn.jid) when Strophe.Status.REGISTER console.debug('Got registration prompt.') when Strophe.Status.REGISTERED console.debug('Registered!') when Strophe.Status.CONFLICT console.debug('Contact already exists!') when Strophe.Status.NOTACCEPTABLE console.debug('Registration form not properly filled out.') when Strophe.Status.REGIFAIL console.debug('The server does not support In-Band Registration.') window.X = new Tram.XMPPInterface() X.startRegistration(onConnect) $('[data-form="registration"], [data-form="vcard"]').each -> $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') $('[data-form="registration"] button').on 'click', -> Tram.validation.unsetError($('#username, #password1, #password2')) ok &= Tram.validation.validateRequired($('#username'), true) ok &= Tram.validation.validatePasswords($('#password1'), $('#password2')) ok &= Tram.validation.validateRequired($('#password1')) ok &= Tram.validation.validateRequired($('#password2')) X.register($('#username').val().trim(), $('#password1').val()) $('[data-form="vcard"] button').on 'click', -> file = $('#avatar').get(0).files[0] reader = new FileReader() fullname: $('#fullname').val() nickname: $('#nickname').val() reader.readAsDataURL(file) fullname: $('#fullname').val() nickname: $('#nickname').val() $('[data-step="registration"]').removeClass('uk-hidden') $('[data-step="registration"]').addClass('uk-hidden') $('[data-msg="r/closed"]').removeClass('uk-hidden') Tram.validation.setError($('#username'), 'A user with this username already exists.') $('[data-msg="r/failed"]').removeClass('uk-hidden') $('#nickname').val($('#username').val()) $('[data-step="vcard"]').removeClass('uk-hidden') $('[data-step="vcard"]').addClass('uk-hidden') $('[data-msg="v/failed"]').removeClass('uk-hidden')