[imp] made the context menu in m2o lazy loads

bzr revid: nicolas.vanhoren@openerp.com-20110825142126-ozmlaopwzhh5xlju
This commit is contained in:
niv-openerp 2011-08-25 16:21:26 +02:00
parent 93aa853ae6
commit d8c48d874a
1 changed files with 38 additions and 28 deletions

View File

@ -1307,15 +1307,16 @@ openerp.base.form.FieldMany2One = openerp.base.form.Field.extend({
this.$drop_down = this.$element.find(".oe-m2o-drop-down-button");
this.$menu_btn = this.$element.find(".oe-m2o-cm-button");
var init_context_menu_def = $.Deferred().then(function(e) {
// context menu
var bindings = {};
bindings[this.cm_id + "_search"] = function() {
bindings[self.cm_id + "_search"] = function() {
self._search_create_popup("search");
};
bindings[this.cm_id + "_create"] = function() {
bindings[self.cm_id + "_create"] = function() {
self._search_create_popup("form");
};
bindings[this.cm_id + "_open"] = function() {
bindings[self.cm_id + "_open"] = function() {
if (!self.value) {
return;
}
@ -1325,7 +1326,7 @@ openerp.base.form.FieldMany2One = openerp.base.form.Field.extend({
self.set_value(self.value[0]);
});
};
var cmenu = this.$menu_btn.contextMenu(this.cm_id, {'leftClickToo': true,
var cmenu = self.$menu_btn.contextMenu(self.cm_id, {'leftClickToo': true,
bindings: bindings, itemStyle: {"color": ""},
onContextMenu: function() {
if(self.value) {
@ -1336,6 +1337,15 @@ openerp.base.form.FieldMany2One = openerp.base.form.Field.extend({
return true;
}
});
setTimeout(function() {
self.$menu_btn.trigger(e);
}, 0);
});
var ctx_callback = function(e) {init_context_menu_def.resolve(e); e.preventDefault()};
this.$menu_btn.bind('contextmenu', ctx_callback);
this.$menu_btn.click(ctx_callback);
// some behavior for input
this.$input.keyup(function() {