summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js
diff options
context:
space:
mode:
authorPierre Paridans <app@odoo.com>2019-08-23 12:30:59 +0000
committerPierre Paridans <app@odoo.com>2019-08-26 14:13:06 +0000
commit9c8902ed57611a9b27228e49c6b2fa64e42c2d78 (patch)
tree82f92cff051eaa99831698672f53a707b77a4650 /addons/web/static/src/js
parent96a52daa80b18d129bd9dbf332c1dd52d062629a (diff)
[IMP] web: add extension hooks to Dialog
This commit adds two methods as hooks to customize the way Dialog deals with its buttons : * _setButtonsTo() : to render and set the buttons into a container element; * _setRemoveButtonOption() : to define the remove button and set its destination zone (header, footer) Task ID: 2038324 closes odoo/odoo#35474 Signed-off-by: Pierre Paridans <pparidans@users.noreply.github.com> Co-authored-by: Dharmang Soni <dpr@odoo.com>
Diffstat (limited to 'addons/web/static/src/js')
-rw-r--r--addons/web/static/src/js/core/dialog.js64
-rw-r--r--addons/web/static/src/js/views/view_dialogs.js26
2 files changed, 56 insertions, 34 deletions
diff --git a/addons/web/static/src/js/core/dialog.js b/addons/web/static/src/js/core/dialog.js
index 6d02c23664e..047df634ba2 100644
--- a/addons/web/static/src/js/core/dialog.js
+++ b/addons/web/static/src/js/core/dialog.js
@@ -157,33 +157,7 @@ var Dialog = Widget.extend({
* @param {Object[]} buttons - @see init
*/
set_buttons: function (buttons) {
- var self = this;
- this.$footer.empty();
- _.each(buttons, function (buttonData) {
- var $button = dom.renderButton({
- attrs: {
- class: buttonData.classes || (buttons.length > 1 ? 'btn-secondary' : 'btn-primary'),
- disabled: buttonData.disabled,
- },
- icon: buttonData.icon,
- text: buttonData.text,
- });
- $button.on('click', function (e) {
- var def;
- if (buttonData.click) {
- def = buttonData.click.call(self, e);
- }
- if (buttonData.close) {
- self.onForceClose = false;
- Promise.resolve(def).then(self.close.bind(self)).guardedCatch(self.close.bind(self));
- }
- });
- if (self.technical) {
- self.$footer.append($button);
- } else {
- self.$footer.prepend($button);
- }
- });
+ this._setButtonsTo(this.$footer, buttons);
},
set_title: function (title, subtitle) {
@@ -303,6 +277,42 @@ var Dialog = Widget.extend({
_focusOnClose: function() {
return false;
},
+ /**
+ * Render and set the given buttons into a target element
+ *
+ * @private
+ * @param {jQueryElement} $target The destination of the rendered buttons
+ * @param {Array} buttons The array of buttons to render
+ */
+ _setButtonsTo($target, buttons) {
+ var self = this;
+ $target.empty();
+ _.each(buttons, function (buttonData) {
+ var $button = dom.renderButton({
+ attrs: {
+ class: buttonData.classes || (buttons.length > 1 ? 'btn-secondary' : 'btn-primary'),
+ disabled: buttonData.disabled,
+ },
+ icon: buttonData.icon,
+ text: buttonData.text,
+ });
+ $button.on('click', function (e) {
+ var def;
+ if (buttonData.click) {
+ def = buttonData.click.call(self, e);
+ }
+ if (buttonData.close) {
+ self.onForceClose = false;
+ Promise.resolve(def).then(self.close.bind(self)).guardedCatch(self.close.bind(self));
+ }
+ });
+ if (self.technical) {
+ $target.append($button);
+ } else {
+ $target.prepend($button);
+ }
+ });
+ },
//--------------------------------------------------------------------------
// Handlers
//--------------------------------------------------------------------------
diff --git a/addons/web/static/src/js/views/view_dialogs.js b/addons/web/static/src/js/views/view_dialogs.js
index beead650622..130173a16fc 100644
--- a/addons/web/static/src/js/views/view_dialogs.js
+++ b/addons/web/static/src/js/views/view_dialogs.js
@@ -155,13 +155,7 @@ var FormViewDialog = ViewDialog.extend({
var multi = options.disable_multiple_selection;
if (!multi && this.deletable) {
- options.buttons.push({
- text: _t("Remove"),
- classes: 'btn-secondary ' + oBtnRemove,
- click: function() {
- self._remove().then(self.close.bind(self));
- }
- });
+ this._setRemoveButtonOption(options, oBtnRemove);
}
}
}
@@ -276,6 +270,24 @@ var FormViewDialog = ViewDialog.extend({
return self.on_saved(record, !!changedFields.length);
});
},
+
+ /**
+ * Set the "remove" button into the options' buttons list
+ *
+ * @private
+ * @param {Object} options The options object to modify
+ * @param {string} btnClasses The classes for the remove button
+ */
+ _setRemoveButtonOption(options, btnClasses) {
+ const self = this;
+ options.buttons.push({
+ text: _t("Remove"),
+ classes: 'btn-secondary ' + btnClasses,
+ click: function() {
+ self._remove().then(self.close.bind(self));
+ }
+ });
+ },
});
/**