summaryrefslogtreecommitdiff
path: root/addons/base/static/src
diff options
context:
space:
mode:
authorXavier Morel <xmo@openerp.com>2011-08-09 12:04:38 +0200
committerXavier Morel <xmo@openerp.com>2011-08-09 12:04:38 +0200
commite483027956fcbe07fef71a4edb04d96b80ebc5dc (patch)
treee3a073eb4a989738f388d5f9012fa86abbf1007c /addons/base/static/src
parent3724ff0545188d678d58647c00039fa4c0f78e5b (diff)
[IMP] simplify and cleanup handling of clicking on a given table open/close icon; split out setup in a separate method
bind the event *once* at the table toplevel instead of binding it at every sub-tree display, which mandates adding supplementary code to filter out clicks coming from the wrong height of the tree and not concerning the record(s) we're interested in bzr revid: xmo@openerp.com-20110809100438-i9546bkxydaz58ol
Diffstat (limited to 'addons/base/static/src')
-rw-r--r--addons/base/static/src/js/tree.js71
-rw-r--r--addons/base/static/src/xml/base.xml1
2 files changed, 40 insertions, 32 deletions
diff --git a/addons/base/static/src/js/tree.js b/addons/base/static/src/js/tree.js
index acb588366a1..ef4d03b34f1 100644
--- a/addons/base/static/src/js/tree.js
+++ b/addons/base/static/src/js/tree.js
@@ -18,7 +18,8 @@ openerp.base.TreeView = openerp.base.View.extend({
this.model = dataset.model;
this.view_id = view_id;
this.session = session;
- this.columns = [];
+
+ this.records = {};
this.options = _.extend({}, this.defaults, options || {});
@@ -78,6 +79,7 @@ openerp.base.TreeView = openerp.base.View.extend({
self.getdata($option.val(), $option.data('children'));
});
_(records).each(function (record) {
+ self.records[record.id] = record;
$('<option>')
.val(record.id)
.text(record.name)
@@ -87,13 +89,48 @@ openerp.base.TreeView = openerp.base.View.extend({
$select.change();
});
+ this.hook_row_click();
+ },
+ /**
+ * Sets up opening a row
+ */
+ hook_row_click: function () {
+ var self = this;
+ this.$element.delegate('.treeview-tr img', 'click', function () {
+ var is_loaded = false,
+ $this = $(this),
+ record_id = $this.data('id'),
+ record = self.records[record_id],
+ children_ids = record[self.children_field];
+
+ _(children_ids).each(function(childid) {
+ if ($('tr #treerow_' + childid).length) {
+ if ($('tr #treerow_' + childid).is(':hidden')) {
+ is_loaded = -1;
+ } else {
+ is_loaded++;
+ }
+ }
+ });
+ if (is_loaded == 0) {
+ if ($this.attr('src') == '/base/static/src/img/expand.gif') {
+ self.getdata(record_id, children_ids, true);
+ }
+ } else if (is_loaded > 0) {
+ self.showcontent(record_id, true, children_ids);
+ } else {
+ self.showcontent(record_id, false, children_ids);
+ }
+ });
},
-
// get child data of selected value
getdata: function (id, children_ids, flag) {
var self = this;
self.dataset.read_ids(children_ids, this.fields_list(), function (records) {
+ _(records).each(function (record) {
+ self.records[record.id] = record;
+ });
var is_padding, row_id;
var curr_node = $('tr #treerow_' + id);
@@ -173,36 +210,6 @@ openerp.base.TreeView = openerp.base.View.extend({
$(this).removeClass('mouse-over');
});
- self.$element.find('tr[id ^= treerow_] td').children(':first-child').click( function() {
- var is_loaded = 0,
- $this = $(this);
-
- var record_id = (this.id).split('_')[1];
- _(records).each(function (record) {
- var children_ids = record[self.children_field];
- if (record_id == record.id && children_ids.length) {
- _(children_ids).each(function(childid) {
- if ($('tr #treerow_' + childid).length) {
- if ($('tr #treerow_' + childid).is(':hidden')) {
- is_loaded = -1;
- } else {
- is_loaded++;
- }
- }
- });
- if (is_loaded == 0) {
- if ($this.attr('src') == '/base/static/src/img/expand.gif') {
- self.getdata(record_id, children_ids, true);
- }
- } else if (is_loaded > 0) {
- self.showcontent(record_id, true, children_ids);
- } else {
- self.showcontent(record_id, false, children_ids);
- }
- }
- });
- });
-
self.$element.find('tr[id ^= treerow_]').find('td').children(':last-child').click( function(e) {
row_id = $(this).parent().parent().attr('id');
var record_id = row_id.split('_')[1];
diff --git a/addons/base/static/src/xml/base.xml b/addons/base/static/src/xml/base.xml
index 82338b7b2a4..9517c8d847c 100644
--- a/addons/base/static/src/xml/base.xml
+++ b/addons/base/static/src/xml/base.xml
@@ -262,6 +262,7 @@
<td t-if="children and children.length"
class="treeview-tr">
<img t-att-id="'parentimg_' + record.id"
+ t-att-data-id="record.id"
src="/base/static/src/img/expand.gif"
width="16" height="16" border="0"/>
</td>