[FIX] sorting list views
lp bug: https://launchpad.net/bugs/809309 fixed bzr revid: xmo@openerp.com-20110713103725-y9fnpp36z78bjbhn
This commit is contained in:
parent
9e0738b97d
commit
d1209c847b
|
@ -531,13 +531,13 @@ class DataSet(openerpweb.Controller):
|
|||
class DataGroup(openerpweb.Controller):
|
||||
_cp_path = "/base/group"
|
||||
@openerpweb.jsonrequest
|
||||
def read(self, request, model, fields, group_by_fields, domain=None):
|
||||
def read(self, request, model, fields, group_by_fields, domain=None, sort=None):
|
||||
Model = request.session.model(model)
|
||||
context, domain = eval_context_and_domain(request.session, request.context, domain)
|
||||
|
||||
return Model.read_group(
|
||||
domain or [], fields, group_by_fields, 0, False,
|
||||
dict(context, group_by=group_by_fields))
|
||||
dict(context, group_by=group_by_fields), sort or False)
|
||||
|
||||
class View(openerpweb.Controller):
|
||||
_cp_path = "/base/view"
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -209,7 +209,7 @@ openerp.base.ListView = openerp.base.View.extend( /** @lends openerp.base.ListVi
|
|||
self.dataset.sort($(this).data('id'));
|
||||
|
||||
// TODO: should only reload content (and set the right column to a sorted display state)
|
||||
self.reload_view();
|
||||
self.reload_content();
|
||||
});
|
||||
|
||||
this.$element.find('.oe-list-pager')
|
||||
|
@ -449,6 +449,7 @@ openerp.base.ListView = openerp.base.View.extend( /** @lends openerp.base.ListVi
|
|||
this.session, this.model,
|
||||
results.domain, results.context,
|
||||
results.group_by);
|
||||
this.groups.datagroup.sort = this.dataset._sort;
|
||||
|
||||
if (_.isEmpty(results.group_by) && !results.context['group_by_no_leaf']) {
|
||||
results.group_by = null;
|
||||
|
|
Loading…
Reference in New Issue