This repository has been archived by the owner on Oct 31, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.coffee
139 lines (118 loc) · 4.03 KB
/
script.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
DEV = location.hostname == 'catacademy.dev'
class Event
class @Header
@render: (event) ->
progress = (event.seats.taken / event.seats.maximum) * 100
console.log event
reward = event.rewards[0]
"""
<div class=event-header
id="#{event.slug}"
style="background-color: #{event.color}">
<span class=tag
style="color: #{event.color}">
#{event.tags.join(' + ')}
</span>
<hr/>
<div class=dates>#{event.dates}</div>
<h1>#{event.name}</h1>
<div class=progress-bar>
<div class=seats-available>
<div class=value>
#{event.seats.available}/#{event.seats.maximum}
</div>
Seats available
</div>
<div class=seat-goal>
<div class=value>
#{event.seats.minimum}
</div>
Seat goal
</div>
<div class=bar>
<div class=progress style="width: #{progress}%"></div>
</div>
<p><a class=buy href='#'>Buy #{reward.name}</a><br/>
#{reward.price.pretty}</p>
</div>
</div>
"""
class @Card
@render: (event) ->
color = if event.is_over then 'grey' else event.color
"""
<div class=event-card style="background-color: #{color}">
<span class=tag
style="color: #{color}">
#{event.tags.join(' + ')}
</span>
<div class=dates>#{event.dates}</div>
<h1 class=name>#{event.name}</h1>
#{@render_link event}
</div>
"""
@render_link: (event) ->
if event.is_over
"""<span class=action>Event is over</span>"""
else
"""<a class=action href="##{event.slug}">Learn more</a>"""
class API
@url: 'https://catacademy-test.herokuapp.com'
@get_root: (callback) ->
console.log @url
$.getJSON(@url).done callback
@post_pledge: (reward_id, token, callback) ->
url = "#{@url}/rewards/#{reward_id}/pledges"
$.ajax(url, {
type: 'POST',
contentType: 'application/json',
data: JSON.stringify(token),
}).done callback
class Checkout
@create: (key, callback) ->
StripeCheckout.configure
key: key
image: if DEV then null else 'images/checkout-logo.png'
token: callback
render = () ->
API.get_root ({events, stripe}) ->
$('.event-card-list').empty()
events.map (event) ->
reward = event.rewards[0]
$('.event-card-list').append(Event.Card.render(event))
if not event.is_over
id = '#' + event.slug
$(id)[0].innerHTML = Event.Header.render(event)
$(id).hide().fadeIn('slow')
checkout = Checkout.create stripe.publishable_key, (token) ->
API.post_pledge reward.id, token, () ->
alert """Thanks joining the event. Confirmation email will be sent \
shortly to #{token.email}"""
render()
console.log 'map'
$(id + ' .buy').on 'click', (e) ->
console.log('buy')
checkout.open
name: 'Cat Academy'
description: "Pledge for course: #{event.name}"
amount: reward.price.amount * 100
currency: 'dkk'
panelLabel: 'Pledge {{amount}}'
allowRememberMe: false
e.preventDefault()
render()
$('a[href^="#"]').on 'click', (event) ->
target = $($(this).attr('href'))
if target.length
event.preventDefault()
$('html, body').animate {scrollTop: target.offset().top}, 500, ->
target.focus()
$('.newsletter form').on 'submit', (e) ->
e.preventDefault()
url = 'https://robocat-newsletters.herokuapp.com/signup'
post_data = {email: $('input.email').val(), list: 'cat-academy'}
$.post url, post_data, ({status, message}, _status, _xhr) ->
$('input.email').attr('disabled', 'disabled')
$('input.email').val('Thank you.')
$('input.subscribe').attr('disabled', 'disabled').css('opacity', 0)
$('.tweet').fadeIn('slow')