[imp] added deferred in m2m & m2o to clean code

bzr revid: nicolas.vanhoren@openerp.com-20110531152807-ejvxyokj3y4816o0
This commit is contained in:
niv-openerp 2011-05-31 17:28:07 +02:00
parent 03c9889964
commit 954ac12560
2 changed files with 32 additions and 32 deletions

View File

@ -992,6 +992,8 @@ openerp.base.form.FieldOne2Many = openerp.base.form.Field.extend({
init: function(view, node) { init: function(view, node) {
this._super(view, node); this._super(view, node);
this.template = "FieldOne2Many"; this.template = "FieldOne2Many";
this.is_started = $.Deferred();
this.is_setted = $.Deferred();
}, },
start: function() { start: function() {
this._super.apply(this, arguments); this._super.apply(this, arguments);
@ -1011,32 +1013,28 @@ openerp.base.form.FieldOne2Many = openerp.base.form.Field.extend({
this.viewmanager = new openerp.base.ViewManager(this.view.session, this.viewmanager = new openerp.base.ViewManager(this.view.session,
this.element_id, this.dataset, views); this.element_id, this.dataset, views);
this.viewmanager.start(); this.viewmanager.start();
this.viewmanager.on_controller_inited.add_last(function(view_type) {
var hack = {loaded: false}; if (view_type == "list") {
var view = this.viewmanager.views[this.viewmanager.active_view].controller; self.is_started.resolve();
view.on_loaded.add_last(function() { // TODO niv
if (! hack.loaded) { } else {
self.is_started = true; // TODO niv
self.check_load();
hack.loaded = true;
} }
}); });
$.when(this.is_started, this.is_setted).then(function() {
var view = self.viewmanager.views[self.viewmanager.active_view].controller;
view.reload_content();
});
}, },
set_value: function(value) { set_value: function(value) {
if(value != false) { if(value != false) {
this.dataset.set_ids(value); this.dataset.set_ids(value);
this.is_setted = true; this.is_setted.resolve();
this.check_load();
}
},
check_load: function() {
if(this.is_started && this.is_setted) {
var view = this.viewmanager.views[this.viewmanager.active_view].controller;
view.reload_content();
} }
}, },
get_value: function(value) { get_value: function(value) {
//TODO //TODO niv
return []; return [];
} }
}); });
@ -1046,8 +1044,8 @@ openerp.base.form.FieldMany2Many = openerp.base.form.Field.extend({
this._super(view, node); this._super(view, node);
this.template = "FieldMany2Many"; this.template = "FieldMany2Many";
this.list_id = _.uniqueId("many2many"); this.list_id = _.uniqueId("many2many");
this.is_started = false; this.is_started = $.Deferred();
this.is_setted = false; this.is_setted = $.Deferred();
}, },
start: function() { start: function() {
this._super.apply(this, arguments); this._super.apply(this, arguments);
@ -1069,29 +1067,21 @@ openerp.base.form.FieldMany2Many = openerp.base.form.Field.extend({
}); });
this.list_view.m2m_field = this; this.list_view.m2m_field = this;
this.list_view.start(); this.list_view.start();
var hack = {loaded: false};
this.list_view.on_loaded.add_last(function() { this.list_view.on_loaded.add_last(function() {
if (! hack.loaded) { self.is_started.resolve();
self.is_started = true; });
self.check_load(); $.when(this.is_started, this.is_setted).then(function() {
hack.loaded = true; self.list_view.reload_content();
}
}); });
}, },
set_value: function(value) { set_value: function(value) {
if (value != false) { if (value != false) {
this.dataset.set_ids(value); this.dataset.set_ids(value);
this.is_setted = true; this.is_setted.resolve();
this.check_load();
} }
}, },
get_value: function() { get_value: function() {
return [[6,false,this.dataset.ids]]; return [[6,false,this.dataset.ids]];
},
check_load: function() {
if(this.is_started && this.is_setted) {
this.list_view.reload_content();
}
} }
}); });

View File

@ -120,6 +120,10 @@ openerp.base.ViewManager = openerp.base.Controller.extend({
var controllerclass = openerp.base.views.get_object(view_type); 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_promise = controller.start(); view_promise = controller.start();
var self = this;
$.when(view_promise).then(function() {
self.on_controller_inited(view_type);
});
this.views[view_type].controller = controller; this.views[view_type].controller = controller;
} }
@ -147,6 +151,12 @@ openerp.base.ViewManager = openerp.base.Controller.extend({
} }
return view_promise; return view_promise;
}, },
/**
* Event launched when a controller has been inited.
*
* @param {String} view_type type of view
*/
on_controller_inited: function(view_type) {},
/** /**
* Sets up the current viewmanager's search view. * Sets up the current viewmanager's search view.
* *