summaryrefslogtreecommitdiff
path: root/addons/base/static/src/js/list.js
diff options
context:
space:
mode:
authorXavier Morel <xmo@openerp.com>2011-08-19 17:15:10 +0200
committerXavier Morel <xmo@openerp.com>2011-08-19 17:15:10 +0200
commitc18eff8665d913aaf07c417543c0fb0c611a7cae (patch)
tree78cc1f350d24dcd3e8c50d1382c7264882657f60 /addons/base/static/src/js/list.js
parent2d024453a97133609a653cdc1060d65a68913f2d (diff)
[IMP] add events unbinging to events mixin, fix Collection.reload() handling by List
bzr revid: xmo@openerp.com-20110819151510-7posqx7mznldurd2
Diffstat (limited to 'addons/base/static/src/js/list.js')
-rw-r--r--addons/base/static/src/js/list.js56
1 files changed, 41 insertions, 15 deletions
diff --git a/addons/base/static/src/js/list.js b/addons/base/static/src/js/list.js
index 996822c4a21..642a0743e9a 100644
--- a/addons/base/static/src/js/list.js
+++ b/addons/base/static/src/js/list.js
@@ -629,19 +629,24 @@ openerp.base.ListView.List = openerp.base.Class.extend( /** @lends openerp.base.
this.dataset = opts.dataset;
this.records = opts.records;
- this.records.bind('remove', function (event, record) {
- var $row = self.$current.find('[data-id=' + record.get('id') + ']');
- var index = $row.data('index');
- $row.nextAll().each(function (row) {
- $(row).data('index', index++);
- });
- $row.remove();
- });
- this.records.bind('reset', $.proxy(this, 'on_records_reset'));
- this.records.bind('change', function (event, record) {
- var $row = self.$current.find('[data-id=' + record.get('id') + ']');
- $row.replaceWith(self.render_record($row.data('index')));
- });
+ this.record_callbacks = {
+ 'remove': function (event, record) {
+ var $row = self.$current.find('[data-id=' + record.get('id') + ']');
+ var index = $row.data('index');
+ $row.nextAll().each(function (row) {
+ $(row).data('index', index++);
+ });
+ $row.remove();
+ },
+ 'reset': $.proxy(this, 'on_records_reset'),
+ 'change': function (event, record) {
+ var $row = self.$current.find('[data-id=' + record.get('id') + ']');
+ $row.replaceWith(self.render_record($row.data('index')));
+ }
+ };
+ _(this.record_callbacks).each(function (callback, event) {
+ this.records.bind(event, callback);
+ }, this);
this.$_element = $('<tbody class="ui-widget-content">')
.appendTo(document.body)
@@ -729,7 +734,10 @@ openerp.base.ListView.List = openerp.base.Class.extend( /** @lends openerp.base.
/**
* Death signal, cleans up list display
*/
- on_records_reset: function (ev, records) {
+ on_records_reset: function () {
+ _(this.record_callbacks).each(function (callback, event) {
+ this.records.unbind(event, callback);
+ }, this);
if (!this.$current) { return; }
this.$current.remove();
this.$current = null;
@@ -1127,7 +1135,7 @@ openerp.base.ListView.Groups = openerp.base.Class.extend( /** @lends openerp.bas
.map(function (child) {
return child.get_records();
}).flatten().value();
- },
+ }
});
/**
@@ -1151,6 +1159,24 @@ var Events = {
return this;
},
/**
+ * @param {String} event event to unbind on the current object
+ * @param {function} [handler] specific event handler to remove (otherwise unbind all handlers for the event)
+ * @returns this
+ */
+ unbind: function (event, handler) {
+ var calls = this._callbacks || {};
+ if (!(event in calls)) { return this; }
+ if (!handler) {
+ delete calls[event];
+ } else {
+ var handlers = calls[event];
+ handlers.splice(
+ _(handlers).indexOf(handler),
+ 1);
+ }
+ return this;
+ },
+ /**
* @param {String} event
* @returns this
*/