summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js/views/abstract_controller.js
diff options
context:
space:
mode:
authorJulien Mougenot <jum@odoo.com>2020-06-19 07:06:32 +0000
committerAaron Bohy <aab@odoo.com>2020-06-22 13:04:01 +0000
commit6998452065044650665c5020e6b730aede690ec0 (patch)
treeea5bd87ab198b1b9ca7278f8eb9567786b2c2186 /addons/web/static/src/js/views/abstract_controller.js
parentc7964657ecbbad278cec73cf231d7eef55b44347 (diff)
[IMP] web: disable keyboard navigation with sample data
Previous commit introduces the sample data feature in list and kanban views. When sample data is displayed, most parts of the renderers can't be clicked on, to prevent the user from interacting with sample records (e.g. to open a sample record in form view from the list). This commit disables keyboard navigation as well, as those sample records could still be accessed with the keyboard. To do so, several refactorings have been done in views: - _giveFocus function added on controllers (so that we can hook on the moment where we want to focus the renderer, and prevent it in sample mode), it kind of replaces giveFocus of ActionMixin which wasn't use from the outside - updateRendererState -> _updateRendererState as it is private - _setState function added on controllers, to have a hook when we set a new state (already existed, but only in kanban) - _renderView function moved from Basic to AbstractRenderer, so that we have a proper hook to deactivate clickable elements in sample mode Task 2232801 X-original-commit: 4482a03fe2f083f4f44fc6eb76d90ae22afbff91
Diffstat (limited to 'addons/web/static/src/js/views/abstract_controller.js')
-rw-r--r--addons/web/static/src/js/views/abstract_controller.js53
1 files changed, 29 insertions, 24 deletions
diff --git a/addons/web/static/src/js/views/abstract_controller.js b/addons/web/static/src/js/views/abstract_controller.js
index 3df1d48410b..07c4138c54d 100644
--- a/addons/web/static/src/js/views/abstract_controller.js
+++ b/addons/web/static/src/js/views/abstract_controller.js
@@ -96,7 +96,7 @@ var AbstractController = mvc.Controller.extend(ActionMixin, {
if (this.withControlPanel) {
this._updateControlPanelProps(this.initialState);
this._controlPanelWrapper = new ComponentWrapper(this, ControlPanel, this.controlPanelProps);
- this._controlPanelWrapper.env.bus.on('focus-view', this, () => this.renderer.giveFocus());
+ this._controlPanelWrapper.env.bus.on('focus-view', this, () => this._giveFocus());
promises.push(this._controlPanelWrapper.mount(this.el, { position: 'first-child' }));
}
await Promise.all(promises);
@@ -193,12 +193,6 @@ var AbstractController = mvc.Controller.extend(ActionMixin, {
return state;
},
/**
- * Gives the focus to the renderer
- */
- giveFocus: function () {
- this.renderer.giveFocus();
- },
- /**
* The use of this method is discouraged. It is still snakecased, because
* it currently is used in many templates, but we will move to a simpler
* mechanism as soon as we can.
@@ -246,7 +240,7 @@ var AbstractController = mvc.Controller.extend(ActionMixin, {
}
await Promise.all([this.update(params, {}), searchPanelUpdateProm]);
if (postponeRendering) {
- return this.renderer._render();
+ return this._updateRendererState(false);
}
},
/**
@@ -261,7 +255,6 @@ var AbstractController = mvc.Controller.extend(ActionMixin, {
* @param {Object} params will be given to the model and to the renderer
* @param {Object} [options={}]
* @param {boolean} [options.reload=true] if true, the model will reload data
- *
* @returns {Promise}
*/
async update(params, options = {}) {
@@ -272,7 +265,7 @@ var AbstractController = mvc.Controller.extend(ActionMixin, {
const localState = this.renderer.getLocalState();
const state = this.model.get(this.handle, { withSampleData: true });
const promises = [
- this.updateRendererState(state, params).then(() => {
+ this._updateRendererState(state, params).then(() => {
this.renderer.setLocalState(localState);
}),
this._update(this.model.get(this.handle), params)
@@ -280,19 +273,6 @@ var AbstractController = mvc.Controller.extend(ActionMixin, {
await this.dp.add(Promise.all(promises));
this.updateButtons();
},
- /**
- * Update the state of the renderer (handle both Widget and Component
- * renderers).
- *
- * @param {Object} state the model state
- * @param {Object} params will be given to the model and to the renderer
- */
- updateRendererState: function (state, params) {
- if (this.renderer instanceof owl.Component) {
- return this.renderer.update(state);
- }
- return this.renderer.updateState(state, params);
- },
//--------------------------------------------------------------------------
// Private
@@ -327,6 +307,16 @@ var AbstractController = mvc.Controller.extend(ActionMixin, {
return null;
},
/**
+ * Gives the focus to the renderer if not in sample mode.
+ *
+ * @private
+ */
+ _giveFocus() {
+ if (!this.model.isInSampleMode()) {
+ this.renderer.giveFocus();
+ }
+ },
+ /**
* This method is the way a view can notifies the outside world that
* something has changed. The main use for this is to update the url, for
* example with a new id.
@@ -472,6 +462,21 @@ var AbstractController = mvc.Controller.extend(ActionMixin, {
return this.updateControlPanel({ pager: pagingInfo });
}
},
+ /**
+ * Updates the state of the renderer (handle both Widget and Component
+ * renderers).
+ *
+ * @private
+ * @param {Object} state the model state
+ * @param {Object} [params={}] will be given to the model and to the renderer
+ * @return {Promise}
+ */
+ _updateRendererState(state, params = {}) {
+ if (this.renderer instanceof owl.Component) {
+ return this.renderer.update(state);
+ }
+ return this.renderer.updateState(state, params);
+ },
//--------------------------------------------------------------------------
// Handlers
@@ -551,7 +556,7 @@ var AbstractController = mvc.Controller.extend(ActionMixin, {
break;
case 'down':
ev.stopPropagation();
- this.giveFocus();
+ this._giveFocus();
break;
}
},