mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-28 01:55:38 -05:00
Signup form now has an optional name field
This commit is contained in:
parent
0be03aa1fe
commit
605bf85729
3 changed files with 27 additions and 5 deletions
|
@ -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')
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue