diff --git a/bi/core.js b/bi/core.js index b50973e43..219e5e21e 100644 --- a/bi/core.js +++ b/bi/core.js @@ -4904,7 +4904,41 @@ BI.Widget = BI.inherit(BI.OB, { }, _change: function (child) { - this.set(this._map(child)); + var self = this; + var childMap = this._map(child); + //this.set(childMap); + var changes = []; + var changing = this._changing; + var changed; + var options = {}; + this._changing = true; + if (!changing) { + this._previousAttributes = _.clone(this.attributes); + this.changed = {}; + } + var current = this.attributes, prev = this._previousAttributes, val; + for (var attr in childMap) { + val = childMap[attr]; + changes.push(attr); + this.changed[attr] = val; + current[attr] = val; + } + if (changes.length) this._pending = options; + for (var i = 0, length = changes.length; i < length; i++) { + this.trigger('change:' + changes[i], this, current[changes[i]], options); + } + if (changing) return this; + changed = BI.clone(this.changed); + while (this._pending) { + options = this._pending; + this._pending = false; + this.trigger('change', changed, prev, this, options); + } + this._pending = false; + this._changing = false; + if (changes.length) { + this.trigger("changed", changed, prev, this, options); + } return this; }, diff --git a/docs/core.js b/docs/core.js index 1a49400a5..1c727cb83 100644 --- a/docs/core.js +++ b/docs/core.js @@ -14900,7 +14900,41 @@ BI.Widget = BI.inherit(BI.OB, { }, _change: function (child) { - this.set(this._map(child)); + var self = this; + var childMap = this._map(child); + //this.set(childMap); + var changes = []; + var changing = this._changing; + var changed; + var options = {}; + this._changing = true; + if (!changing) { + this._previousAttributes = _.clone(this.attributes); + this.changed = {}; + } + var current = this.attributes, prev = this._previousAttributes, val; + for (var attr in childMap) { + val = childMap[attr]; + changes.push(attr); + this.changed[attr] = val; + current[attr] = val; + } + if (changes.length) this._pending = options; + for (var i = 0, length = changes.length; i < length; i++) { + this.trigger('change:' + changes[i], this, current[changes[i]], options); + } + if (changing) return this; + changed = BI.clone(this.changed); + while (this._pending) { + options = this._pending; + this._pending = false; + this.trigger('change', changed, prev, this, options); + } + this._pending = false; + this._changing = false; + if (changes.length) { + this.trigger("changed", changed, prev, this, options); + } return this; }, diff --git a/src/core/model.js b/src/core/model.js index fa7b2613b..f050d0d36 100644 --- a/src/core/model.js +++ b/src/core/model.js @@ -117,7 +117,41 @@ BI.Model = BI.inherit(BI.M, { }, _change: function (child) { - this.set(this._map(child)); + var self = this; + var childMap = this._map(child); + //this.set(childMap); + var changes = []; + var changing = this._changing; + var changed; + var options = {}; + this._changing = true; + if (!changing) { + this._previousAttributes = _.clone(this.attributes); + this.changed = {}; + } + var current = this.attributes, prev = this._previousAttributes, val; + for (var attr in childMap) { + val = childMap[attr]; + changes.push(attr); + this.changed[attr] = val; + current[attr] = val; + } + if (changes.length) this._pending = options; + for (var i = 0, length = changes.length; i < length; i++) { + this.trigger('change:' + changes[i], this, current[changes[i]], options); + } + if (changing) return this; + changed = BI.clone(this.changed); + while (this._pending) { + options = this._pending; + this._pending = false; + this.trigger('change', changed, prev, this, options); + } + this._pending = false; + this._changing = false; + if (changes.length) { + this.trigger("changed", changed, prev, this, options); + } return this; },