Anton Shestakov <av6@dwimlabs.net>, Thu, 07 Apr 2016 22:08:18 +0800
index: handling incoming "subscribed" and "unsubscribed" presences
Currently the client can only comply with the request.
coffee/register.coffee
Permissions: -rw-r--r--
class RegistrationData extends Backbone.Model validate: (attrs, options) -> @unset('username-errors') @unset('password1-errors') @unset('password2-errors') if (attrs.username ? '').trim() is '' @set('username-errors', ['This field is required.']) if (attrs.password1 ? '') is '' @set('password1-errors', ['This field is required.']) if (attrs.password1 ? '') isnt (attrs.password2 ? '') @set('password2-errors', ['Passwords must match.']) else if (attrs.password2 ? '') is '' @set('password2-errors', ['This field is required.']) return @has('username-errors') or @has('password1-errors') or @has('password2-errors') class ProfileData extends Backbone.Model window.regData = new RegistrationData() window.vcData = new ProfileData() X.register(regData.get('username').trim(), regData.get('password1')) fullname: vcData.get('fullname').trim() nickname: vcData.get('nickname').trim() console.debug('vcard is set!', arguments) $('[data-step="vcard"]').addClass('uk-hidden') console.warn('vcard is NOT set!', arguments) $('[data-msg="save-failed"]').removeClass('uk-hidden') file = $('#avatar').get(0).files[0] reader = new FileReader() _(data).extend(avatar: reader.result) X.savevCard(data, okcb, failcb) reader.readAsDataURL(file) X.savevCard(data, okcb, failcb) window.regRivet = rivets.bind($('[data-form="registration"]'), data: regData, register: registerfn) window.vcRivet = rivets.bind($('[data-form="vcard"]'), data: vcData, save: savefn) window.X = new Tram.XMPPInterface() $('[data-step="registration"]').removeClass('uk-hidden') $('[data-step="registration"]').addClass('uk-hidden') $('[data-msg="registration-closed"]').removeClass('uk-hidden') regData.set('username-errors', ['A user with this username already exists.']) $('[data-msg="registration-failed"]').removeClass('uk-hidden') vcData.set('nickname', regData.get('username').trim()) $('[data-step="vcard"]').removeClass('uk-hidden') $('[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')