2016-01-13 18:54:57 -05:00
|
|
|
ModalView = require 'views/core/ModalView'
|
|
|
|
template = require 'templates/editor/level/modal/artisan-guide-modal'
|
|
|
|
|
|
|
|
forms = require 'core/forms'
|
|
|
|
{sendContactMessage} = require 'core/contact'
|
|
|
|
|
|
|
|
contactSchema =
|
|
|
|
additionalProperties: false
|
|
|
|
required: ['creditName', 'levelPurpose', 'levelInspiration', 'levelLocation']
|
|
|
|
properties:
|
|
|
|
creditName:
|
|
|
|
type: 'string'
|
|
|
|
levelPurpose:
|
|
|
|
type: 'string'
|
|
|
|
levelInspiration:
|
|
|
|
type: 'string'
|
|
|
|
levelLocation:
|
|
|
|
type: 'string'
|
|
|
|
|
|
|
|
module.exports = class ArtisanGuideModal extends ModalView
|
|
|
|
id: 'artisan-guide-modal'
|
|
|
|
template: template
|
|
|
|
events:
|
|
|
|
'click #level-submit': 'levelSubmit'
|
|
|
|
|
2016-01-20 18:32:21 -05:00
|
|
|
initialize: (options) ->
|
2016-01-13 20:45:27 -05:00
|
|
|
@level = options.level
|
|
|
|
@options = level: @level.get 'name'
|
2016-01-20 18:32:21 -05:00
|
|
|
@creator = @level.get 'creator'
|
|
|
|
@meID = me.id
|
2016-01-13 18:54:57 -05:00
|
|
|
|
|
|
|
levelSubmit: ->
|
|
|
|
@playSound 'menu-button-click'
|
|
|
|
forms.clearFormAlerts @$el
|
2016-01-27 16:55:17 -05:00
|
|
|
results = forms.formToObject @$el
|
|
|
|
res = tv4.validateMultiple results, contactSchema
|
2016-01-13 18:54:57 -05:00
|
|
|
return forms.applyErrorsToForm @$el, res.errors unless res.valid
|
2016-01-27 16:55:17 -05:00
|
|
|
contactMessage = {message:"""Name: #{results.creditName}
|
|
|
|
Purpose: #{results.levelPurpose}
|
|
|
|
Inspiration: #{results.levelInspiration}
|
|
|
|
Location: #{results.levelLocation}"""}
|
2016-01-13 18:54:57 -05:00
|
|
|
@populateBrowserData contactMessage
|
|
|
|
contactMessage = _.merge contactMessage, @options
|
|
|
|
contactMessage.country = me.get('country')
|
|
|
|
sendContactMessage contactMessage, @$el
|
|
|
|
$.post "/db/user/#{me.id}/track/contact_codecombat"
|
|
|
|
|
|
|
|
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
|