From 605bf85729b102bfa866b3016b974c6f4224ad5f Mon Sep 17 00:00:00 2001 From: Ruben Vereecken Date: Sun, 13 Jul 2014 17:39:16 +0200 Subject: [PATCH] Signup form now has an optional name field --- app/templates/modal/auth.jade | 6 ++++++ app/views/account/settings_view.coffee | 7 ++----- app/views/modal/auth_modal.coffee | 19 +++++++++++++++++++ 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/app/templates/modal/auth.jade b/app/templates/modal/auth.jade index 7edff3fff..80444f4c1 100644 --- a/app/templates/modal/auth.jade +++ b/app/templates/modal/auth.jade @@ -34,6 +34,12 @@ block modal-body-content input#password.input-large.form-control(name="password", type="password", value=formValues.password) if mode === 'signup' + .form-group + label.control-label(for="name", data-i18n="general.name") Name + if me.get('name') + input#name.input-large.form-control(name="name", type="text", value="#{me.get('name')}") + else + input#name.input-large.form-control(name="name", type="text", value="", placeholder="Anoner") .form-group.checkbox label.control-label(for="subscribe") input#subscribe(name="subscribe", type="checkbox", checked='checked') diff --git a/app/views/account/settings_view.coffee b/app/views/account/settings_view.coffee index 103c4636b..4ad6b1c2c 100644 --- a/app/views/account/settings_view.coffee +++ b/app/views/account/settings_view.coffee @@ -15,7 +15,6 @@ module.exports = class SettingsView extends View events: 'click #save-button': 'save' - #'change #settings-panes input': (e) -> @trigger 'inputChanged', e 'change #settings-panes input:checkbox': (e) -> @trigger 'checkboxToggled', e 'keyup #settings-panes input:text, #settings-panes input:password': (e) -> @trigger 'inputChanged', e 'keyup #name': 'onNameChange' @@ -38,7 +37,6 @@ module.exports = class SettingsView extends View $that = $(that) savedValue = $that.data 'saved-value' currentValue = $that.val() - console.debug savedValue, currentValue if savedValue isnt currentValue @changedFields.push that unless that in @changedFields @enableSaveButton() @@ -49,7 +47,6 @@ module.exports = class SettingsView extends View onToggle: (e) -> $that = $(e.currentTarget) $that.val $that[0].checked - console.debug $that.val() enableSaveButton: -> $('#save-button', @$el).removeClass 'disabled' @@ -62,14 +59,14 @@ module.exports = class SettingsView extends View $('#save-button', @$el).text 'No Changes' checkNameExists: => - name = $('#name').val() + name = $('#name', @$el).val() User.getUnconflictedName name, (newName) => forms.clearFormAlerts(@$el) if name is newName @suggestedName = undefined else @suggestedName = newName - forms.setErrorToProperty @$el, 'name', "This name is already taken. What about #{newName}?", true + forms.setErrorToProperty @$el, 'name', "That name is taken! How about #{newName}?", true afterRender: -> super() diff --git a/app/views/modal/auth_modal.coffee b/app/views/modal/auth_modal.coffee index 5f486281e..9d32de0ae 100644 --- a/app/views/modal/auth_modal.coffee +++ b/app/views/modal/auth_modal.coffee @@ -15,11 +15,16 @@ module.exports = class AuthModalView extends View 'click #switch-to-signup-button': 'onSignupInstead' 'click #signup-confirm-age': 'checkAge' 'submit': 'onSubmitForm' # handles both submit buttons + 'keyup #name': 'onNameChange' subscriptions: 'server-error': 'onServerError' 'logging-in-with-facebook': 'onLoggingInWithFacebook' + constructor: (options) -> + @onNameChange = _.debounce @checkNameExists, 500 + super options + getRenderData: -> c = super() c.showRequiredError = @options.showRequiredError @@ -31,6 +36,7 @@ module.exports = class AuthModalView extends View c.mode = @mode c.formValues = @previousFormInputs or {} c.onEmployersPage = Backbone.history.fragment is "employers" + c.me = me c afterInsert: -> @@ -64,6 +70,8 @@ module.exports = class AuthModalView extends View userObject = forms.formToObject @$el delete userObject.subscribe delete userObject['confirm-age'] + delete userObject.name if userObject.name is '' + userObject.name = @suggestedName if @suggestedName for key, val of me.attributes when key in ['preferredLanguage', 'testGroupNumber', 'dateCreated', 'wizardColor1', 'name', 'music', 'volume', 'emails'] userObject[key] ?= val subscribe = @$el.find('#signup-subscribe').prop('checked') @@ -82,3 +90,14 @@ module.exports = class AuthModalView extends View onServerError: (e) -> # TODO: work error handling into a separate forms system @disableModalInProgress(@$el) + + checkNameExists: => + name = $('#name', @$el).val() + return forms.clearFormAlerts(@$el) if name is '' + User.getUnconflictedName name, (newName) => + forms.clearFormAlerts(@$el) + if name is newName + @suggestedName = undefined + else + @suggestedName = newName + forms.setErrorToProperty @$el, 'name', "That name is taken! How about #{newName}?", true