From 277aaa7d573649246f048fca4b00d4e7cd5234c7 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Wed, 18 May 2011 15:00:09 +0200 Subject: [PATCH] [FIX] events handling from inner lists Move handling of opening a group to its own method, to reduce nesting bzr revid: xmo@openerp.com-20110518130009-8mlgpg2f3i1hod4t --- addons/base/static/src/css/base.css | 4 +- addons/base/static/src/js/list.js | 68 ++++++++++++++++++----------- 2 files changed, 44 insertions(+), 28 deletions(-) diff --git a/addons/base/static/src/css/base.css b/addons/base/static/src/css/base.css index 9b3ac6ef47c..88dba9bdb1a 100644 --- a/addons/base/static/src/css/base.css +++ b/addons/base/static/src/css/base.css @@ -534,12 +534,12 @@ body.openerp { -moz-border-radius-topright: 7px; border-top-right-radius: 7px; } -.openerp .oe-listview table tbody tr:last-child th:first-child { +.openerp .oe-listview table tbody:last-child tr:last-child th:first-child { -webkit-border-bottom-left-radius: 7px; -moz-border-radius-bottomleft: 7px; border-bottom-left-radius: 7px; } -.openerp .oe-listview table tbody tr:last-child td:last-child { +.openerp .oe-listview table tbody:last-child tr:last-child td:last-child { -webkit-border-bottom-right-radius: 7px; -moz-border-radius-bottomright: 7px; border-bottom-right-radius: 7px; diff --git a/addons/base/static/src/js/list.js b/addons/base/static/src/js/list.js index bc92c4669a3..85798d2aea3 100644 --- a/addons/base/static/src/js/list.js +++ b/addons/base/static/src/js/list.js @@ -469,33 +469,38 @@ openerp.base.ListView.Groups = Class.extend( /** @lends openerp.base.ListView.Gr make_fragment: function () { return this.$element[0].ownerDocument.createDocumentFragment(); }, + open_group: function (e, group) { + var self = this, + $row = $(e.currentTarget); + group.list(function (groups) { + $row.parent()[0].insertBefore( + self.render_groups(groups), + $row[0].nextSibling); + }, function (dataset) { + // Now we need to split the current tbody in order to + // insert the list's + + // Create new tbody after current one + var $current_body = $row.closest('tbody'); + + var $next_siblings = $row.nextAll(); + if ($next_siblings.length) { + var $split = $('').insertAfter($current_body); + // Move all following siblings of current row to split + $split.append($row.nextAll()); + } + // Insert list rendering after current tbody + self.render_dataset(dataset).then(function (list) { + $current_body.after(list.$current); + }); + }); + }, render_groups: function (datagroups) { var self = this; var placeholder = this.make_fragment(); _(datagroups).each(function (group) { - var $row = $('').click(function () { - group.list(function (groups) { - $row.parent()[0].insertBefore( - self.render_groups(groups), - $row[0].nextSibling); - }, function (dataset) { - // Now we need to split the current tbody in order to - // insert the list's - - // Create new tbody after current one - var $current_body = $row.closest('tbody'); - - var $next_siblings = $row.nextAll(); - if ($next_siblings.length) { - var $split = $('').insertAfter($current_body); - // Move all following siblings of current row to split - $split.append($row.nextAll()); - } - // Insert list rendering after current tbody - self.render_dataset(dataset).then(function (list) { - $current_body.after(list.$current); - }); - }); + var $row = $('').click(function (e) { + self.open_group(e, group); }); placeholder.appendChild($row[0]); self.pad($row); @@ -516,13 +521,24 @@ openerp.base.ListView.Groups = Class.extend( /** @lends openerp.base.ListView.Gr return placeholder; }, render_dataset: function (dataset) { - var self = this; - var rows = []; - var list = new openerp.base.ListView.List({ + var self = this, + $self = $(self), + rows = [], + list = new openerp.base.ListView.List({ options: this.options, columns: this.columns, rows: rows }); + $(list).bind('selected deleted action row_link', function (e) { + // additional positional parameters are provided to trigger as an + // Array, following the event type or event object, but are + // provided to the .bind event handler as *args. + // Convert our *args back into an Array in order to trigger them + // on the group itself, so it can ultimately be forwarded wherever + // it's supposed to go. + var args = Array.prototype.slice.call(arguments, 1); + $self.trigger.call($self, e, args); + }); var d = new $.Deferred(); this.view.rpc('/base/listview/fill', {