Added noty error messages when unable to save CocoModels.
This commit is contained in:
parent
8f1f378bcb
commit
8fb1237810
1 changed files with 10 additions and 4 deletions
|
@ -37,7 +37,7 @@ class CocoModel extends Backbone.Model
|
||||||
@loading = false
|
@loading = false
|
||||||
@markToRevert()
|
@markToRevert()
|
||||||
@loadFromBackup()
|
@loadFromBackup()
|
||||||
|
|
||||||
getNormalizedURL: -> "#{@urlRoot}/#{@id}"
|
getNormalizedURL: -> "#{@urlRoot}/#{@id}"
|
||||||
|
|
||||||
set: ->
|
set: ->
|
||||||
|
@ -69,11 +69,17 @@ class CocoModel extends Backbone.Model
|
||||||
@set 'editPath', document.location.pathname
|
@set 'editPath', document.location.pathname
|
||||||
options ?= {}
|
options ?= {}
|
||||||
success = options.success
|
success = options.success
|
||||||
options.success = (resp) =>
|
error = options.error
|
||||||
|
options.success = (model, res) =>
|
||||||
@trigger "save:success", @
|
@trigger "save:success", @
|
||||||
success(@, resp) if success
|
success(@, res) if success
|
||||||
@markToRevert()
|
@markToRevert()
|
||||||
@clearBackup()
|
@clearBackup()
|
||||||
|
options.error = (model, res) =>
|
||||||
|
error(@, res) if error
|
||||||
|
errorMessage = "Error saving #{@get('name') ? @type()}"
|
||||||
|
console.error errorMessage, res.responseJSON
|
||||||
|
noty text: "#{errorMessage}: #{res.status} #{res.statusText}", layout: 'topCenter', type: 'error', killer: false, timeout: 10000
|
||||||
@trigger "save", @
|
@trigger "save", @
|
||||||
return super attrs, options
|
return super attrs, options
|
||||||
|
|
||||||
|
@ -164,7 +170,7 @@ class CocoModel extends Backbone.Model
|
||||||
getDelta: ->
|
getDelta: ->
|
||||||
differ = deltasLib.makeJSONDiffer()
|
differ = deltasLib.makeJSONDiffer()
|
||||||
differ.diff @_revertAttributes, @attributes
|
differ.diff @_revertAttributes, @attributes
|
||||||
|
|
||||||
getDeltaWith: (otherModel) ->
|
getDeltaWith: (otherModel) ->
|
||||||
differ = deltasLib.makeJSONDiffer()
|
differ = deltasLib.makeJSONDiffer()
|
||||||
differ.diff @attributes, otherModel.attributes
|
differ.diff @attributes, otherModel.attributes
|
||||||
|
|
Reference in a new issue