context = window
rest = context.JK.Rest()
@JamTrackLandingPage = React.createClass({
isFree: () ->
context.JK.currentUserFreeJamTrack && @props.jam_track.allow_free
render: () ->
loggedIn = context.JK.currentUserId?
if this.state.done
ctaButtonText = 'sending you in...'
else if this.state.processing
ctaButtonText = 'hold on...'
else
if @isFree()
ctaButtonText = 'GET IT FREE!'
else
ctaButtonText = 'Add To Cart'
if @state.iOS
iosBadge = ``
register = `
Download our free iOS app now, and get this JamTrack free! See why our JamTracks are so much better than traditional backing tracks - with no risk.
`
else
if loggedIn
loggedInCtaButton = ``
if !@isFree()
loggedInPriceAdvisory = `
${this.props.jam_track.download_price}
`
else
if !@isFree()
loggedOutPriceAdvisory = `
${this.props.jam_track.download_price}
`
if this.state.loginErrors?
for key, value of this.state.loginErrors
break
errorText = context.JK.getFullFirstError(key, this.state.loginErrors, {email: 'Email', password: 'Password', 'terms_of_service' : 'The terms of service'})
register = `
Register for a free account to get this JamTrack free. We will not share your email. See our privacy policy.
by {this.props.jam_track.original_artist.toUpperCase()}
{iosBadge}
JamTracks by JamKazam are the best way to play along with your favorite songs. Far better and different than traditional
backing tracks, our JamTracks are complete multi-track professional recordings, with fully isolated tracks for each part of the music.
And our free app and Internet service are packed with features that give you unmatched creative freedom to learn, practice, record, play with others, and share your performances.
Preview JamTrack
Click the play buttons below to preview the master mix and 20-second samples of all the isolated tracks.
{loggedInCtaButton}
{loggedInPriceAdvisory}
{register}
`
getInitialState: () ->
try
iOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream;
catch e
iOS = false
{ loginErrors: null, processing:false, iOS: iOS }
privacyPolicy: (e) ->
e.preventDefault()
context.JK.popExternalLink('/corp/privacy')
termsClicked: (e) ->
e.preventDefault()
context.JK.popExternalLink('/corp/terms')
componentDidMount:() ->
$root = $(this.getDOMNode())
$checkbox = $root.find('.terms-checkbox')
#console.log("$checkbox", $checkbox)
#context.JK.checkbox($checkbox)
# add item to cart, create the user if necessary, and then place the order to get the free JamTrack.
ctaClick: (e) ->
e.preventDefault()
return if @state.processing
@setState({loginErrors: null})
loggedIn = context.JK.currentUserId?
isFree = @isFree()
rest.addJamtrackToShoppingCart({id: @props.jam_track.id, clear:true}).done((response) =>
if isFree
if loggedIn
@setState({done: true})
context.location = '/client?redeemed_flow=1#/jamtrack'
else
@createUser()
else
if loggedIn
@setState({done: true})
context.location = '/client#/shoppingCart'
else
@createUser(true)
).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'
if loggedIn
@setState({done: true})
context.location = '/client#/shoppingCart'
else
@createUser(true)
else
context.JK.app.ajaxError(jqXHR, textStatus, errorMessage)
@setState({processing:false})
)
createUser: (redirectToShoppingCart) ->
$form = $('.jamtrack-signup-form')
email = $form.find('input[name="email"]').val()
password = $form.find('input[name="password"]').val()
terms = $form.find('input[name="terms"]').is(':checked')
rest.signup({email: email, password: password, first_name: null, last_name: null, terms:terms})
.done((response) =>
if redirectToShoppingCart
@setState({done: true})
context.location = '/client#/shoppingCart'
return
rest.placeOrder()
.done((response) =>
this.setState({done: true})
context.JK.Tracking.redeemCompleteTrack()
window.location = '/client?redeemed_flow=1#/jamtrack'
)
.fail((jqXHR) =>
logger.error("unable to place an older after creating the user")
window.reload()
)
).fail((jqXHR) =>
@setState({processing:false})
if jqXHR.status == 422
response = JSON.parse(jqXHR.responseText)
if response.errors
@setState({loginErrors: response.errors})
else
context.JK.app.notify({title: 'Unknown Signup Error', text: jqXHR.responseText})
else
context.JK.app.notifyServerError(jqXHR, "Unable to Sign Up")
)
@setState({processing:true})
})