Merge lp:~openerp-dev/openerp-web/6.1-opw-579519-msh into lp:openerp-web/6.1

Proposed by Mohammed Shekha(Open ERP)
Status: Merged
Approved by: Xavier ALT
Approved revision: 2462
Merged at revision: 2491
Proposed branch: lp:~openerp-dev/openerp-web/6.1-opw-579519-msh
Merge into: lp:openerp-web/6.1
Diff against target: 79 lines (+28/-6)
1 file modified
addons/web/static/src/js/view_form.js (+28/-6)
To merge this branch: bzr merge lp:~openerp-dev/openerp-web/6.1-opw-579519-msh
Reviewer Review Type Date Requested Status
OpenERP Core Team Pending
Review via email: mp+126388@code.launchpad.net

Description of the change

Hello,

Fixed the issue of blur and focus event binded on many2one menu button, here when you open context menu in editable one2many and click any option of the context will call save for current row.

Reason :- We bind the focus and blur of menu button of context menu, so when we click inside context menu will call blur for the menu button, and focus is not set to other widget of current row hence it will call form-blur and form-blur in turn call save for current row.

Hence manually bind the focus and blur for menu button of context menu instead of setupFocus, and ignore the blur when context menu clicked.

Thanks.

To post a comment you must log in.
2462. By Xavier ALT

[IMP] many2one: better handle blur flag - has to be independant of autocomplete + correctly resetted on hide

Revision history for this message
Xavier ALT (dex-phx) wrote :

Hi Mohammed,

I've rework thing a little here to better handle the blur flag, as pn r2461 the flag was never resetted to "false".
I have also improved handling of that blur thing when both "contextmneu" and "autocomplete" is visible (that why we need to distinct flag) and when clicking on "menu_btn" from different many2one consecutively.

Cheers,
Xavier

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'addons/web/static/src/js/view_form.js'
2--- addons/web/static/src/js/view_form.js 2012-10-23 07:30:10 +0000
3+++ addons/web/static/src/js/view_form.js 2012-11-30 11:46:26 +0000
4@@ -2036,6 +2036,7 @@
5 this.$input = this.$element.find("input");
6 this.$drop_down = this.$element.find(".oe-m2o-drop-down-button");
7 this.$menu_btn = this.$element.find(".oe-m2o-cm-button");
8+ var $self = $(self), ignore_blur = false, cm_ignore_blur = false;
9
10 // context menu
11 var init_context_menu_def = $.Deferred().then(function(e) {
12@@ -2084,6 +2085,24 @@
13 });
14 var cmenu = self.$menu_btn.contextMenu(self.cm_id, {'noRightClick': true,
15 bindings: bindings, itemStyle: {"color": ""},
16+ onShowMenu: function(ev, menu) {
17+ if (menu.attr('openerp_cm_id') && menu.attr('openerp_cm_id') != self.cm_id) {
18+ // if contextMenu still visible but for a different
19+ // m2o, force it to hide to ensure 'cm_ignore_blur'
20+ // is correctly resetted.
21+ menu.hide();
22+ }
23+ menu.attr('openerp_cm_id', self.cm_id);
24+ cm_ignore_blur = true;
25+ menu.hide = function() {
26+ if ($(this).attr('openerp_cm_id')) {
27+ $(this).attr('openerp_cm_id', null);
28+ cm_ignore_blur = false;
29+ }
30+ $(this).hide();
31+ }
32+ return menu;
33+ },
34 onContextMenu: function() {
35 if(self.value) {
36 $("#" + self.cm_id + " .oe_m2o_menu_item_mandatory").removeClass("oe-m2o-disabled-cm");
37@@ -2101,9 +2120,14 @@
38 $.async_when().then(function() {self.$menu_btn.trigger(e);});
39 });
40 });
41- var ctx_callback = function(e) {init_context_menu_def.resolve(e); e.preventDefault()};
42- this.$menu_btn.click(ctx_callback);
43-
44+ this.$menu_btn.bind({
45+ click: function(e) { init_context_menu_def.resolve(e); e.preventDefault() },
46+ focus: function () { $self.trigger('widget-focus'); },
47+ blur: function () {
48+ if (cm_ignore_blur) { return; }
49+ $self.trigger('widget-blur');
50+ }
51+ });
52 // some behavior for input
53 this.$input.keyup(function() {
54 if (self.$input.val() === "") {
55@@ -2143,7 +2167,6 @@
56 }
57 }
58 };
59- var $self = $(self), ignore_blur = false;
60 this.$input.bind({
61 focusout: anyoneLoosesFocus,
62 focus: function () { $self.trigger('widget-focus'); },
63@@ -2151,7 +2174,7 @@
64 autocompleteclose: function () { ignore_blur = false; },
65 blur: function () {
66 // autocomplete open
67- if (ignore_blur) { return; }
68+ if (ignore_blur || cm_ignore_blur) { return; }
69 var child_popup_open = _(self.widget_children).any(function (child) {
70 return child instanceof openerp.web.form.SelectCreatePopup
71 || child instanceof openerp.web.form.FormOpenPopup;
72@@ -2194,7 +2217,6 @@
73 }
74 });
75
76- this.setupFocus(this.$menu_btn);
77 },
78 // autocomplete component content handling
79 get_search_result: function(request, response) {