[imp] refactoring to allow passing objects instead of normal views declaration to view manager to allow passing additional options + small fix in form view about actions

bzr revid: nicolas.vanhoren@openerp.com-20110616142530-vbzf3z7atncf508y
This commit is contained in:
niv-openerp 2011-06-16 16:25:30 +02:00
parent 34ea3495b9
commit 571771a879
3 changed files with 17 additions and 11 deletions

View File

@ -32,7 +32,7 @@ openerp.base.FormView = openerp.base.View.extend( /** @lends openerp.base.FormV
this.ready = false;
this.show_invalid = true;
this.touched = false;
this.flags = this.view_manager.action.flags || {};
this.flags = this.view_manager.flags || {};
this.registry = openerp.base.form.widgets;
},
start: function() {
@ -1242,9 +1242,14 @@ openerp.base.form.FieldOne2Many = openerp.base.form.Field.extend({
modes = !!modes ? modes.split(",") : ["tree", "form"];
var views = [];
_.each(modes, function(mode) {
var view = [false, mode == "tree" ? "list" : mode];
var view = {view_id: false, view_type: mode == "tree" ? "list" : mode};
if (self.field.views && self.field.views[mode]) {
view.push(self.field.views[mode]);
view.embedded_view = self.field.views[mode];
}
if(view.view_type === "list") {
view.options = {
"selectable": false
};
}
views.push(view);
});

View File

@ -78,7 +78,8 @@ openerp.base.ViewManager = openerp.base.Controller.extend({
this.dataset = dataset;
this.searchview = null;
this.active_view = null;
this.views_src = views;
this.views_src = _.map(views, function(x)
{return x instanceof Array? {view_id: x[0], view_type: x[1]} : x;});
this.views = {};
this.flags = this.flags || {};
this.sidebar = new openerp.base.NullSidebar();
@ -94,14 +95,13 @@ openerp.base.ViewManager = openerp.base.Controller.extend({
self.on_mode_switch($(this).data('view-type'));
});
_.each(this.views_src, function(view) {
self.views[view[1]] = { view_id: view[0], controller: null,
embedded_view: view[2]};
self.views[view.view_type] = $.extend({}, view, {controller: null});
});
if (this.flags.views_switcher === false) {
this.$element.find('.oe_vm_switch').hide();
}
// switch to the first one in sequence
return this.on_mode_switch(this.views_src[0][1]);
return this.on_mode_switch(this.views_src[0].view_type);
},
stop: function() {
},
@ -118,7 +118,8 @@ openerp.base.ViewManager = openerp.base.Controller.extend({
if (!view.controller) {
// Lazy loading of views
var controllerclass = openerp.base.views.get_object(view_type);
var controller = new controllerclass( this, this.session, this.element_id + "_view_" + view_type, this.dataset, view.view_id);
var controller = new controllerclass( this, this.session, this.element_id + "_view_" + view_type,
this.dataset, view.view_id, view.options);
if (view.embedded_view) {
controller.set_embedded_view(view.embedded_view);
}

View File

@ -232,14 +232,14 @@
<!-- TODO prefix id with the element_id of the controller t-attf-id="#{prefix}_localid" -->
<div class="oe_vm_switch">
<t t-if="views.length != 1" t-foreach="views" t-as="view">
<button type="button" t-att-data-view-type="view[1]">
<t t-esc="view[1]"/>
<button type="button" t-att-data-view-type="view.view_type">
<t t-esc="view.view_type"/>
</button>
</t>
</div>
<div t-attf-id="#{prefix}_search" t-opentag="true"/>
<t t-foreach="views" t-as="view">
<div t-attf-id="#{prefix}_view_#{view[1]}"/>
<div t-attf-id="#{prefix}_view_#{view.view_type}"/>
</t>
</td>
<td class="view-manager-main-sidebar" height="100%">