client/lanes/models/ChangeMonitor.coffee in lanes-0.1.9.5 vs client/lanes/models/ChangeMonitor.coffee in lanes-0.3.0
- old
+ new
@@ -4,23 +4,27 @@
# ------------------------------------------------------------------ #
class Lanes.Models.ChangeMonitor
constructor: (model) ->
model.on('change', this.onChange, this)
+ @_unsaved = {}
onChange: (record, options) ->
attrs = record.changedAttributes()
return if _.isEmpty(attrs)
+ if attrs[record.idAttribute] and record.associations
+ record.associations.onIdChange(record)
if attrs.isDirty == false
- delete @_unsaved
+ @_unsaved = {}
else
- @_unsaved ||= {}
this.recordChanges(record, _.keys(attrs))
+ reset: ->
+ @_unsaved = {}
recordChanges: (record, names) ->
# console.log "Change: #{names}"
- #console.log record.getAttributes(props:true, session: true)
+ # console.log record.getAttributes(props:true, session: true)
for name in names
if name != record.idAttribute && record._definition[name] && !record._definition[name].session
record.isDirty = true
@_unsaved[ name ] = true