[IMP] Loaded data and displayed in tree structure.
bzr revid: bth@tinyerp.com-20110607071034-lfr5nlt5aiduk6z6
This commit is contained in:
parent
f75ac6d8f2
commit
c4fe70d92c
|
@ -756,3 +756,20 @@ class Action(openerpweb.Controller):
|
|||
if action:
|
||||
value = clean_action(action[0], req.session)
|
||||
return {'result': value}
|
||||
class TreeView(View):
|
||||
_cp_path = "/base/treeview"
|
||||
|
||||
@openerpweb.jsonrequest
|
||||
def load(self, req, model, view_id, toolbar=False):
|
||||
fields_view = self.fields_view_get(req, model, view_id, 'tree', toolbar=toolbar)
|
||||
return {'field_parent': fields_view}
|
||||
|
||||
def fields_view_get(self, request, model, view_id, view_type="tree",
|
||||
transform=True, toolbar=False, submenu=False):
|
||||
""" Sets @editable on the view's arch if it isn't already set and
|
||||
``set_editable`` is present in the request context
|
||||
"""
|
||||
view = super(TreeView, self).fields_view_get(
|
||||
request, model, view_id, view_type, transform, toolbar, submenu)
|
||||
|
||||
return view
|
|
@ -1,26 +1,105 @@
|
|||
/*---------------------------------------------------------
|
||||
* OpenERP base library
|
||||
*---------------------------------------------------------*/
|
||||
|
||||
openerp.base.tree = function(openerp) {
|
||||
|
||||
openerp.base.views.add('tree', 'openerp.base.TreeView');
|
||||
openerp.base.TreeView = openerp.base.Controller.extend({
|
||||
/**
|
||||
* Genuine tree view (the one displayed as a tree, not the list)
|
||||
*/
|
||||
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;
|
||||
this.model = dataset.model;
|
||||
this.view_id = view_id;
|
||||
|
||||
this.columns = [];
|
||||
|
||||
this.options = _.extend({}, this.defaults, options || {});
|
||||
this.flags = this.view_manager.action.flags;
|
||||
},
|
||||
start: function () {
|
||||
this._super();
|
||||
this.$element.append('Tree view');
|
||||
return this.rpc("/base/treeview/load", {
|
||||
model: this.model,
|
||||
view_id: this.view_id,
|
||||
toolbar: this.view_manager ? !!this.view_manager.sidebar : false
|
||||
}, this.on_loaded);
|
||||
},
|
||||
do_show: function () {
|
||||
this.$element.show();
|
||||
on_loaded: function (data) {
|
||||
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(){
|
||||
self.getch(this.id,1)
|
||||
});
|
||||
});
|
||||
});
|
||||
},
|
||||
do_hide: function () {
|
||||
this.$element.hide();
|
||||
getch: function(id,flag) {
|
||||
|
||||
var self=this;
|
||||
if(flag==0){
|
||||
$('#parent_id').change(function(){
|
||||
self.on_change($('#parent_id').attr('value'),0);
|
||||
});
|
||||
}
|
||||
else if(flag==1){
|
||||
self.on_change(id,1);
|
||||
}else{
|
||||
self.on_change(id,2);
|
||||
}
|
||||
},
|
||||
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) {
|
||||
if(flag==0){
|
||||
$('#child_id').remove();
|
||||
self.$element.append(QWeb.render('TreeView_Secondry', {'child_data':response}));
|
||||
}else if(flag==1){
|
||||
jQuery('#'+parentid).append(QWeb.render('TreeView_Children', {'childdata':response}))
|
||||
$('#'+parentid).find('#subchild').find('#subchild').remove();
|
||||
$('#'+parentid).find('#subchild').slice(1,3).remove();
|
||||
}else if(flag==2){
|
||||
$("#subchild #"+parentid).find('#subchild').remove();
|
||||
$("#subchild #"+parentid).find('#childsubchild').remove();
|
||||
$("#subchild #"+parentid).append(QWeb.render('TreeView_SubChildren', {'subchilddata':response}))
|
||||
}
|
||||
$('#child_id').find('div').click(function(){
|
||||
self.getch(this.id,1)
|
||||
});
|
||||
$('#child_id div #subchild').find('div').click(function(){
|
||||
self.getch(this.id,2)
|
||||
});
|
||||
});
|
||||
}
|
||||
},
|
||||
reload_view: function (grouped) {
|
||||
var self = this;
|
||||
this.dataset.offset = 0;
|
||||
this.dataset.limit = false;
|
||||
return this.rpc('/base/treeview/load', {
|
||||
model: this.model,
|
||||
view_id: this.view_id,
|
||||
toolbar: !!this.flags.sidebar
|
||||
}, function (field_view_get) {
|
||||
self.on_loaded(field_view_get, grouped);
|
||||
});
|
||||
},
|
||||
do_search: function (domains, contexts, groupbys) {
|
||||
var self = this;
|
||||
return this.rpc('/base/session/eval_domain_and_context', {
|
||||
domains: domains,
|
||||
contexts: contexts,
|
||||
group_by_seq: groupbys
|
||||
}, function (results) {
|
||||
self.dataset.context = results.context;
|
||||
self.dataset.domain = results.domain;
|
||||
self.reload_view(!!results.group_by).then(
|
||||
$.proxy(self, 'reload_content'));
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
// vim:et fdc=0 fdl=0 foldnestmax=3 fdm=syntax:
|
||||
}
|
|
@ -229,7 +229,63 @@
|
|||
</table>
|
||||
</t>
|
||||
<table t-name="TreeView">
|
||||
<tr>
|
||||
<select name="parent" id="parent_id" style="width: 30%">
|
||||
<t t-foreach="field_data" t-as="field" >
|
||||
<option t-att-value="field.id">
|
||||
<t t-esc="field.name"/>
|
||||
</option>
|
||||
</t>
|
||||
</select>
|
||||
</tr>
|
||||
</table>
|
||||
<t t-name="TreeView_Secondry">
|
||||
<div id="child_id">
|
||||
<t t-foreach="child_data" t-as="field" >
|
||||
<div t-att-id="field.id">
|
||||
<t t-if="(field.child_id).length>=1">
|
||||
<img src="/base/static/src/img/iconset-d-drop.gif" width="16" height="16" border="0"/>
|
||||
</t>
|
||||
<t t-esc="field.name"/>
|
||||
</div>
|
||||
</t>
|
||||
</div>
|
||||
<!-- <ul id="child_id">
|
||||
<t t-foreach="child_data" t-as="field" >
|
||||
<li t-att-id="field.id" >
|
||||
<t t-esc="field.name"/>
|
||||
|
||||
|
||||
</li>
|
||||
</t>
|
||||
</ul> -->
|
||||
|
||||
</t>
|
||||
<t t-name="TreeView_Children">
|
||||
<div id="subchild" >
|
||||
<t t-foreach="childdata" t-as="child" >
|
||||
<div t-att-id="child.id" >
|
||||
<t t-if="(child.child_id).length>=1">
|
||||
<img src="/base/static/src/img/iconset-d-drop.gif" width="16" height="16" border="0"/>
|
||||
</t>
|
||||
<t t-esc="child.name"/>
|
||||
</div>
|
||||
</t>
|
||||
</div>
|
||||
</t>
|
||||
<t t-name="TreeView_SubChildren">
|
||||
<div id="childsubchild">
|
||||
<t t-foreach="subchilddata" t-as="subchild" >
|
||||
<div t-att-id="subchild.id" >
|
||||
<t t-if="(subchild.child_id).length>=1">
|
||||
<img src="/base/static/src/img/iconset-d-drop.gif" width="16" height="16" border="0"/>
|
||||
</t>
|
||||
|
||||
<t t-esc="subchild.name"/>
|
||||
</div>
|
||||
</t>
|
||||
</div>
|
||||
</t>
|
||||
<table t-name="ListView">
|
||||
<t t-set="columns_count" t-value="visible_columns.length + (options.selectable ? 1 : 0) + (options.deletable ? 1 : 0)"/>
|
||||
<t t-set="actions_span" t-value="Math.floor((options.deletable or options.addable) ? columns_count/2 : 0)"/>
|
||||
|
|
Loading…
Reference in New Issue