2014-01-03 13:32:13 -05:00
|
|
|
View = require 'views/kinds/ModalView'
|
|
|
|
template = require 'templates/modal/wizard_settings'
|
|
|
|
WizardSprite = require 'lib/surface/WizardSprite'
|
|
|
|
ThangType = require 'models/ThangType'
|
2014-02-24 12:06:22 -05:00
|
|
|
{me} = require 'lib/auth'
|
2014-06-30 22:16:26 -04:00
|
|
|
forms = require 'lib/forms'
|
2014-07-10 14:50:16 -04:00
|
|
|
User = require 'models/User'
|
2014-01-03 13:32:13 -05:00
|
|
|
|
2014-02-24 12:46:40 -05:00
|
|
|
module.exports = class WizardSettingsModal extends View
|
2014-06-30 22:16:26 -04:00
|
|
|
id: 'wizard-settings-modal'
|
2014-01-03 13:32:13 -05:00
|
|
|
template: template
|
|
|
|
closesOnClickOutside: false
|
|
|
|
|
2014-07-10 14:50:16 -04:00
|
|
|
events:
|
|
|
|
'keyup #wizard-settings-name': -> @trigger 'nameChanged'
|
|
|
|
'click #wizard-settings-done': 'onWizardSettingsDone'
|
|
|
|
|
2014-03-23 20:18:36 -04:00
|
|
|
constructor: (options) ->
|
2014-03-23 21:55:44 -04:00
|
|
|
@onNameChange = _.debounce(@checkNameExists, 500)
|
2014-07-10 14:50:16 -04:00
|
|
|
@on 'nameChanged', @onNameChange
|
2014-03-23 20:18:36 -04:00
|
|
|
super options
|
|
|
|
|
2014-01-03 13:32:13 -05:00
|
|
|
afterRender: ->
|
2014-02-24 12:06:22 -05:00
|
|
|
WizardSettingsView = require 'views/account/wizard_settings_view'
|
|
|
|
view = new WizardSettingsView()
|
|
|
|
@insertSubView view
|
2014-04-12 01:30:28 -04:00
|
|
|
super()
|
2014-01-03 13:32:13 -05:00
|
|
|
|
2014-03-23 20:18:36 -04:00
|
|
|
checkNameExists: =>
|
2014-03-23 19:47:41 -04:00
|
|
|
forms.clearFormAlerts(@$el)
|
2014-03-23 20:18:36 -04:00
|
|
|
name = $('#wizard-settings-name').val()
|
2014-07-10 14:50:16 -04:00
|
|
|
User.getUnconflictedName name, (newName) =>
|
2014-03-23 20:18:36 -04:00
|
|
|
forms.clearFormAlerts(@$el)
|
2014-07-10 14:50:16 -04:00
|
|
|
if name isnt newName
|
|
|
|
forms.setErrorToProperty @$el, 'name', 'This name is already taken so you won\'t be able to keep it.', true
|
2014-03-23 19:47:41 -04:00
|
|
|
|
2014-04-12 01:30:28 -04:00
|
|
|
onWizardSettingsDone: ->
|
2014-03-23 13:41:15 -04:00
|
|
|
me.set('name', $('#wizard-settings-name').val())
|
2014-02-24 12:06:22 -05:00
|
|
|
forms.clearFormAlerts(@$el)
|
|
|
|
res = me.validate()
|
|
|
|
if res?
|
|
|
|
forms.applyErrorsToForm(@$el, res)
|
|
|
|
return
|
|
|
|
|
2014-06-11 16:16:17 -04:00
|
|
|
res = me.patch()
|
2014-02-24 12:06:22 -05:00
|
|
|
return unless res
|
|
|
|
save = $('#save-button', @$el).text($.i18n.t('common.saving', defaultValue: 'Saving...'))
|
2014-04-12 01:30:28 -04:00
|
|
|
.addClass('btn-info').show().removeClass('btn-danger')
|
2014-02-24 12:06:22 -05:00
|
|
|
|
|
|
|
res.error =>
|
|
|
|
errors = JSON.parse(res.responseText)
|
2014-06-30 22:16:26 -04:00
|
|
|
console.warn 'Got errors saving user:', errors
|
2014-02-24 12:06:22 -05:00
|
|
|
forms.applyErrorsToForm(@$el, errors)
|
|
|
|
@disableModalInProgress(@$el)
|
2014-03-23 18:04:39 -04:00
|
|
|
|
2014-02-24 12:46:40 -05:00
|
|
|
res.success (model, response, options) =>
|
|
|
|
@hide()
|
2014-02-24 12:06:22 -05:00
|
|
|
|
|
|
|
@enableModalInProgress(@$el)
|