Redirect to level editor only after modal hidden event is triggered. Fixes .

This commit is contained in:
Tay Yang Shun 2014-03-01 01:55:30 +08:00
parent e20e9d68cf
commit 8af62d53cd

View file

@ -24,6 +24,7 @@ module.exports = class ThangTypeHomeView extends View
'click button.new-model-submit': 'makeNewModel'
'submit form': 'makeNewModel'
'shown.bs.modal #new-model-modal': 'focusOnName'
'hidden.bs.modal #new-model-modal': 'onModalHidden'
getRenderData: ->
c = super()
@ -85,16 +86,21 @@ module.exports = class ThangTypeHomeView extends View
res = model.save()
return unless res
modal = @$el.find('.modal')
modal = @$el.find('#new-model-modal')
forms.clearFormAlerts(modal)
@showLoading(modal.find('.modal-body'))
res.error =>
@hideLoading()
forms.applyErrorsToForm(modal, JSON.parse(res.responseText))
that = @
res.success ->
modal.modal('hide')
base = document.location.pathname[1..] + '/'
app.router.navigate(base + (model.get('slug') or model.id), {trigger:true})
that.model = model
modal.modal('hide')
onModalHidden: ->
# Can only redirect after the modal hidden event has triggered
base = document.location.pathname[1..] + '/'
app.router.navigate(base + (@model.get('slug') or @model.id), {trigger:true})
focusOnName: ->
@$el.find('#name').focus()