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'
|
|
|
|
forms = require('lib/forms')
|
2014-01-03 13:32:13 -05:00
|
|
|
|
2014-02-24 12:46:40 -05:00
|
|
|
module.exports = class WizardSettingsModal extends View
|
2014-01-03 13:32:13 -05:00
|
|
|
id: "wizard-settings-modal"
|
|
|
|
template: template
|
|
|
|
closesOnClickOutside: false
|
|
|
|
|
2014-03-23 20:18:36 -04:00
|
|
|
constructor: (options) ->
|
2014-03-23 21:55:44 -04:00
|
|
|
@onNameChange = _.debounce(@checkNameExists, 500)
|
2014-03-23 20:18:36 -04:00
|
|
|
super options
|
|
|
|
|
2014-01-03 13:32:13 -05:00
|
|
|
events:
|
2014-03-23 19:47:41 -04:00
|
|
|
'keyup #wizard-settings-name': 'onNameChange'
|
2014-02-24 12:06:22 -05:00
|
|
|
'click #wizard-settings-done': 'onWizardSettingsDone'
|
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()
|
|
|
|
success = (id) =>
|
|
|
|
forms.clearFormAlerts(@$el)
|
|
|
|
forms.applyErrorsToForm(@$el, {property:'name', message:'is already taken'}) if id and id isnt me.id
|
|
|
|
$.ajax("/db/user/#{name}/nameToID", {success: success})
|
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
|
|
|
|
|
|
|
|
res = me.save()
|
|
|
|
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-04-12 01:30:28 -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)
|