[IMP] Lazy loading of views

bzr revid: fme@openerp.com-20110331132058-w6g87wsxof3kyiqv
This commit is contained in:
Fabien Meghazi 2011-03-31 15:20:58 +02:00
parent 911af887b9
commit f64b7d3b8c
3 changed files with 39 additions and 25 deletions

View File

@ -395,6 +395,11 @@ body.openerp {
padding-left: 10px; padding-left: 10px;
} }
/* View Manager */
.openerp .views_switchers {
text-align: right;
}
/* Form */ /* Form */
.openerp .required.error { .openerp .required.error {
border: 1px solid #900; border: 1px solid #900;

View File

@ -41,8 +41,31 @@ openerp.base.ViewManager = openerp.base.Controller.extend({
}, },
on_mode_switch: function(view_type) { on_mode_switch: function(view_type) {
this.active_view = view_type; this.active_view = view_type;
var view = this.views[view_type];
if (!view.controller) {
// Lazy loading of views
var controller;
switch (view_type) {
case 'tree':
controller = new openerp.base.ListView(this.session, this.element_id + "_view_tree", this.dataset, view.view_id);
break;
case 'form':
controller = new openerp.base.FormView(this.session, this.element_id + "_view_form", this.dataset, view.view_id);
break;
case 'calendar':
controller = new openerp.base.CalendarView(this.session, this.element_id + "_view_calendar", this.dataset, view.view_id);
break;
case 'gantt':
controller = new openerp.base.GanttView(this.session, this.element_id + "_view_gantt", this.dataset, view.view_id);
break;
}
controller.start();
this.views[view_type].controller = controller;
}
for (var i in this.views) { for (var i in this.views) {
this.views[i].controller.$element.toggle(i === view_type); if (this.views[i].controller) {
this.views[i].controller.$element.toggle(i === view_type);
}
} }
}, },
/** /**
@ -86,25 +109,12 @@ openerp.base.ViewManager = openerp.base.Controller.extend({
searchview.do_search); searchview.do_search);
} }
} }
for(var i = 0; i < action.views.length; i++) { this.$element.find('.views_switchers button').click(function() {
var view_id, controller; self.on_mode_switch($(this).data('view-type'));
view_id = action.views[i][0]; });
if(action.views[i][1] == "tree") { _.each(action.views, function(view) {
controller = new openerp.base.ListView(this.session, this.element_id + "_view_tree", this.dataset, view_id); self.views[view[1]] = { view_id: view[0], controller: null };
controller.start(); });
this.views.tree = { view_id: view_id, controller: controller };
this.$element.find(prefix_id + "_button_tree").bind('click',function(){
self.on_mode_switch("tree");
});
} else if(action.views[i][1] == "form") {
controller = new openerp.base.FormView(this.session, this.element_id + "_view_form", this.dataset, view_id);
controller.start();
this.views.form = { view_id: view_id, controller: controller };
this.$element.find(prefix_id + "_button_form").bind('click',function(){
self.on_mode_switch("form");
});
}
}
// switch to the first one in sequence // switch to the first one in sequence
this.on_mode_switch(action.views[0][1]); this.on_mode_switch(action.views[0][1]);
}, },

View File

@ -126,12 +126,11 @@
</t> </t>
<t t-name="ViewManager"> <t t-name="ViewManager">
<!-- TODO prefix id with the element_id of the controller t-attf-id="#{prefix}_localid" --> <!-- TODO prefix id with the element_id of the controller t-attf-id="#{prefix}_localid" -->
<div style="text-align:right;"> <div class="views_switchers">
<!--
<input t-foreach="views" t-as="view" t-att-id="" t-att-value="view[1]"/>
-->
<t t-foreach="views" t-as="view"> <t t-foreach="views" t-as="view">
<input t-attf-id="#{prefix}_button_#{view[1]}" type="button" t-att-value="view[1]"/> <button type="button" t-att-data-view-type="view[1]">
<t t-esc="view[1]"/>
</button>
</t> </t>
</div> </div>
<div t-attf-id="#{prefix}_search"></div> <div t-attf-id="#{prefix}_search"></div>