[FIX]Fix indentation of parent-child & highlight record on hover & some minor changes
bzr revid: bth@tinyerp.com-20110614063943-fpdurf8psk518c56
This commit is contained in:
@@ -17,7 +17,7 @@ openerp.base.TreeView = openerp.base.View.extend({
|
||||
this.options = _.extend({}, this.defaults, options || {});
|
||||
this.flags = this.view_manager.action.flags;
|
||||
},
|
||||
|
||||
|
||||
start: function () {
|
||||
this._super();
|
||||
return this.rpc("/base/treeview/load", {
|
||||
@@ -30,7 +30,7 @@ openerp.base.TreeView = openerp.base.View.extend({
|
||||
on_loaded: function (data) {
|
||||
var self = this;
|
||||
this.dataset.read_slice([], 0, false, function (response) {
|
||||
self.$element.html(QWeb.render('TreeView', {'field_data':response}));
|
||||
self.$element.html(QWeb.render('TreeView', {'field_data' : response}));
|
||||
id=self.dataset.ids[0];
|
||||
self.$element.find('#parent_id').bind('change', function(){
|
||||
self.getdata($('#parent_id').val(), 0);
|
||||
@@ -44,16 +44,31 @@ openerp.base.TreeView = openerp.base.View.extend({
|
||||
var self = this;
|
||||
self.dataset.domain = [['parent_id', '=', parseInt(id, 10)]];
|
||||
self.dataset.read_slice([], 0, false, function (response) {
|
||||
if (($('tr #' + id).length) == 1){
|
||||
$('tr #' + id).find('td #parentimg').attr('src','/base/static/src/img/collapse.gif');
|
||||
|
||||
$('tr #'+id).after(QWeb.render('TreeView_Secondry', {'child_data': response}));
|
||||
if (($('tr #Treerow_' + id).length) == 1) {
|
||||
$('tr #Treerow_' + id).find('td #parentimg').attr('src','/base/static/src/img/collapse.gif');
|
||||
$('tr #Treerow_' + id).after(QWeb.render('TreeView_Secondry', {'child_data' : response}));
|
||||
parentlen = $('tr #Treerow_' + id).find('td').length;
|
||||
for (i in response) {
|
||||
if ($('tr #'+response[i].id)) {
|
||||
indent=$('tr #' + id).css('textIndent');
|
||||
ind=indent.split('px');
|
||||
j=(parseInt(ind[0],10)) + 10;
|
||||
$('tr #'+response[i].id).animate({textIndent: j});
|
||||
if ($('tr #Treerow_' + response[i].id)) {
|
||||
childlen = $('tr #Treerow_' + response[i].id).find('td').length;
|
||||
while (childlen < (parentlen + 1)) {
|
||||
$('tr #Treerow_' + response[i].id).find('td:eq(0)').before('<td></td>');
|
||||
childlen++;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (i in response) {
|
||||
if ($('tr #Treerow_' + response[i].id)) {
|
||||
childlen = $('tr #Treerow_' + response[i].id).find('td').length;
|
||||
textoftd = $('tr #Treerow_' + response[i].id).find('td:eq('+ (childlen - 1) +')').text();
|
||||
if ($('tr #Treerow_' + response[i].id).find('td:eq('+ (childlen - 2) +')').find('#parentimg').length > 0) {
|
||||
$('tr #Treerow_' + response[i].id).find('td:eq('+ (childlen - 2) +')').css({ paddingLeft : '2px' });
|
||||
} else {
|
||||
$('tr #Treerow_' + response[i].id).find('td:eq('+ (childlen - 2) +')').css({ paddingLeft : '35px' });
|
||||
}
|
||||
$('tr #Treerow_' + response[i].id).find('td:eq('+ (childlen - 2) +')').attr('colspan', '2');
|
||||
$('tr #Treerow_' + response[i].id).find('td:eq('+ (childlen - 2) +')').append(textoftd);
|
||||
$('tr #Treerow_' + response[i].id).find('td:eq('+ (childlen - 1) +')').remove();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -63,15 +78,24 @@ openerp.base.TreeView = openerp.base.View.extend({
|
||||
self.$element.append(QWeb.render('TreeView_Secondry', {'child_data': response}));
|
||||
}
|
||||
|
||||
self.$element.find('tr').mouseover( function() {
|
||||
$(this).css({ color : '#0000FF' });
|
||||
});
|
||||
self.$element.find('tr').mouseout( function() {
|
||||
$(this).css({ color : '#000000' });
|
||||
});
|
||||
|
||||
$('tr').click(function() {
|
||||
divflag = 0;
|
||||
if ($('#' + (this.id)).length == 1) {
|
||||
divflag=0;
|
||||
if ($('#'+(this.id)).length == 1) {
|
||||
rowid = (this.id).split('_');
|
||||
|
||||
for (i in response) {
|
||||
if (this.id == response[i].id) {
|
||||
if (rowid[1] == response[i].id){
|
||||
if (response[i].child_id.length > 0) {
|
||||
jQuery(response[i].child_id).each(function(e, chid) {
|
||||
if (jQuery('tr #' + chid).length > 0){
|
||||
if (jQuery('tr #' + chid).is(':hidden')) {
|
||||
jQuery(response[i].child_id).each (function(e, chid) {
|
||||
if (jQuery('tr #Treerow_' + chid).length > 0) {
|
||||
if (jQuery('tr #Treerow_' + chid).is(':hidden')) {
|
||||
divflag = -1;
|
||||
} else {
|
||||
divflag++;
|
||||
@@ -80,12 +104,12 @@ openerp.base.TreeView = openerp.base.View.extend({
|
||||
});
|
||||
if (divflag == 0) {
|
||||
if ($('#' + (this.id)).find('td #parentimg').attr('src') == '/base/static/src/img/expand.gif') {
|
||||
self.getdata(this.id);
|
||||
self.getdata(rowid[1]);
|
||||
}
|
||||
} else if (divflag > 0) {
|
||||
self.showcontent(this.id, 1, response[i].child_id);
|
||||
self.showcontent(rowid[1], 1, response[i].child_id);
|
||||
} else if (divflag == -1) {
|
||||
self.showcontent(this.id, 0, response[i].child_id);
|
||||
self.showcontent(rowid[1], 0, response[i].child_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -97,31 +121,32 @@ openerp.base.TreeView = openerp.base.View.extend({
|
||||
|
||||
// show & hide the contents
|
||||
showcontent: function (id, flag, childid) {
|
||||
var self = this;
|
||||
var self=this;
|
||||
if (flag == 1) {
|
||||
$('tr #' + id).find('td #parentimg').attr('src', '/base/static/src/img/expand.gif');
|
||||
} else {
|
||||
$('tr #' + id).find('td #parentimg').attr('src', '/base/static/src/img/collapse.gif');
|
||||
$('tr #Treerow_' + id).find('td #parentimg').attr('src', '/base/static/src/img/expand.gif');
|
||||
}
|
||||
else {
|
||||
$('tr #Treerow_' + id).find('td #parentimg').attr('src', '/base/static/src/img/collapse.gif');
|
||||
}
|
||||
|
||||
for (i in childid) {
|
||||
if (flag == 1) {
|
||||
self.dataset.domain = [['parent_id', '=', parseInt(childid[i], 10)]];
|
||||
childimg = $('tr #' + childid[i]).find('td #parentimg').attr('src');
|
||||
childimg = $('tr #Treerow_ '+ childid[i]).find('td #parentimg').attr('src');
|
||||
if (childimg == "/base/static/src/img/collapse.gif") {
|
||||
$('tr #' + childid[i]).find('td #parentimg').attr('src', '/base/static/src/img/expand.gif');
|
||||
$('tr #Treerow_'+childid[i]).find('td #parentimg').attr('src','/base/static/src/img/expand.gif');
|
||||
}
|
||||
self.dataset.read_slice([], 0, false, function (response) {
|
||||
for (j in response){
|
||||
if (jQuery('tr #' + response[j].id).length > 0) {
|
||||
jQuery('tr #' + response[j].id).hide();
|
||||
for (j in response) {
|
||||
if (jQuery('tr #Treerow_' + response[j].id).length > 0) {
|
||||
jQuery('tr #Treerow_' + response[j].id).hide();
|
||||
}
|
||||
}
|
||||
});
|
||||
jQuery ('tr #' + childid[i]).hide();
|
||||
jQuery ('tr #Treerow_' + childid[i]).hide();
|
||||
}
|
||||
else {
|
||||
jQuery ('tr #' + childid[i]).show();
|
||||
jQuery ('tr #Treerow_' + childid[i]).show();
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -239,15 +239,22 @@
|
||||
</t>
|
||||
<t t-name="TreeView_Secondry">
|
||||
<t t-foreach="child_data" t-as="field" >
|
||||
<tr t-att-id="field.id" class="childclass" >
|
||||
<td valign="top">
|
||||
<tr t-att-id="'Treerow_'+field.id" class="childclass">
|
||||
<td valign="top" align="left" style="cursor:pointer;">
|
||||
<t t-if="(field.child_id).length>=1">
|
||||
<img id="parentimg" src="/base/static/src/img/expand.gif" width="16" height="16" border="0"/>
|
||||
</t>
|
||||
</td>
|
||||
<td>
|
||||
<t t-esc="field.name"/>
|
||||
</td>
|
||||
<t t-if="(field.child_id).length>=1">
|
||||
<td style="cursor:pointer;" align="left">
|
||||
<t t-esc="field.name"/>
|
||||
</td>
|
||||
</t>
|
||||
<t t-if="(field.child_id).length==0">
|
||||
<td align="left">
|
||||
<t t-esc="field.name"/>
|
||||
</td>
|
||||
</t>
|
||||
</tr>
|
||||
</t>
|
||||
</t>
|
||||
|
||||
Reference in New Issue
Block a user