summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js/core
diff options
context:
space:
mode:
authorJulien Mougenot <jum@odoo.com>2020-03-11 09:38:28 +0000
committerJulien Mougenot <jum@odoo.com>2020-03-13 14:08:33 +0000
commit18e5416636b19b0953b1e6e26bfaeab1ebecce4c (patch)
tree5be75af26f1707a5b8b2184545719f3628d2980f /addons/web/static/src/js/core
parentfbf347498f1cc7b74ef373179b7bcae201715c24 (diff)
[REF] web: Adapt views/actions to new control panel
Some web actions/controllers/viewsl have been adapted to properly instantiate the newly refactored control panel and update it accordingly. We needed to adapt the starting mechanism of actions and controllers to ensure that the control panel instantiation did not delay the loading of any widget. Part of task 2196029 Co-authored-by: Mathieu Duckerts-Antoine <dam@odoo.com>
Diffstat (limited to 'addons/web/static/src/js/core')
-rw-r--r--addons/web/static/src/js/core/custom_hooks.js52
-rw-r--r--addons/web/static/src/js/core/owl_dialog.js4
2 files changed, 29 insertions, 27 deletions
diff --git a/addons/web/static/src/js/core/custom_hooks.js b/addons/web/static/src/js/core/custom_hooks.js
index 69750066a8c..883f385ac3c 100644
--- a/addons/web/static/src/js/core/custom_hooks.js
+++ b/addons/web/static/src/js/core/custom_hooks.js
@@ -5,35 +5,37 @@ odoo.define('web.custom_hooks', function () {
const { onMounted, onPatched, onWillUnmount } = hooks;
/**
- * Returns a function which purpose is to focus the given selector on the next
- * repaint (mount or patch). Its default selector is the first element having
- * an `autofocus' attribute. Text selection will be set at the end of the value
- * if the target is a text element. The action is lost if no element was found.
- *
- * @returns {Function}
+ * Focus a given selector as soon as it appears in the DOM and if it was not
+ * displayed before. If the selected target is an input|textarea, set the selection
+ * at the end.
+ * @param {Object} [params]
+ * @param {string} [params.selector='autofocus'] default: select the first element
+ * with an `autofocus` attribute.
+ * @returns {Function} function that forces the focus on the next update if visible.
*/
- function useFocusOnUpdate() {
- const component = Component.current;
- let willFocus = null;
-
- function _focusSelector() {
- if (willFocus) {
- const target = component.el.querySelector(willFocus);
- if (target) {
- target.focus();
- if (['INPUT', 'TEXTAREA'].includes(target.tagName)) {
- target.selectionStart = target.selectionEnd = target.value.length;
- }
+ function useAutofocus(params = {}) {
+ const comp = Component.current;
+ // Prevent autofocus in mobile
+ if (comp.env.device.isMobile) {
+ return () => {};
+ }
+ const selector = params.selector || '[autofocus]';
+ let target = null;
+ function autofocus() {
+ const prevTarget = target;
+ target = comp.el.querySelector(selector);
+ if (target && target !== prevTarget) {
+ target.focus();
+ if (['INPUT', 'TEXTAREA'].includes(target.tagName)) {
+ target.selectionStart = target.selectionEnd = target.value.length;
}
- willFocus = null;
}
}
+ onMounted(autofocus);
+ onPatched(autofocus);
- onMounted(_focusSelector);
- onPatched(_focusSelector);
-
- return function focusOnUpdate(selector = '[autofocus]') {
- willFocus = selector;
+ return function focusOnUpdate() {
+ target = null;
};
}
@@ -110,7 +112,7 @@ odoo.define('web.custom_hooks', function () {
}
return {
- useFocusOnUpdate,
+ useAutofocus,
useListener,
};
});
diff --git a/addons/web/static/src/js/core/owl_dialog.js b/addons/web/static/src/js/core/owl_dialog.js
index d376e042ae4..daa29468934 100644
--- a/addons/web/static/src/js/core/owl_dialog.js
+++ b/addons/web/static/src/js/core/owl_dialog.js
@@ -163,7 +163,7 @@ odoo.define('web.OwlDialog', function () {
$(this.mainButton)
.tooltip({
delay: { show: 200, hide: 0 },
- title: () => this.env.qweb.renderToString('DialogButton.tooltip', {
+ title: () => this.env.qweb.renderToString('web.DialogButton.tooltip', {
title: this.mainButton.innerText.toUpperCase(),
}),
trigger: 'manual',
@@ -263,7 +263,7 @@ odoo.define('web.OwlDialog', function () {
technical: Boolean,
title: String,
};
- Dialog.template = 'OwlDialog';
+ Dialog.template = 'web.OwlDialog';
return Dialog;
});