Sha256: 447494fb36c0ead812a8f5425f5dd315c986e6a1a69a6d56e18cdcefd66bc12f

Contents?: true

Size: 1.75 KB

Versions: 2

Compression:

Stored size: 1.75 KB

Contents

# https://github.com/thoughtbot/hound/blob/master/app/assets/javascripts/directives/repo.js.coffee.erb
App.directive 'repo', ['Subscription', 'StripeCheckout', (Subscription, StripeCheckout) ->
  scope: true
  templateUrl: '/templates/repo'
  link: (scope, element, attributes) ->
    repo = scope.repo
    scope.processing = false

    activate = ->
      repo.$activate()
        .then(->
          scope.processing = false
        ).catch(-> alert('Your repo failed to activate.'))

    deactivate = ->
      repo.$deactivate()
        .then(-> scope.processing = false)
        .catch(-> alert('Your repo failed to deactivate.'))

    createSubscription = (stripeToken) ->
      scope.processing = true

      subscription = new Subscription(
        repo_id: repo.id
        card_token: stripeToken.id
        email_address: stripeToken.email
      )

      subscription.$save().then(->
        scope.processing = false
        repo.active = true
      , ->
        scope.processing = false
        alert('Your subscription failed.')
      )

    scope.toggle = ->
      if repo.active
        if repo.stripe_subscription_id
          scope.processing = true
          subscription = new Subscription(repo_id: repo.id)
          subscription.$delete().then(->
            repo.active = false
            scope.processing = false
          , ->
            alert('Your repo could not be disabled')
            scope.processing = false
          )
        else
          scope.processing = true
          deactivate(repo)
      else
        # if repo.private
        #   StripeCheckout.open(
        #     name: repo.full_plan_name,
        #     amount: repo.price_in_cents,
        #     createSubscription
        #   )
        # else
       scope.processing = true
       activate(repo)
]

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
hound_breeder-0.0.2 lib/generators/hound_breeder/repo.js.coffee.erb
hound_breeder-0.0.1 lib/generators/hound_breeder/repo.js.coffee.erb