From 5cfc3d44a6e30fa4c2b1f2326b916a97288a4255 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Wed, 31 Dec 2014 15:35:02 +0100 Subject: [PATCH] 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. --- assets/scripts/app/routes.coffee | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/assets/scripts/app/routes.coffee b/assets/scripts/app/routes.coffee index b0e82ff5..5f9b1f1c 100644 --- a/assets/scripts/app/routes.coffee +++ b/assets/scripts/app/routes.coffee @@ -476,7 +476,7 @@ Travis.SshKeyRoute = Travis.Route.extend model: (params) -> repo = @modelFor('repo') 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 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 @@ -495,3 +495,8 @@ Travis.SshKeyRoute = Travis.Route.extend if @defaultKey controller.set('defaultKey', @defaultKey) @defaultKey = null + + deactivate: -> + @_super.apply(this, arguments) + + @controllerFor('ssh_key').send('cancel')