MCPcopy Index your code
hub / github.com/codecombat/codecombat / save

Method save

app/models/CocoModel.js:212–270  ·  view source on GitHub ↗
(attrs, options)

Source from the content-addressed store, hash-verified

210 }
211
212 save (attrs, options) {
213 if (options == null) { options = {} }
214 const originalOptions = _.cloneDeep(options)
215 if (options.headers == null) { options.headers = {} }
216 options.headers['X-Current-Path'] = (document.location != null ? document.location.pathname : undefined) != null ? (document.location != null ? document.location.pathname : undefined) : 'unknown'
217 const {
218 success,
219 } = options
220 const {
221 error,
222 } = options
223 options.success = (model, res) => {
224 this.retries = 0
225 this.trigger('save:success', this)
226 if (success) { success(this, res) }
227 if (this._revertAttributes) { this.markToRevert() }
228 this.clearBackup()
229 CocoModel.pollAchievements()
230 options.success = (options.error = null) // So the callbacks can be garbage-collected.
231 }
232 options.error = (model, res) => {
233 let left, notyError
234 if (res.status === 0) {
235 let msg
236 if (this.retries == null) { this.retries = 0 }
237 this.retries += 1
238 if (this.retries > 20) {
239 msg = 'Your computer or our servers appear to be offline. Please try refreshing.'
240 noty({ text: msg, layout: 'center', type: 'error', killer: true })
241 return
242 } else {
243 msg = $.i18n.t('loading_error.connection_failure', { defaultValue: 'Connection failed.' })
244 try {
245 noty({ text: msg, layout: 'center', type: 'error', killer: true, timeout: 3000 })
246 } catch (error1) {
247 notyError = error1
248 console.warn("Couldn't even show noty error for", error, 'because', notyError)
249 }
250 return _.delay(() => this.save(attrs, originalOptions), 3000)
251 }
252 }
253 if (error) { error(this, res) }
254 if (!this.notyErrors) { return }
255 const errorMessage = `Error saving ${(left = this.get('name')) != null ? left : this.type()}`
256 console.log('going to log an error message')
257 console.warn(errorMessage, res.responseJSON)
258 if (!(typeof webkit !== 'undefined' && webkit !== null ? webkit.messageHandlers : undefined)) { // Don't show these notys on iPad
259 try {
260 noty({ text: `${errorMessage}: ${res.status} ${res.statusText}\n${res.responseText}`, layout: 'topCenter', type: 'error', killer: false, timeout: 10000 })
261 } catch (error2) {
262 notyError = error2
263 console.warn("Couldn't even show noty error for", error, 'because', notyError)
264 }
265 }
266 options.success = (options.error = null) // So the callbacks can be garbage-collected.
267 }
268 this.trigger('save', this)
269 return super.save(attrs, options)

Callers 15

patchMethod · 0.95
saveNewMinorVersionMethod · 0.95
saveNewMajorVersionMethod · 0.95
CocoModel.spec.jsFile · 0.45
blocklyUtils.jsFile · 0.45
setHocCampaignFunction · 0.45
setReferrerTrackingFunction · 0.45
initFunction · 0.45
onSetVolumeFunction · 0.45
trackFirstArrivalFunction · 0.45

Calls 7

markToRevertMethod · 0.95
clearBackupMethod · 0.95
getMethod · 0.95
typeMethod · 0.95
pollAchievementsMethod · 0.80
logMethod · 0.80
errorFunction · 0.50

Tested by

no test coverage detected