Skip to content

Instantly share code, notes, and snippets.

@mikehenriquezf
Created September 10, 2012 18:25
Show Gist options
  • Save mikehenriquezf/3692731 to your computer and use it in GitHub Desktop.
Save mikehenriquezf/3692731 to your computer and use it in GitHub Desktop.
View = require './view'
Application = require '../application'
module.exports = class PromoPostView extends View
className: 'promo-wrapper'
template: require "./templates/#{socialshows.device}/promo_post"
events:
'click a.promo-post-review-button': 'review'
getRenderData: ->
learn_more_context =
program: socialshows.models.AiringModel.get('program').title
website_url: socialshows.models.AiringModel.get('assets').external_show_url
learn_more_fmt = gettext 'Thanks for joining the live chat. Go <a href="%(website_url)s">here</a> to learn more about %(program)s and watch a sneak peak of next week's episode.'
buy_itunes_context =
itunes_url: socialshows.models.AiringModel.get('assets').itunes_url
buy_itunes_fmt = gettext '<a href="%(itunes_url)s" target="_blank">Buy more episodes</a> of this show on iTunes.'
website_context =
website_url: 'http://example.com'
website_fmt = gettext 'Visit <a href="%(website_url)s">%(website_url)s</a> to learn more about this show'
_.extend {}, socialshows.models.AiringModel.toJSON(), learn_more_text: interpolate(learn_more_fmt, learn_more_context, yes), buy_itunes_text: interpolate(buy_itunes_fmt, buy_itunes_context, yes), website_text: interpolate(website_fmt, website_context, yes)
review: (event) ->
event.preventDefault()
unless $(event.currentTarget).data('state') is 'disabled'
review = $(event.currentTarget).data 'review'
data = airing: socialshows.models.AiringModel.get('id'), review: review
data.didnt_watch = yes if review is 'didntwatch'
template = require "./templates/#{socialshows.device}/review_modal"
modal = socialshows.views.AppView.createModal template
setTimeout ( -> modal.close() ), 3000
$.ajax(
type: 'POST'
url: "/#{socialshows.models.AppModel.get('entrypoint').namespace}/#{socialshows.models.AiringModel.get('program').slug}/review/",
beforeSend: (xhr, settings) -> xhr.setRequestHeader 'X-CSRFToken', $('div.app').data 'csrf'
data: data
).done =>
@$el.find('a.promo-post-review-button').attr 'data-state', 'disabled'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment