Files
ember-panda/app/routes/organization.coffee
T
2017-12-21 11:51:55 +01:00

34 lines
1.4 KiB
CoffeeScript

import Ember from 'ember'
{get} = Ember
export default Ember.Route.extend
session: Ember.inject.service('session')
actions:
editOrganization: (organization)->
@modal 'organization/edit-organization',
model: organization.get('changeset')
newOrganization: ->
organization = @store.createRecord('panda/organization')
@modal 'organization/edit-organization',
model: organization.get('changeset')
title: t('action.new_model', model: t('models.organization'))
setLogo: (organization, file) ->
return unless file
base = @
session = @get('session')
#TODO implement generic request feature, this is not the way to do it! Done because it works and no time
if get(session, 'isAuthenticated')
session.authorize 'authorizer:devise', (key, authorization) ->
file.upload organization.action_url('logo'),
headers:
"#{key}": authorization
#authorization: "Token token=\"#{@get('session.session.content.authenticated.token')}\", email=\"#{@get('session.session.content.authenticated.email')}\""
.then (response) ->
organization.store.pushPayload response.body if response?.body?.data
else # assume same host authenticated rails session
file.upload(organization.action_url('logo')).then (response) ->
organization.store.pushPayload response.body if response?.body?.data
@send 'closeModal'