summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js/views
diff options
context:
space:
mode:
authorDamien Bouvy <dbo@odoo.com>2019-10-29 16:06:10 +0000
committerAaron Bohy <aab@odoo.com>2019-10-31 11:26:44 +0000
commit8f0d1f1462b7b207e0fa299d3f50762cb99a7685 (patch)
tree03ea758fe38917c855a02f78ac262b76a7efce43 /addons/web/static/src/js/views
parent8e4a55fb81f40a5d406a0906ee3ffeacdcfffc4e (diff)
[IMP] web: allow custom state in action mixin
Sometimes, it might be useful for an action (e.g. a client action, although this may be used by standard views as well) to include custom values in its state. Since the state of a 'fullscreen' action is pushed in the URL, this means that it is possible for the action to resume its state properly upon refresh of the page (before this commit, only some standard information were pushed to the state - action_id, menu_id, etc. for window actions and action's name, active_id, active_ids for client actions). By implementing the `getState` method, an extension of the action mixin can thus push any state it wishes to the URL. closes odoo/odoo#39529 Signed-off-by: Damien Bouvy (dbo) <dbo@odoo.com>
Diffstat (limited to 'addons/web/static/src/js/views')
-rw-r--r--addons/web/static/src/js/views/abstract_controller.js6
-rw-r--r--addons/web/static/src/js/views/form/form_controller.js25
2 files changed, 13 insertions, 18 deletions
diff --git a/addons/web/static/src/js/views/abstract_controller.js b/addons/web/static/src/js/views/abstract_controller.js
index 70cec99aa86..152d8c08071 100644
--- a/addons/web/static/src/js/views/abstract_controller.js
+++ b/addons/web/static/src/js/views/abstract_controller.js
@@ -331,13 +331,11 @@ var AbstractController = mvc.Controller.extend(ActionMixin, {
* example with a new id.
*
* @private
- * @param {Object} [state] information that will be pushed to the outside
- * world
*/
- _pushState: function (state) {
+ _pushState: function () {
this.trigger_up('push_state', {
controllerID: this.controllerID,
- state: state || {},
+ state: this.getState(),
});
},
/**
diff --git a/addons/web/static/src/js/views/form/form_controller.js b/addons/web/static/src/js/views/form/form_controller.js
index 2a39742b206..ede9667bf0c 100644
--- a/addons/web/static/src/js/views/form/form_controller.js
+++ b/addons/web/static/src/js/views/form/form_controller.js
@@ -126,6 +126,17 @@ var FormController = BasicController.extend({
return this.model.getName(this.handle);
},
/**
+ * Add the current ID to the state pushed in the url.
+ *
+ * @override
+ */
+ getState: function () {
+ const state = this._super.apply(this, arguments);
+ const env = this.model.get(this.handle, {env: true});
+ state.id = env.currentId;
+ return state;
+ },
+ /**
* Render buttons for the control panel. The form view can be rendered in
* a dialog, and in that case, if we have buttons defined in the footer, we
* have to use them instead of the standard buttons.
@@ -422,20 +433,6 @@ var FormController = BasicController.extend({
}
},
/**
- * We just add the current ID to the state pushed. This allows the web
- * client to add it in the url, for example.
- *
- * @override method from AbstractController
- * @private
- * @param {Object} [state]
- */
- _pushState: function (state) {
- state = state || {};
- var env = this.model.get(this.handle, {env: true});
- state.id = env.currentId;
- this._super(state);
- },
- /**
* Overrides to reload the form when saving failed in readonly (e.g. after
* a change on a widget like priority or statusbar).
*