diff options
| author | Xavier Morel <xmo@openerp.com> | 2011-07-13 12:37:25 +0200 |
|---|---|---|
| committer | Xavier Morel <xmo@openerp.com> | 2011-07-13 12:37:25 +0200 |
| commit | d1209c847bdc252eef3a7627439d22c35163579f (patch) | |
| tree | a3e733d8a83a54a6e60b44eb948cc364e8c8c2a4 /addons/base/static/src/js/data.js | |
| parent | 9e0738b97dc8e28983bbfe59436181978ac87ab6 (diff) | |
[FIX] sorting list views
lp bug: https://launchpad.net/bugs/809309 fixed
bzr revid: xmo@openerp.com-20110713103725-y9fnpp36z78bjbhn
Diffstat (limited to 'addons/base/static/src/js/data.js')
| -rw-r--r-- | addons/base/static/src/js/data.js | 38 |
1 files changed, 26 insertions, 12 deletions
diff --git a/addons/base/static/src/js/data.js b/addons/base/static/src/js/data.js index a49e6cf901f..b01ceeaed5c 100644 --- a/addons/base/static/src/js/data.js +++ b/addons/base/static/src/js/data.js @@ -1,6 +1,23 @@ openerp.base.data = function(openerp) { +/** + * Serializes the sort criterion array of a dataset into a form which can be + * consumed by OpenERP's RPC APIs. + * + * @param {Array} criterion array of fields, from first to last criteria, prefixed with '-' for reverse sorting + * @returns {String} SQL-like sorting string (``ORDER BY``) clause + */ +openerp.base.serialize_sort = function (criterion) { + return _.map(criterion, + function (criteria) { + if (criteria[0] === '-') { + return criteria.slice(1) + ' DESC'; + } + return criteria + ' ASC'; + }).join(', '); +}; + openerp.base.DataGroup = openerp.base.Controller.extend( /** @lends openerp.base.DataGroup# */{ /** * Management interface between views and grouped collections of OpenERP @@ -130,7 +147,8 @@ openerp.base.ContainerDataGroup = openerp.base.DataGroup.extend( context: this.context, domain: this.domain, fields: _.uniq(this.group_by.concat(fields)), - group_by_fields: this.group_by + group_by_fields: this.group_by, + sort: openerp.base.serialize_sort(this.sort) }, function () { }).then(function (response) { var data_groups = _(response).map( _.bind(self.transform_group, self)); @@ -174,7 +192,7 @@ openerp.base.ContainerDataGroup = openerp.base.DataGroup.extend( self.session, self.model, group.__domain, child_context, child_context.group_by, self.level + 1), - group); + group, {sort: self.sort}); })); }); } @@ -197,8 +215,8 @@ openerp.base.GrouplessDataGroup = openerp.base.DataGroup.extend( }, list: function (fields, ifGroups, ifRecords) { ifRecords(_.extend( - new openerp.base.DataSetSearch(this.session, this.model), - {domain: this.domain, context: this.context})); + new openerp.base.DataSetSearch(this.session, this.model), + {domain: this.domain, context: this.context, _sort: this.sort})); } }); @@ -444,16 +462,12 @@ openerp.base.DataSetSearch = openerp.base.DataSet.extend({ */ sort: function (field, force_reverse) { if (!field) { - return _.map(this._sort, function (criteria) { - if (criteria[0] === '-') { - return criteria.slice(1) + ' DESC'; - } - return criteria + ' ASC'; - }).join(', '); + return openerp.base.serialize_sort(this._sort); } - var reverse = force_reverse || (this._sort[0] === field); - this._sort = _.without(this._sort, field, '-' + field); + this._sort.splice.apply( + this._sort, [0, this._sort.length].concat( + _.without(this._sort, field, '-' + field))); this._sort.unshift((reverse ? '-' : '') + field); return undefined; |
