mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2025-03-14 07:00:01 -04:00
Refactor AccountSettingsView to use new event callback naming guideline
See: https://github.com/codecombat/codecombat/wiki/Events,-subscriptions,-shortcuts#events
This commit is contained in:
parent
1ff97243ad
commit
cef4fc0794
2 changed files with 17 additions and 18 deletions
|
@ -15,7 +15,7 @@ else
|
|||
- var godmode = me.get('permissions', true).indexOf('godmode') != -1;
|
||||
.form-group
|
||||
label.control-label(for="name", data-i18n="general.name") Name
|
||||
input#name.form-control(name="name", type="text", value="#{name}")
|
||||
input#name-input.form-control(name="name", type="text", value="#{name}")
|
||||
.form-group
|
||||
label.control-label(for="email", data-i18n="general.email") Email
|
||||
input#email.form-control(name="email", type="text", value="#{email}")
|
||||
|
@ -31,7 +31,7 @@ else
|
|||
.panel.panel-default
|
||||
.panel-heading
|
||||
.panel-title(data-i18n="account_settings.picture_tab")
|
||||
.panel-body
|
||||
#profile-photo-panel-body.panel-body
|
||||
img.profile-photo(src=me.getPhotoURL(230), draggable="false")
|
||||
input#photoURL(type="hidden", value=me.get('photoURL')||'')
|
||||
button#upload-photo-button.btn.form-control.btn-primary(data-i18n="account_settings.upload_picture")
|
||||
|
@ -59,7 +59,7 @@ else
|
|||
.form-group
|
||||
label.control-label(for="password1", data-i18n="account_settings.type_in_password")
|
||||
input#password1.form-control(name="password1", type="password")
|
||||
button#delete-account-button.btn.form-control.btn-primary(data-i18n="account_settings.delete_this_account")
|
||||
button#delete-account-btn.btn.form-control.btn-primary(data-i18n="account_settings.delete_this_account")
|
||||
|
||||
.col-md-6
|
||||
|
||||
|
@ -159,6 +159,6 @@ else
|
|||
input#email_ambassadorNews(name="email_ambassadorNews", type="checkbox", checked=subs.ambassadorNews)
|
||||
span(data-i18n="contribute.ambassador_subscribe_desc").help-block Get emails on support updates and multiplayer developments.
|
||||
|
||||
button#toggle-all-button.btn.btn-primary.form-control(data-i18n="account_settings.email_toggle") Toggle All
|
||||
button#toggle-all-btn.btn.btn-primary.form-control(data-i18n="account_settings.email_toggle") Toggle All
|
||||
|
||||
.clearfix
|
||||
|
|
|
@ -13,12 +13,11 @@ module.exports = class AccountSettingsView extends CocoView
|
|||
className: 'countainer-fluid'
|
||||
|
||||
events:
|
||||
'change .panel input': 'onInputChanged'
|
||||
'change #name': 'checkNameExists'
|
||||
'click #toggle-all-button': 'toggleEmailSubscriptions'
|
||||
'click .profile-photo': 'onEditProfilePhoto'
|
||||
'click #upload-photo-button': 'onEditProfilePhoto'
|
||||
'click #delete-account-button': 'confirmAccountDeletion'
|
||||
'change .panel input': 'onChangePanelInput'
|
||||
'change #name-input': 'onChangeNameInput'
|
||||
'click #toggle-all-btn': 'onClickToggleAllButton'
|
||||
'click #profile-photo-panel-body': 'onClickProfilePhotoPanelBody'
|
||||
'click #delete-account-btn': 'onClickDeleteAccountButton'
|
||||
|
||||
constructor: (options) ->
|
||||
super options
|
||||
|
@ -38,20 +37,20 @@ module.exports = class AccountSettingsView extends CocoView
|
|||
|
||||
|
||||
#- Form input callbacks
|
||||
onInputChanged: (e) ->
|
||||
onChangePanelInput: (e) ->
|
||||
$(e.target).addClass 'changed'
|
||||
if (JSON.stringify(document.getElementById('email1').className)).indexOf("changed") > -1 or (JSON.stringify(document.getElementById('password1').className)).indexOf("changed") > -1
|
||||
$(e.target).removeClass 'changed'
|
||||
else
|
||||
@trigger 'input-changed'
|
||||
|
||||
toggleEmailSubscriptions: =>
|
||||
onClickToggleAllButton: ->
|
||||
subs = @getSubscriptions()
|
||||
$('#email-panel input[type="checkbox"]', @$el).prop('checked', not _.any(_.values(subs))).addClass('changed')
|
||||
@trigger 'input-changed'
|
||||
|
||||
checkNameExists: =>
|
||||
name = $('#name', @$el).val()
|
||||
onChangeNameInput: ->
|
||||
name = $('#name-input', @$el).val()
|
||||
return if name is me.get 'name'
|
||||
User.getUnconflictedName name, (newName) =>
|
||||
forms.clearFormAlerts(@$el)
|
||||
|
@ -67,7 +66,7 @@ module.exports = class AccountSettingsView extends CocoView
|
|||
|
||||
|
||||
#- Just copied from OptionsView, TODO refactor
|
||||
confirmAccountDeletion: ->
|
||||
onClickDeleteAccountButton: ->
|
||||
forms.clearFormAlerts(@$el)
|
||||
myEmail = me.get 'email'
|
||||
email1 = document.getElementById('email1').value
|
||||
|
@ -141,7 +140,7 @@ module.exports = class AccountSettingsView extends CocoView
|
|||
layout: 'topCenter'
|
||||
url: "/db/user/#{myID}"
|
||||
|
||||
onEditProfilePhoto: (e) ->
|
||||
onClickProfilePhotoPanelBody: (e) ->
|
||||
return if window.application.isIPadApp # TODO: have an iPad-native way of uploading a photo, since we don't want to load FilePicker on iPad (memory)
|
||||
photoContainer = @$el.find('.profile-photo')
|
||||
onSaving = =>
|
||||
|
@ -229,8 +228,8 @@ module.exports = class AccountSettingsView extends CocoView
|
|||
$('.nano').nanoScroller({scrollTo: @$el.find('.has-error')})
|
||||
|
||||
grabOtherData: ->
|
||||
@$el.find('#name').val @suggestedName if @suggestedName
|
||||
me.set 'name', @$el.find('#name').val()
|
||||
@$el.find('#name-input').val @suggestedName if @suggestedName
|
||||
me.set 'name', @$el.find('#name-input').val()
|
||||
me.set 'email', @$el.find('#email').val()
|
||||
for emailName, enabled of @getSubscriptions()
|
||||
me.setEmailSubscription emailName, enabled
|
||||
|
|
Loading…
Reference in a new issue