From e4f66912b87fd449d8c09dd1376be99f202e7236 Mon Sep 17 00:00:00 2001 From: "sma (Tiny)" Date: Thu, 19 May 2011 18:52:13 +0530 Subject: [PATCH] [IMP] Initially just open context menu with static items. bzr revid: sma@tinyerp.com-20110519132213-leppy05us2o5y1gi --- addons/base/static/src/js/m2o.js | 118 ++++++++++++++++++++++++++++++- 1 file changed, 115 insertions(+), 3 deletions(-) diff --git a/addons/base/static/src/js/m2o.js b/addons/base/static/src/js/m2o.js index c1c21ce5242..00da2f76c29 100644 --- a/addons/base/static/src/js/m2o.js +++ b/addons/base/static/src/js/m2o.js @@ -15,6 +15,15 @@ openerp.base.m2o = function(openerp){ this.relation = model; this.result_ids = []; this.create_option = jQuery('#'+this.element.attr('name')+ '_open'); + if (this.create_option) { + var defaults = [ + {'text': 'Go to..', 'action': "call_Actions()"}, + {'text': 'Choose..', 'action': "call_Actions()"} + ] + jQuery(this.create_option).click(jQuery.proxy(function(evt){ + on_context_menu(evt, this.element, defaults); + }, this)); + } var self = this; this.$input = this.element.autocomplete ({ @@ -84,7 +93,7 @@ openerp.base.m2o = function(openerp){ if (ui.item.id == 'more') { this.dataset.ids = this.result_ids; this.dataset.count = this.dataset.ids.length; - this.dataset.domain = this.result_ids.length ? [["id", "in", this.dataset.ids]] : [] + this.dataset.domain = this.result_ids.length ? [["id", "in", this.dataset.ids]] : []; this.element.val(''); var pop = new openerp.base.form.Many2XSelectPopup(null, this.session); pop.select_element(this.relation, this.dataset); @@ -92,7 +101,7 @@ openerp.base.m2o = function(openerp){ } if (ui.item.id == 'create') { - this.openRecords(event, ui) + this.openRecords(event, ui); } this.element.attr('m2o_id', ui.item.id); }, @@ -107,7 +116,7 @@ openerp.base.m2o = function(openerp){ openRecords: function(event, ui) { var val = this.element.val(); - var self = this + var self = this; this.dataset.create({'name': ui.item.value}, function(r){}, function(r){ var element_id = _.uniqueId("act_window_dialog"); @@ -126,3 +135,106 @@ openerp.base.m2o = function(openerp){ } }); } + +function call_Actions() { + +} + +function on_context_menu(evt, target, defaults){ + + var $target = jQuery(target || evt.target); + var kind = $target.attr('type'); + if (!(kind && $target.is(':input, :enabled'))) { + return; + } + var $menu = jQuery('#contextmenu').show(); + if (!$menu.length) { + $menu = jQuery('
') + .css({position: 'absolute'}) + .hover(showContextMenu, hideContextMenu) + .appendTo(document.body).show(); + + if (jQuery(document.documentElement).hasClass('ie')) { + jQuery('