2014-11-28 20:49:41 -05:00
|
|
|
ModalView = require 'views/core/ModalView'
|
2014-11-29 14:39:37 -05:00
|
|
|
template = require 'templates/core/contact'
|
2014-01-03 13:32:13 -05:00
|
|
|
|
2014-11-28 20:49:41 -05:00
|
|
|
forms = require 'core/forms'
|
|
|
|
{sendContactMessage} = require 'core/contact'
|
2014-01-03 13:32:13 -05:00
|
|
|
|
|
|
|
contactSchema =
|
|
|
|
additionalProperties: false
|
2014-04-10 17:59:32 -04:00
|
|
|
required: ['email', 'message']
|
2014-01-03 13:32:13 -05:00
|
|
|
properties:
|
|
|
|
email:
|
|
|
|
type: 'string'
|
|
|
|
maxLength: 100
|
|
|
|
minLength: 1
|
|
|
|
format: 'email'
|
|
|
|
|
|
|
|
message:
|
|
|
|
type: 'string'
|
|
|
|
minLength: 1
|
|
|
|
|
2014-07-23 10:02:45 -04:00
|
|
|
module.exports = class ContactModal extends ModalView
|
2014-06-30 22:16:26 -04:00
|
|
|
id: 'contact-modal'
|
2014-01-03 13:32:13 -05:00
|
|
|
template: template
|
2014-01-10 20:32:29 -05:00
|
|
|
closeButton: true
|
2014-01-03 13:32:13 -05:00
|
|
|
|
|
|
|
events:
|
2014-06-30 22:16:26 -04:00
|
|
|
'click #contact-submit-button': 'contact'
|
2014-01-03 13:32:13 -05:00
|
|
|
|
|
|
|
contact: ->
|
2014-11-26 09:58:23 -05:00
|
|
|
@playSound 'menu-button-click'
|
2014-01-03 13:32:13 -05:00
|
|
|
forms.clearFormAlerts @$el
|
|
|
|
contactMessage = forms.formToObject @$el
|
|
|
|
res = tv4.validateMultiple contactMessage, contactSchema
|
|
|
|
return forms.applyErrorsToForm @$el, res.errors unless res.valid
|
2014-12-19 21:37:42 -05:00
|
|
|
@populateBrowserData contactMessage
|
2015-11-11 18:43:25 -05:00
|
|
|
contactMessage.country = me.get('country')
|
2014-01-03 13:32:13 -05:00
|
|
|
window.tracker?.trackEvent 'Sent Feedback', message: contactMessage
|
|
|
|
sendContactMessage contactMessage, @$el
|
2014-06-10 19:30:07 -04:00
|
|
|
$.post "/db/user/#{me.id}/track/contact_codecombat"
|
2014-12-19 21:37:42 -05:00
|
|
|
|
|
|
|
populateBrowserData: (context) ->
|
|
|
|
if $.browser
|
|
|
|
context.browser = "#{$.browser.platform} #{$.browser.name} #{$.browser.versionNumber}"
|
|
|
|
context.screenSize = "#{screen?.width ? $(window).width()} x #{screen?.height ? $(window).height()}"
|
|
|
|
context.screenshotURL = @screenshotURL
|
|
|
|
|
|
|
|
updateScreenshot: ->
|
|
|
|
return unless @screenshotURL
|
|
|
|
screenshotEl = @$el.find('#contact-screenshot').removeClass('secret')
|
|
|
|
screenshotEl.find('a').prop('href', @screenshotURL)
|
|
|
|
screenshotEl.find('img').prop('src', @screenshotURL)
|