travis-web/app/routes/ssh-key.coffee
Piotr Sarnacki dfc22014a8 Set page titles relevant to page is loaded
I used ember-cli-document-title addon.
2015-02-17 14:35:59 +01:00

37 lines
1.1 KiB
CoffeeScript

`import Ember from 'ember'`
`import Ajax from 'travis/utils/ajax'`
`import TravisRoute from 'travis/routes/basic'`
Route = TravisRoute.extend
titleToken: 'Ssh Keys'
model: (params) ->
repo = @modelFor('repo')
self = this
@store.find('sshKey', 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
# ssh_key.new or ssh_key.no_key
return null
afterModel: (model, transition) ->
repo = @modelFor('repo')
Ajax.get "/repositories/#{repo.get('id')}/key", (data) =>
@defaultKey = Ember.Object.create(fingerprint: data.fingerprint)
setupController: (controller, model) ->
controller.reset()
@_super.apply this, arguments
if @defaultKey
controller.set('defaultKey', @defaultKey)
@defaultKey = null
deactivate: ->
@_super.apply(this, arguments)
@controllerFor('ssh_key').send('cancel')
`export default Route`