[IMP] web: formview auto close dialog

Sometimes when using a form view in a modal (e.i.: in a gantt view), we might
want to have some button in the footer. We expect clicking on buttons to close
the dialog but nothing happens, since the webclient does not know that this is
a modal.
To do so, we provide the `close='1'` attribute on the button, in form view.
This will trigger the event closing the modal.

This is done with the benediction of aab-odoo

Task-2024216

closes odoo/odoo#36493

Signed-off-by: Jérome Maes (jem) <jem@openerp.com>
This commit is contained in:
jem-odoo
2019-09-05 20:11:28 +00:00
parent 1b24f60a5c
commit ba05c66e09
2 changed files with 16 additions and 1 deletions
+8
View File
@@ -21,6 +21,7 @@ var Dialog = Widget.extend({
xmlDependencies: ['/web/static/src/xml/dialog.xml'],
custom_events: _.extend({}, Widget.prototype.custom_events, {
focus_control_button: '_onFocusControlButton',
close_dialog: '_onCloseDialog',
}),
events: _.extend({}, Widget.prototype.events, {
'keydown .modal-footer button': '_onFooterButtonKeyDown',
@@ -316,6 +317,13 @@ var Dialog = Widget.extend({
//--------------------------------------------------------------------------
// Handlers
//--------------------------------------------------------------------------
/**
* @private
*/
_onCloseDialog: function (ev) {
ev.stopPropagation();
this.close();
},
/**
* Moves the focus to the first button primary in the footer of the dialog
*
@@ -577,7 +577,14 @@ var FormController = BasicController.extend({
return;
}
def.then(this._enableButtons.bind(this)).guardedCatch(this._enableButtons.bind(this));
// Kind of hack for FormViewDialog: button on footer should trigger the dialog closing
// if the `close` attribute is set
def.then(function () {
self._enableButtons();
if (attrs.close) {
self.trigger_up('close_dialog');
}
}).guardedCatch(this._enableButtons.bind(this));
},
/**
* Called when the user wants to create a new record -> @see createRecord