From 2d3afa5e19ac8df2237ae8b8769e5e2b513637de Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Thu, 7 Apr 2011 08:07:20 +0200 Subject: [PATCH] [ADD] view switching when clicking on a list item bzr revid: xmo@openerp.com-20110407060720-2ro8mm2dixi6u6pw --- addons/base/static/src/js/list.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/addons/base/static/src/js/list.js b/addons/base/static/src/js/list.js index e4ae1abb464..b99db1241f9 100644 --- a/addons/base/static/src/js/list.js +++ b/addons/base/static/src/js/list.js @@ -30,6 +30,8 @@ openerp.base.ListView = openerp.base.Controller.extend({ }).value(); this.$element.html(QWeb.render("ListView", this)); + this.$element.find('table').delegate( + 'tr', 'click', this.on_select_row); // sidebar stuff if (this.view_manager.sidebar) @@ -39,9 +41,28 @@ openerp.base.ListView = openerp.base.Controller.extend({ this.rows = records; var table = this.$element.find('table'); + // remove all data lines + table.find('tr:first').nextAll().remove(); + // add new content table.append(QWeb.render("ListView.rows", { columns: this.columns, rows: this.rows})); }, + on_select_row: function (event) { + // count number of preceding siblings to line clicked, that's the one + // we want (note: line 0 is title row, so remove 1 for actual row + // index) + var row = this.rows[$(event.currentTarget).prevAll().length - 1]; + + var index = _.indexOf(this.dataset.ids, row.id); + if (index == undefined || index === -1) { + return; + } + this.dataset.index = index; + _.delay(_.bind(function () { + this.view_manager.on_mode_switch('form'); + }, this)); + + }, do_show: function () { // TODO: re-trigger search this.$element.show();