summaryrefslogtreecommitdiff
path: root/addons/web/static/src
diff options
context:
space:
mode:
authorAlexandre Kühn <aku@odoo.com>2018-07-16 11:03:47 +0200
committerSimon Lejeune <sle@openerp.com>2018-08-13 14:23:19 +0200
commit65cc630050ed8e7642747a8f5b54d668f458dd0c (patch)
treed9dcbb2e067e145a4922330b03bbccb9664fb246 /addons/web/static/src
parent2502b34a7220ebf8c0a9f1b64861ab200f5bd9a8 (diff)
[IMP] web: provide infos for close action
This is a backport of 3210f108272be89f1a7b01f4e1816b7f04ae0a3b With this commit, when we perform a close action, we can provide infos to the `on_close` handler, so that it can handle different cases that caused the close action.
Diffstat (limited to 'addons/web/static/src')
-rw-r--r--addons/web/static/src/js/chrome/action_manager.js49
-rw-r--r--addons/web/static/src/js/core/dialog.js14
2 files changed, 46 insertions, 17 deletions
diff --git a/addons/web/static/src/js/chrome/action_manager.js b/addons/web/static/src/js/chrome/action_manager.js
index f98447c8983..e9ff1957ea2 100644
--- a/addons/web/static/src/js/chrome/action_manager.js
+++ b/addons/web/static/src/js/chrome/action_manager.js
@@ -279,17 +279,21 @@ var ActionManager = Widget.extend({
* Closes the current dialog, if any. Because we listen to the 'closed'
* event triggered by the dialog when it is closed, this also destroys the
* embedded controller and removes the reference to the corresponding action.
- * This also executes the 'on_close' handler in some cases.
+ * This also executes the 'on_close' handler in some cases, and may also
+ * provide infos for closing this dialog.
*
* @private
- * @param {boolean} [silent=false] if true, the 'on_close' handler won't be
- * called ; this is in general the case when the current dialog is closed
- * because another action is opened, so we don't want the former action
- * to execute its handler as it won't be displayed anyway
- */
- _closeDialog: function (silent) {
+ * @param {Object} options
+ * @param {Object} [options.infos] some infos related to the closing the
+ * dialog.
+ * @param {boolean} [options.silent=false] if true, the 'on_close' handler
+ * won't be called ; this is in general the case when the current dialog
+ * is closed because another action is opened, so we don't want the former
+ * action to execute its handler as it won't be displayed anyway
+ */
+ _closeDialog: function (options) {
if (this.currentDialogController) {
- this.currentDialogController.dialog.destroy(silent);
+ this.currentDialogController.dialog.destroy(options);
}
},
/**
@@ -340,7 +344,7 @@ var ActionManager = Widget.extend({
})
.then(function (controller) {
if (self.currentDialogController) {
- self._closeDialog(true);
+ self._closeDialog({ silent: true });
}
// store the optional 'on_reverse_breadcrumb' handler
@@ -394,7 +398,7 @@ var ActionManager = Widget.extend({
var prevDialogOnClose;
if (self.currentDialogController) {
prevDialogOnClose = self.currentDialogController.onClose;
- self._closeDialog(true);
+ self._closeDialog({ silent: true });
}
controller.onClose = prevDialogOnClose || options.on_close;
@@ -404,11 +408,19 @@ var ActionManager = Widget.extend({
title: action.name,
size: action.context.dialog_size,
}));
- dialog.on('closed', self, function (silent) {
+ /**
+ * @param {Object} [options]
+ * @param {Object} [options.infos] if provided and `silent` is
+ * unset, the `on_close` handler will pass this information,
+ * which gives some context for closing this dialog.
+ * @param {boolean} [options.silent=false] if set, do not call the
+ * `on_close` handler.
+ */
+ dialog.on('closed', self, function (options) {
self._removeAction(action.jsID);
self.currentDialogController = null;
- if (silent !== true) {
- controller.onClose();
+ if (options && options.silent !== true) {
+ controller.onClose(options.infos);
}
});
controller.dialog = dialog;
@@ -486,17 +498,24 @@ var ActionManager = Widget.extend({
* Executes actions of type 'ir.actions.act_window_close', i.e. closes the
* last opened dialog.
*
+ * The action may also specify an effect to display right after the close
+ * action (e.g. rainbow man), or provide a reason for the close action.
+ * This is useful for decision making for the `on_close` handler.
+ *
* @private
* @param {Object} action
+ * @param {Object} [action.effect] effect to show up, e.g. rainbow man.
+ * @param {Object} [action.infos] infos on performing the close action.
+ * Useful for providing some context for the `on_close` handler.
* @returns {Deferred} resolved immediately
*/
_executeCloseAction: function (action, options) {
var result;
if (!this.currentDialogController) {
- result = options.on_close();
+ result = options.on_close(action.infos);
}
- this._closeDialog();
+ this._closeDialog({ infos: action.infos });
// display some effect (like rainbowman) on appropriate actions
if (action.effect) {
diff --git a/addons/web/static/src/js/core/dialog.js b/addons/web/static/src/js/core/dialog.js
index 7d4796886b7..2331cdaa12d 100644
--- a/addons/web/static/src/js/core/dialog.js
+++ b/addons/web/static/src/js/core/dialog.js
@@ -183,12 +183,22 @@ var Dialog = Widget.extend({
this.destroy();
},
- destroy: function (arg) {
+ /**
+ * Close and destroy the dialog.
+ *
+ * @param {Object} [options]
+ * @param {Object} [options.infos] if provided and `silent` is unset, the
+ * `on_close` handler will pass this information related to closing this
+ * information.
+ * @param {boolean} [options.silent=false] if set, do not call the
+ * `on_close` handler.
+ */
+ destroy: function (options) {
// Need to trigger before real destroy but if 'closed' handler destroys
// the widget again, we want to avoid infinite recursion
if (!this.__closed) {
this.__closed = true;
- this.trigger("closed", arg);
+ this.trigger('closed', options);
}
if (this.isDestroyed()) {