codecombat/app/views/courses/InviteToClassroomModal.coffee

47 lines
1.7 KiB
CoffeeScript
Raw Normal View History

ModalView = require 'views/core/ModalView'
template = require 'templates/courses/invite-to-classroom-modal'
module.exports = class InviteToClassroomModal extends ModalView
id: 'invite-to-classroom-modal'
template: template
2015-12-04 17:11:17 -05:00
events:
'click #send-invites-btn': 'onClickSendInvitesButton'
'click #copy-url-btn, #join-url-input': 'copyURL'
initialize: (options) ->
@classroom = options.classroom
2015-12-01 16:17:21 -05:00
@classCode = @classroom.get('codeCamel') || @classroom.get('code')
@joinURL = document.location.origin + "/courses?_cc=" + @classCode
onClickSendInvitesButton: ->
emails = @$('#invite-emails-textarea').val()
emails = emails.split('\n')
emails = _.filter((_.string.trim(email) for email in emails))
if not emails.length
return
url = @classroom.url() + '/invite-members'
@$('#send-invites-btn, #invite-emails-textarea').addClass('hide')
@$('#invite-emails-sending-alert').removeClass('hide')
2015-12-04 17:11:17 -05:00
application.tracker?.trackEvent 'Classroom invite via email', category: 'Courses', classroomID: @classroom.id, emails: emails
$.ajax({
url: url
data: {emails: emails}
method: 'POST'
context: @
success: ->
@$('#invite-emails-sending-alert').addClass('hide')
@$('#invite-emails-success-alert').removeClass('hide')
})
2015-12-01 16:17:21 -05:00
copyURL: ->
2015-12-01 16:17:21 -05:00
@$('#join-url-input').val(@joinURL).select()
try
document.execCommand('copy')
@$('#copied-alert').removeClass('hide')
2015-12-04 17:11:17 -05:00
application.tracker?.trackEvent 'Classroom copy URL', category: 'Courses', classroomID: @classroom.id, url: @joinURL
2015-12-01 16:17:21 -05:00
catch err
console.log('Oops, unable to copy', err)
@$('#copy-failed-alert').removeClass('hide')