[IMP] refactoring in m2o for future development

bzr revid: nicolas.vanhoren@openerp.com-20120918124332-mj764gxrk2ssjzjd
This commit is contained in:
niv-openerp 2012-09-18 14:43:32 +02:00
parent 6c846100f9
commit 09ab484e0b
1 changed files with 38 additions and 29 deletions

View File

@ -2753,11 +2753,8 @@ instance.web.form.FieldMany2One = instance.web.form.AbstractField.extend(instanc
this.render_editable(); this.render_editable();
this.render_value(); this.render_value();
}, },
render_editable: function() { init_error_displayer: function() {
var self = this; this.$input.tipsy({
this.$input = this.$el.find("input");
self.$input.tipsy({
title: function() { title: function() {
return QWeb.render('Tipsy.alert', { return QWeb.render('Tipsy.alert', {
message: "No element was selected, you should create or select one from the dropdown list." message: "No element was selected, you should create or select one from the dropdown list."
@ -2770,9 +2767,21 @@ instance.web.form.FieldMany2One = instance.web.form.AbstractField.extend(instanc
opacity: 1, opacity: 1,
offset: 4, offset: 4,
}); });
},
hide_error_displayer: function() {
this.$input.tipsy("hide");
},
show_error_displayer: function() {
this.$input.tipsy("show");
},
render_editable: function() {
var self = this;
this.$input = this.$el.find("input");
this.init_error_displayer();
self.$input.on('focus', function() { self.$input.on('focus', function() {
self.$input.tipsy("hide"); self.hide_error_displayer();
}); });
this.$drop_down = this.$el.find(".oe_m2o_drop_down_button"); this.$drop_down = this.$el.find(".oe_m2o_drop_down_button");
@ -2826,10 +2835,10 @@ instance.web.form.FieldMany2One = instance.web.form.AbstractField.extend(instanc
} }
} }
}); });
self.tip_def = $.Deferred(); self.ed_def = $.Deferred();
self.untip_def = $.Deferred(); self.uned_def = $.Deferred();
var tip_delay = 200; var ed_delay = 200;
var tip_duration = 15000; var ed_duration = 15000;
var anyoneLoosesFocus = function() { var anyoneLoosesFocus = function() {
var used = false; var used = false;
if (self.floating) { if (self.floating) {
@ -2849,25 +2858,25 @@ instance.web.form.FieldMany2One = instance.web.form.AbstractField.extend(instanc
} }
self.floating = false; self.floating = false;
} }
if (used && self.get("value") === false && ! self.no_tipsy) { if (used && self.get("value") === false && ! self.no_ed) {
self.tip_def.reject(); self.ed_def.reject();
self.untip_def.reject(); self.uned_def.reject();
self.tip_def = $.Deferred(); self.ed_def = $.Deferred();
self.tip_def.then(function() { self.ed_def.then(function() {
self.$input.tipsy("show"); self.show_error_displayer();
}); });
setTimeout(function() { setTimeout(function() {
self.tip_def.resolve(); self.ed_def.resolve();
self.untip_def.reject(); self.uned_def.reject();
self.untip_def = $.Deferred(); self.uned_def = $.Deferred();
self.untip_def.then(function() { self.uned_def.then(function() {
self.$input.tipsy("hide"); self.hide_error_displayer();
}); });
setTimeout(function() {self.untip_def.resolve();}, tip_duration); setTimeout(function() {self.uned_def.resolve();}, ed_duration);
}, tip_delay); }, ed_delay);
} else { } else {
self.no_tipsy = false; self.no_ed = false;
self.tip_def.reject(); self.ed_def.reject();
} }
}; };
var ignore_blur = false; var ignore_blur = false;
@ -3007,13 +3016,13 @@ instance.web.form.FieldMany2One = instance.web.form.AbstractField.extend(instanc
this.$input.focus(); this.$input.focus();
}, },
_quick_create: function() { _quick_create: function() {
this.no_tipsy = true; this.no_ed = true;
this.tip_def.reject(); this.ed_def.reject();
return instance.web.form.CompletionFieldMixin._quick_create.apply(this, arguments); return instance.web.form.CompletionFieldMixin._quick_create.apply(this, arguments);
}, },
_search_create_popup: function() { _search_create_popup: function() {
this.no_tipsy = true; this.no_ed = true;
this.tip_def.reject(); this.ed_def.reject();
return instance.web.form.CompletionFieldMixin._search_create_popup.apply(this, arguments); return instance.web.form.CompletionFieldMixin._search_create_popup.apply(this, arguments);
}, },
}); });