diff options
| author | niv-openerp <nicolas.vanhoren@openerp.com> | 2011-05-06 13:56:07 +0200 |
|---|---|---|
| committer | niv-openerp <nicolas.vanhoren@openerp.com> | 2011-05-06 13:56:07 +0200 |
| commit | c828a5e8727768d44c9ecf90e76f8f1e7108da26 (patch) | |
| tree | 7cdd02be5eac020f615b4e110183e1af80b9e548 /addons/base/static/src/js | |
| parent | ecbe0ad56b210db453886ba82ad5e79e79f6fc91 (diff) | |
| parent | 12de5a891b7a73f142c321ea2d013457470d1370 (diff) | |
[MERGE]
bzr revid: nicolas.vanhoren@openerp.com-20110506115607-c23lh5skwx5qtt82
Diffstat (limited to 'addons/base/static/src/js')
| -rw-r--r-- | addons/base/static/src/js/data.js | 33 | ||||
| -rw-r--r-- | addons/base/static/src/js/list.js | 11 |
2 files changed, 42 insertions, 2 deletions
diff --git a/addons/base/static/src/js/data.js b/addons/base/static/src/js/data.js index 107ba65e468..fbd2c6951b1 100644 --- a/addons/base/static/src/js/data.js +++ b/addons/base/static/src/js/data.js @@ -154,7 +154,7 @@ openerp.base.DataSetSearch = openerp.base.DataSet.extend({ init: function(session, model) { this._super(session, model); this.domain = []; - this.sort = []; + this._sort = []; this.offset = 0; // subset records[offset:offset+limit] // is it necessary ? @@ -176,7 +176,7 @@ openerp.base.DataSetSearch = openerp.base.DataSet.extend({ fields: fields, domain: this.domain, context: this.context, - sort: this.sort, + sort: this.sort(), offset: offset, limit: limit }, function (records) { @@ -187,6 +187,35 @@ openerp.base.DataSetSearch = openerp.base.DataSet.extend({ } callback(records); }); + }, + /** + * Reads or changes sort criteria on the dataset. + * + * If not provided with any argument, serializes the sort criteria to + * an SQL-like form usable by OpenERP's ORM. + * + * If given a field, will set that field as first sorting criteria or, + * if the field is already the first sorting criteria, will reverse it. + * + * @param {String} [field] field to sort on, reverses it (toggle from ASC to DESC) if already the main sort criteria + * @param {Boolean} [force_reverse=false] forces inserting the field as DESC + * @returns {String|undefined} + */ + 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(', '); + } + + var reverse = force_reverse || (this._sort[0] === field); + this._sort = _.without(this._sort, field, '-' + field); + + this._sort.unshift((reverse ? '-' : '') + field); + return undefined; } }); diff --git a/addons/base/static/src/js/list.js b/addons/base/static/src/js/list.js index 62abdc6f106..e7ec7eea553 100644 --- a/addons/base/static/src/js/list.js +++ b/addons/base/static/src/js/list.js @@ -123,6 +123,8 @@ openerp.base.ListView = openerp.base.Controller.extend( this.visible_columns = _.filter(this.columns, function (column) { return column.invisible !== '1'; }); + + if (!this.fields_view.sorted) { this.fields_view.sorted = {}; } this.$element.html(QWeb.render("ListView", this)); // Head hook @@ -130,6 +132,14 @@ openerp.base.ListView = openerp.base.Controller.extend( this.$element.find('#oe-list-delete') .hide() .click(this.do_delete_selected); + this.$element.find('thead').delegate('th[data-id]', 'click', function (e) { + e.stopPropagation(); + + self.dataset.sort($(this).data('id')); + + // TODO: should only reload content (and set the right column to a sorted display state) + self.do_reload(); + }); var $table = this.$element.find('table'); // Cell events @@ -319,6 +329,7 @@ openerp.base.ListView = openerp.base.Controller.extend( 'id': this.view_id, 'context': this.dataset.context, 'domain': this.dataset.domain, + 'sort': this.dataset.sort && this.dataset.sort(), 'ids': this.dataset.ids }, this.do_fill_table); }, |
