Sha256: 6fdc11f376f29a4cf446076bc22806a28dc728ef22af01785fca7acc8dde8a74
Contents?: true
Size: 1.24 KB
Versions: 8
Compression:
Stored size: 1.24 KB
Contents
# ------------------------------------------------------------------ # # The ModelChangeMonitor watches for changes on the # # Model and remembers which attributes have been changed # # ------------------------------------------------------------------ # 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 @_unsaved = {} else this.recordChanges(record, _.keys(attrs)) reset: -> @_unsaved = {} recordChanges: (record, names) -> # console.log "Change: #{names}" # 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 changedAttributes: -> _.keys(@_unsaved) isDirty: -> !_.isEmpty(@_unsaved)
Version data entries
8 entries across 8 versions & 1 rubygems