jam-cloud/web/app/assets/javascripts/react-components/InLessonBroadcast.js.jsx.co...

87 lines
3.1 KiB
CoffeeScript

context = window
@InLessonBroadcast = React.createClass({
displayName: 'In Lesson Broadcast'
getTimeRemaining: (t) ->
if t < 0
t = -t
seconds = Math.floor( (t/1000) % 60 );
minutes = Math.floor( (t/1000/60) % 60 );
hours = Math.floor( (t/(1000*60*60)) % 24 );
days = Math.floor( t/(1000*60*60*24) );
return {
'total': t,
'days': days,
'hours': hours,
'minutes': minutes,
'seconds': seconds
};
displayTime: () ->
if @props.lessonSession.initialWindow
# offset time by 10 minutes to get the 'you need to wait message' in
untilTime = @getTimeRemaining(@props.lessonSession.until.total + (10 * 60 * 1000))
else
untilTime = @props.lessonSession.until
timeString = ''
if untilTime.days != 0
timeString += "#{untilTime.days} days, "
if untilTime.hours != 0 || timeString.length > 0
timeString += "#{untilTime.hours} hours, "
if untilTime.minutes != 0 || timeString.length > 0
timeString += "#{untilTime.minutes} minutes, "
if untilTime.seconds != 0 || timeString.length > 0
timeString += "#{untilTime.seconds} seconds"
if timeString == ''
'now!'
timeString
render: () ->
if @props.lessonSession.completed
if @props.lessonSession.success
content = `<div className="message">
<p>This lesson is over.</p>
</div>`
else
content = `<div className="message">
<p>This lesson is over, but will not be billed.</p>
</div>`
else if @props.lessonSession.beforeSession
content = `<div className="message">
<p>This lesson will start in:</p>
<p className="time">{this.displayTime()}</p>
</div>`
else if @props.lessonSession.initialWindow
content = `<div className="message">
<p>You need to wait in this session for</p>
<p className="time">{this.displayTime()}</p>
<p>to allow time for your teacher to join you. If you leave before this timer reaches zero, and your teacher joins this session, you will be marked absent and charged for the lesson.</p>
</div>`
else if @props.lessonSession.teacherFault
if @props.lessonSession.teacherPresent?
content = `<div className="message">
<p>Because your teacher was late, you may now leave the session. However, if you choose to stay in the session with the teacher, after 5 minutes together the session will be considered a success, and you will be billed.</p>
<p>If the two of you do not spend at least 5 minutes together in the session, your teacher will be marked absent and penalized for missing the lesson, and you will not be charged for this lesson.</p>
</div>`
else
content = `<div className="message">
<p>You may now leave the session.</p>
<p>Your teacher will be marked absent and penalized for missing the lesson. You will not be charged for this lesson.</p>
<p>We apologize for your inconvenience, and we will work to remedy this situation.</p>
</div>`
if content?
`<div className="broadcast-notification lesson">
{content}
</div>`
else
null
})