[IMP]Implements collapse functionality.

bzr revid: bth@tinyerp.com-20110608133706-9zrkl4jx7fcqrngc
This commit is contained in:
Bhumi Thakkar (Open ERP)
2011-06-08 19:07:06 +05:30
parent 4b15c43c43
commit 2e8aafae50
3 changed files with 87 additions and 44 deletions
+10 -10
View File
@@ -98,12 +98,12 @@ class Session(openerpweb.Controller):
"session_id": req.session_id,
"uid": req.session._uid,
}
@openerpweb.jsonrequest
def get_databases_list(self, req):
proxy = req.session.proxy("db")
dbs = proxy.list()
return {"db_list": dbs}
@openerpweb.jsonrequest
@@ -192,7 +192,7 @@ class Session(openerpweb.Controller):
This method store an action object in the session object and returns an integer
identifying that action. The method get_session_action() can be used to get
back the action.
:param the_action: The action to save in the session.
:type the_action: anything
:return: A key identifying the saved action.
@@ -215,7 +215,7 @@ class Session(openerpweb.Controller):
"""
Gets back a previously saved action. This method can return None if the action
was saved since too much time (this case should be handled in a smart way).
:param key: The key given by save_session_action()
:type key: integer
:return: The saved action or None.
@@ -225,8 +225,8 @@ class Session(openerpweb.Controller):
if not saved_actions:
return None
return saved_actions["actions"].get(key)
def load_actions_from_ir_values(req, key, key2, models, meta, context):
Values = req.session.model('ir.values')
actions = Values.get(key, key2, models, meta, context)
@@ -305,7 +305,7 @@ class Menu(openerpweb.Controller):
menu_items = Menus.read(menu_ids, ['name', 'sequence', 'parent_id'])
menu_root = {'id': False, 'name': 'root', 'parent_id': [-1, '']}
menu_items.append(menu_root)
# make a tree using parent_id
menu_items_map = dict((menu_item["id"], menu_item) for menu_item in menu_items)
for menu_item in menu_items:
@@ -369,7 +369,7 @@ class DataSet(openerpweb.Controller):
reads = Model.read(ids, fields or False, request.context)
reads.sort(key=lambda obj: ids.index(obj['id']))
return reads
@openerpweb.jsonrequest
def read(self, request, model, ids, fields=False):
return self.do_search_read(request, model, ids, fields)
@@ -445,7 +445,7 @@ class DataSet(openerpweb.Controller):
m = req.session.model(model)
r = m.default_get(fields, context)
return {'result': r}
@openerpweb.jsonrequest
def name_search(self, req, model, search_str, domain=[], context={}):
m = req.session.model(model)
@@ -472,7 +472,7 @@ class View(openerpweb.Controller):
toolbar, submenu)
self.process_view(request.session, fvg, request.context, transform)
return fvg
def process_view(self, session, fvg, context, transform):
if transform:
evaluation_context = session.evaluation_context(context or {})
+74 -31
View File
@@ -2,6 +2,7 @@ openerp.base.tree = function(openerp) {
openerp.base.views.add('tree', 'openerp.base.TreeView');
openerp.base.TreeView = openerp.base.View.extend({
init: function(view_manager, session, element_id, dataset, view_id, options) {
this._super(session, element_id);
this.view_manager = view_manager || new openerp.base.NullViewManager();
this.dataset = dataset;
@@ -25,21 +26,26 @@ openerp.base.TreeView = openerp.base.View.extend({
var self = this;
this.dataset.read_slice([], 0, false, function (response) {
self.$element.html(QWeb.render('TreeView', {'field_data':response}));
id=self.dataset.ids[0];
self.dataset.domain=[['parent_id','=',parseInt(id,10)]];
self.dataset.read_slice([], 0, false, function (response) {
$('#parent_id').change(self.getch(($('#parent_id').attr('value')),0));
self.$element.append(QWeb.render('TreeView_Secondry', {'child_data':response}));
$('#child_id').find('div').click(function(){
if(jQuery('#child_id').find('#'+(this.id)).find('#subchild').length==0){
self.getch(this.id,1);
}
if($('#'+this.id).parent().attr('id')=="child_id"){
if(jQuery('#child_id').find('#'+(this.id)).find('#subchild').length==0){
//console.log('in load');
self.getch(this.id,1);
}
}
});
});
});
},
getch: function(id,flag) {
//console.log(flag);
var self=this;
if(flag==0){
$('#parent_id').change(function(){
@@ -53,7 +59,9 @@ openerp.base.TreeView = openerp.base.View.extend({
}
},
on_change:function(parentid,flag){
var self=this;
if(parentid>0){
this.dataset.domain=[['parent_id','=',parseInt(parentid,10)]];
this.dataset.read_slice([],0,false, function (response) {
@@ -72,39 +80,74 @@ openerp.base.TreeView = openerp.base.View.extend({
jQuery('#subchild #'+parentid).find("#childimg").attr("src", "/base/static/src/img/collapse.gif");
$("#subchild #"+parentid).append(QWeb.render('TreeView_SubChildren', {'subchilddata':response}))
$("#subchild #"+parentid).find('#childsubchild').show();
}
/*for(var i=0;i<$('#child_id > div').length;i++){
console.log($('#child_id:nth-child('+i+') '));
}*/
//console.log($('#child_id > div').slice().attr('id'));
// subclass
//$('#child_id').find('.childclass').click(function(){
if(flag==0){
//console.log('in flag 0');
$('#child_id').find('div').click(function(){
var pathimg=jQuery('#child_id').find('#'+(this.id)).find("#parentimg").attr("src");
if(pathimg=='/base/static/src/img/collapse.gif'){
jQuery('#child_id').find('#'+(this.id)).find('#parentimg').attr('src','/base/static/src/img/expand.gif');
//jQuery('#subchild').find('#'+(this.id)).find('#childsubchild').hide();
//jQuery('#child_id').find('#'+(this.id)).find('#subchild').css('display','none');
}
else if(pathimg=='/base/static/src/img/expand.gif'){
if(jQuery('#child_id').find('#'+(this.id)).find('#subchild').length==0){
self.getch(this.id,1);
}
}
if($('#'+this.id).parent().attr('id')=="child_id"){
var pathimg=jQuery('#child_id').find('#'+(this.id)).find("#parentimg").attr("src");
if(pathimg=='/base/static/src/img/collapse.gif'){
$(('#'+this.id)+'> div').hide();
jQuery('#child_id').find('#'+(this.id)).find('#parentimg').attr('src','/base/static/src/img/expand.gif');
}
else if(pathimg=='/base/static/src/img/expand.gif'){
if(jQuery('#child_id').find('#'+(this.id)).find('#subchild').length==0){
self.getch(this.id,1);
}else{
$(('#'+this.id)+'> div').show();
jQuery('#child_id').find('#'+(this.id)).find('#parentimg').attr('src','/base/static/src/img/collapse.gif');
}
}
}
});
$('#child_id div #subchild').find('div').click(function(){
if(jQuery('#subchild').find('#'+(this.id)).find('#childsubchild').length==0){
self.getch(this.id,2);
}else if((jQuery('#subchild').find('#'+(this.id)).find('#childimg').attr('src'))=='/base/static/src/img/collapse.gif'){
jQuery('#subchild').find('#'+(this.id)).find('#childimg').attr('src','/base/static/src/img/expand.gif');
//jQuery('#subchild').find('#'+(this.id)).find('#childsubchild').hide();
jQuery('#subchild').find('#'+(this.id)).find('#childsubchild').css('display','none');
}
$('#child_id div #subchild').find('div').click(function(){
var childimg=jQuery('#subchild').find('#'+(this.id)).find("#childimg").attr("src");
if(childimg=='/base/static/src/img/collapse.gif'){
$('#'+this.id).find('#childsubchild').hide();
jQuery('#subchild').find('#'+(this.id)).find('#childimg').attr('src','/base/static/src/img/expand.gif');
}else if(childimg=='/base/static/src/img/expand.gif'){
/* console.log('in else of subchild div');
if($('#'+(this.id)).find('#childsubchild').css('display')=='none'){
console.log('in else-else of subchild div');
$(('#'+this.id)+'> div').show();
jQuery('#subchild').find('#'+(this.id)).find('#childimg').attr('src','/base/static/src/img/collapse.gif');
}else{
jQuery('#subchild').find('#'+(this.id)).find('#childsubchild').css('display','block');
//jQuery('#subchild').find('#'+(this.id)).find('#childsubchild').show();
}/*else{
jQuery('#subchild').find('#'+(this.id)).find('#childimg').attr('src','/base/static/src/img/expand.gif');
jQuery('#subchild').find('#'+(this.id)).find('#childsubchild').hide();
self.getch(this.id,2);
}*/
});
if(jQuery('#subchild').find('#'+(this.id)).find('#childsubchild').length==0){
//console.log('in else-if of subchild div');
self.getch(this.id,2);
}else{
//console.log('in else-else of subchild div');
$(('#'+this.id)+'> div').show();
jQuery('#subchild').find('#'+(this.id)).find('#childimg').attr('src','/base/static/src/img/collapse.gif');
}
}
/*if(jQuery('#subchild').find('#'+(this.id)).find('#childsubchild').length==0){
self.getch(this.id,2);
}else if((jQuery('#subchild').find('#'+(this.id)).find('#childimg').attr('src'))=='/base/static/src/img/collapse.gif'){
jQuery('#subchild').find('#'+(this.id)).find('#childimg').attr('src','/base/static/src/img/expand.gif');
//jQuery('#subchild').find('#'+(this.id)).find('#childsubchild').hide();
jQuery('#subchild').find('#'+(this.id)).find('#childsubchild').css('display','none');
}else{
jQuery('#subchild').find('#'+(this.id)).find('#childsubchild').css('display','block');
//jQuery('#subchild').find('#'+(this.id)).find('#childsubchild').show();
}*/ /*else{
jQuery('#subchild').find('#'+(this.id)).find('#childimg').attr('src','/base/static/src/img/expand.gif');
jQuery('#subchild').find('#'+(this.id)).find('#childsubchild').hide();
}*/
});
});
}
},
+3 -3
View File
@@ -242,7 +242,7 @@
<t t-name="TreeView_Secondry">
<div id="child_id">
<t t-foreach="child_data" t-as="field" >
<div t-att-id="field.id">
<div t-att-id="field.id" class="childclass">
<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>
@@ -264,7 +264,7 @@
<t t-name="TreeView_Children">
<div id="subchild" style="display:none">
<t t-foreach="childdata" t-as="child" >
<div t-att-id="child.id" >
<div t-att-id="child.id" class="subclass">
<t t-if="(child.child_id).length>=1">
<img id="childimg" src="/base/static/src/img/expand.gif" width="16" height="16" border="0"/>
</t>
@@ -275,7 +275,7 @@
</t>
<t t-name="TreeView_SubChildren">
<div id="childsubchild" style="display:none">
<t t-foreach="subchilddata" t-as="subchild" >
<t t-foreach="subchilddata" t-as="subchild" class="subchildclass">
<div t-att-id="subchild.id" >
<t t-if="(subchild.child_id).length>=1">
<img id="subchildimg" src="/base/static/src/img/expand.gif" width="16" height="16" border="0"/>