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
=== modified file 'addons/web/static/src/js/view_form.js'
--- addons/web/static/src/js/view_form.js 2012-10-23 07:30:10 +0000
+++ addons/web/static/src/js/view_form.js 2012-11-30 11:46:26 +0000
@@ -2036,6 +2036,7 @@
2036 this.$input = this.$element.find("input");2036 this.$input = this.$element.find("input");
2037 this.$drop_down = this.$element.find(".oe-m2o-drop-down-button");2037 this.$drop_down = this.$element.find(".oe-m2o-drop-down-button");
2038 this.$menu_btn = this.$element.find(".oe-m2o-cm-button");2038 this.$menu_btn = this.$element.find(".oe-m2o-cm-button");
2039 var $self = $(self), ignore_blur = false, cm_ignore_blur = false;
20392040
2040 // context menu2041 // context menu
2041 var init_context_menu_def = $.Deferred().then(function(e) {2042 var init_context_menu_def = $.Deferred().then(function(e) {
@@ -2084,6 +2085,24 @@
2084 });2085 });
2085 var cmenu = self.$menu_btn.contextMenu(self.cm_id, {'noRightClick': true,2086 var cmenu = self.$menu_btn.contextMenu(self.cm_id, {'noRightClick': true,
2086 bindings: bindings, itemStyle: {"color": ""},2087 bindings: bindings, itemStyle: {"color": ""},
2088 onShowMenu: function(ev, menu) {
2089 if (menu.attr('openerp_cm_id') && menu.attr('openerp_cm_id') != self.cm_id) {
2090 // if contextMenu still visible but for a different
2091 // m2o, force it to hide to ensure 'cm_ignore_blur'
2092 // is correctly resetted.
2093 menu.hide();
2094 }
2095 menu.attr('openerp_cm_id', self.cm_id);
2096 cm_ignore_blur = true;
2097 menu.hide = function() {
2098 if ($(this).attr('openerp_cm_id')) {
2099 $(this).attr('openerp_cm_id', null);
2100 cm_ignore_blur = false;
2101 }
2102 $(this).hide();
2103 }
2104 return menu;
2105 },
2087 onContextMenu: function() {2106 onContextMenu: function() {
2088 if(self.value) {2107 if(self.value) {
2089 $("#" + self.cm_id + " .oe_m2o_menu_item_mandatory").removeClass("oe-m2o-disabled-cm");2108 $("#" + self.cm_id + " .oe_m2o_menu_item_mandatory").removeClass("oe-m2o-disabled-cm");
@@ -2101,9 +2120,14 @@
2101 $.async_when().then(function() {self.$menu_btn.trigger(e);});2120 $.async_when().then(function() {self.$menu_btn.trigger(e);});
2102 });2121 });
2103 });2122 });
2104 var ctx_callback = function(e) {init_context_menu_def.resolve(e); e.preventDefault()};2123 this.$menu_btn.bind({
2105 this.$menu_btn.click(ctx_callback);2124 click: function(e) { init_context_menu_def.resolve(e); e.preventDefault() },
21062125 focus: function () { $self.trigger('widget-focus'); },
2126 blur: function () {
2127 if (cm_ignore_blur) { return; }
2128 $self.trigger('widget-blur');
2129 }
2130 });
2107 // some behavior for input2131 // some behavior for input
2108 this.$input.keyup(function() {2132 this.$input.keyup(function() {
2109 if (self.$input.val() === "") {2133 if (self.$input.val() === "") {
@@ -2143,7 +2167,6 @@
2143 }2167 }
2144 }2168 }
2145 };2169 };
2146 var $self = $(self), ignore_blur = false;
2147 this.$input.bind({2170 this.$input.bind({
2148 focusout: anyoneLoosesFocus,2171 focusout: anyoneLoosesFocus,
2149 focus: function () { $self.trigger('widget-focus'); },2172 focus: function () { $self.trigger('widget-focus'); },
@@ -2151,7 +2174,7 @@
2151 autocompleteclose: function () { ignore_blur = false; },2174 autocompleteclose: function () { ignore_blur = false; },
2152 blur: function () {2175 blur: function () {
2153 // autocomplete open2176 // autocomplete open
2154 if (ignore_blur) { return; }2177 if (ignore_blur || cm_ignore_blur) { return; }
2155 var child_popup_open = _(self.widget_children).any(function (child) {2178 var child_popup_open = _(self.widget_children).any(function (child) {
2156 return child instanceof openerp.web.form.SelectCreatePopup2179 return child instanceof openerp.web.form.SelectCreatePopup
2157 || child instanceof openerp.web.form.FormOpenPopup;2180 || child instanceof openerp.web.form.FormOpenPopup;
@@ -2194,7 +2217,6 @@
2194 }2217 }
2195 });2218 });
21962219
2197 this.setupFocus(this.$menu_btn);
2198 },2220 },
2199 // autocomplete component content handling2221 // autocomplete component content handling
2200 get_search_result: function(request, response) {2222 get_search_result: function(request, response) {