context = window
rest = context.JK.Rest()
@JamTrackCta = React.createClass({
redeem: (e) ->
e.preventDefault()
return if @state.processing
isFree = context.JK.currentUserFreeJamTrack
rest.addJamtrackToShoppingCart({id: @props.jam_track.id}).done((response) =>
if(isFree)
if context.JK.currentUserId?
context.JK.currentUserFreeJamTrack = true # make sure the user sees no more free notices
context.location = '/client#/redeemComplete'
else
# now make a rest call to buy it
context.location = '/client#/redeemSignup'
else
context.location = '/client#/shoppingCart'
).fail((jqXHR, textStatus, errorMessage) =>
if jqXHR.status == 422
errors = JSON.parse(jqXHR.responseText)
cart_errors = errors?.errors?.cart_id
if cart_errors?.length == 1 && cart_errors[0] == 'has already been taken'
context.location = '/client#/shoppingCart'
else
context.JK.app.ajaxError(jqXHR, textStatus, errorMessage)
@setState({processing:false})
)
@setState({processing:true})
getInitialState:() ->
{processing: false}
render: () ->
isFree = context.JK.currentUserFreeJamTrack
if isFree
img =`
`
else
img =`
`
if @props.instrument?
getFreeText = "Get \"#{this.props.jam_track.name}\" JamTrack Free Now"
instrumentBrowseUrl = "/client?instrument=#{this.props.instrument_id}#/jamtrack/filter"
`