diff options
| author | Xavier Morel <xmo@openerp.com> | 2012-07-10 15:12:05 +0200 |
|---|---|---|
| committer | Xavier Morel <xmo@openerp.com> | 2012-07-10 15:12:05 +0200 |
| commit | 5b6df7ebebbc80c83ed094388f7b85459dae8668 (patch) | |
| tree | 4a6a8c2e4d447b7510ef40dadc62cfce73e21110 /addons/web/static/src | |
| parent | 079e90afbbe657d8c6c746a5911e27446302facd (diff) | |
[ADD] Collection#pred as well, while we're at it
bzr revid: xmo@openerp.com-20120710131205-voi1nc5rkvewjr2f
Diffstat (limited to 'addons/web/static/src')
| -rw-r--r-- | addons/web/static/src/js/view_list.js | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/addons/web/static/src/js/view_list.js b/addons/web/static/src/js/view_list.js index 2d1a06173cd..27b39a40b22 100644 --- a/addons/web/static/src/js/view_list.js +++ b/addons/web/static/src/js/view_list.js @@ -1931,7 +1931,7 @@ var Collection = instance.web.Class.extend(/** @lends Collection# */{ var result; for(var section in this._proxies) { if (!this._proxies.hasOwnProperty(section)) { - continue + continue; } if ((result = this._proxies[section].succ(record, options))) { return result; @@ -1944,6 +1944,27 @@ var Collection = instance.web.Class.extend(/** @lends Collection# */{ return this.at(0); } return this.at(next_index); + }, + pred: function (record, options) { + options = options || {wraparound: false}; + + var result; + for (var section in this._proxies) { + if (!this._proxies.hasOwnProperty(section)) { + continue; + } + if ((result = this._proxies[section].pred(record, options))) { + return result; + } + } + + var index = this.indexOf(record); + if (index === -1) { return null; } + var next_index = index - 1; + if (options.wraparound && (next_index === -1)) { + return this.at(this.length - 1); + } + return this.at(next_index); } }); Collection.include(Events); |
