MCPcopy Create free account
hub / github.com/codecombat/codecombat / onClickAnswer

Method onClickAnswer

app/views/play/modal/PollModal.js:97–150  ·  view source on GitHub ↗
(e)

Source from the content-addressed store, hash-verified

95 }
96
97 onClickAnswer (e) {
98 let left
99 const $selectedAnswer = $(e.target).closest('.answer')
100 const pollVotes = (left = this.userPollsRecord.get('polls')) != null ? left : {}
101 pollVotes[this.poll.id] = $selectedAnswer.data('answer').toString()
102 this.userPollsRecord.set('polls', pollVotes)
103 this.updateAnswers(true)
104 return this.userPollsRecord.save({ polls: pollVotes }, {
105 success: () => {
106 let left1
107 if (typeof this.awardRandomGems === 'function') {
108 this.awardRandomGems()
109 }
110 if (utils.isOzaria) { return }
111 const myAnswer = ((left1 = this.userPollsRecord.get('polls')) != null ? left1 : {})[this.poll.id]
112 const answerObj = _.find(this.poll.get('answers'), answer => answer.key === myAnswer) || {}
113 const nextPollId = answerObj.nextPoll
114
115 // The following block allows for the user to be indecisive with their answer, updating UI accordingly.
116 const btn = this.$el.find('.btn.btn-illustrated.btn-lg.done-button')
117 btn.off('click')
118
119 if (answerObj.nextURL) {
120 btn.text(i18n.t('common.next'))
121 return btn.one('click', () => {
122 btn.prop('disabled', true)
123 return window.open(answerObj.nextURL, '_blank', 'noopener,noreferrer')
124 })
125 } else if (nextPollId) {
126 btn.text(i18n.t('common.next'))
127 return btn.one('click', () => {
128 btn.prop('disabled', true)
129 if (this.poll.id === '5e84c7a519cb270028516687') {
130 // Show live Class Modal
131 return this.trigger('trigger-show-live-classes')
132 } else {
133 return this.trigger('trigger-next-poll', nextPollId)
134 }
135 })
136 } else {
137 btn.text(i18n.t('play_level.done'))
138
139 // For code quest modal
140 return btn.one('click', () => {
141 if (this.poll.id === '5f21e48ec22bdf002922cd8c') {
142 // Id of codequest poll
143 btn.prop('disabled', true)
144 return this.trigger('trigger-codequest-modal')
145 }
146 })
147 }
148 }
149 })
150 }
151
152 awardRandomGems () {
153 let left, left1, reward

Callers

nothing calls this directly

Calls 7

updateAnswersMethod · 0.95
awardRandomGemsMethod · 0.95
dataMethod · 0.80
getMethod · 0.45
setMethod · 0.45
saveMethod · 0.45
openMethod · 0.45

Tested by

no test coverage detected