openfoodfoundation/openfoodnetwork

View on GitHub
app/assets/javascripts/darkswarm/services/enterprise_image_service.js.coffee

Summary

Maintainability
Test Coverage
angular.module('Darkswarm').factory "EnterpriseImageService", (FileUploader, spreeApiKey) ->
  new class EnterpriseImageService
    imageSrc: null

    imageUploader: new FileUploader
      headers:
        'X-Spree-Token': spreeApiKey
      autoUpload: true

    configure: (enterprise) =>
      @imageUploader.url = "/api/v0/enterprises/#{enterprise.id}/update_image"
      @imageUploader.onSuccessItem = (image, response) => @imageSrc = response