Fix ssh key form when returning after form was open

When user opens ssh key form, navigates to a different rote and returns, ssh key
form shows that a custom key is added, but it's just a leftover from the
previous open of the form. It seems that Ember Model caches the new model in
the store and returns it from fetch. The fix is to return null in such case.
This commit is contained in:
Piotr Sarnacki 2014-12-31 15:35:02 +01:00
parent 04e97aa9ab
commit 5cfc3d44a6

View File

@ -476,7 +476,7 @@ Travis.SshKeyRoute = Travis.Route.extend
model: (params) -> model: (params) ->
repo = @modelFor('repo') repo = @modelFor('repo')
self = this self = this
Travis.SshKey.fetch(repo.get('id')).then ( (result) -> result ), (xhr) -> Travis.SshKey.fetch(repo.get('id')).then ( (result) -> result unless result.get('isNew') ), (xhr) ->
if xhr.status == 404 if xhr.status == 404
# if there is no model, just return null. I'm not sure if this is the # if there is no model, just return null. I'm not sure if this is the
# best answer, maybe we should just redirect to different route, like # best answer, maybe we should just redirect to different route, like
@ -495,3 +495,8 @@ Travis.SshKeyRoute = Travis.Route.extend
if @defaultKey if @defaultKey
controller.set('defaultKey', @defaultKey) controller.set('defaultKey', @defaultKey)
@defaultKey = null @defaultKey = null
deactivate: ->
@_super.apply(this, arguments)
@controllerFor('ssh_key').send('cancel')