diff options
| author | qsm-odoo <qsm@odoo.com> | 2017-07-13 18:09:22 +0200 |
|---|---|---|
| committer | qsm-odoo <qsm@odoo.com> | 2017-07-24 14:26:59 +0200 |
| commit | 68766764bc9c2c824c7844bb721a48189d812ef6 (patch) | |
| tree | 00f69fda165018896293170427c7ede24ac9bea9 /addons/web/static/src/js/core/dialog.js | |
| parent | f2521c9449d1f0b4fac7443aca4792e986c1a3a9 (diff) | |
[IMP] web: get rid of WidgetButton template
Qweb rendering is great to render "complex" widget structures. However,
using it to render something as simple as a button was not very
meaningful. This commit deletes the "WidgetButton" template and replaces
it with an utility JS function to render buttons according to given
parameters.
Also, this change will allow a better change. Before this commit, the
only templates left in the "base_common.xml" file are the "WidgetButton"
and the "Dialog" ones. With the removal of "WidgetButton", the file can
now be lazy loaded only if necessary, on the first dialog instantiation.
This will allow to remove the need to load static XML files on each
frontend page loading.
Diffstat (limited to 'addons/web/static/src/js/core/dialog.js')
| -rw-r--r-- | addons/web/static/src/js/core/dialog.js | 48 |
1 files changed, 22 insertions, 26 deletions
diff --git a/addons/web/static/src/js/core/dialog.js b/addons/web/static/src/js/core/dialog.js index 6214c99483e..ec3a3109053 100644 --- a/addons/web/static/src/js/core/dialog.js +++ b/addons/web/static/src/js/core/dialog.js @@ -2,6 +2,7 @@ odoo.define('web.Dialog', function (require) { "use strict"; var core = require('web.core'); +var dom = require('web.dom'); var Widget = require('web.Widget'); var QWeb = core.qweb; @@ -71,36 +72,31 @@ var Dialog = Widget.extend({ } this.$el.addClass('modal-body ' + this.dialogClass); }, - - set_buttons: function(buttons) { + /** + * @param {Object[]} buttons - @see init + */ + set_buttons: function (buttons) { var self = this; - - self.$footer.empty(); - - _.each(buttons, function(b) { - var text = b.text || ""; - var classes = b.classes || ((buttons.length === 1)? "btn-primary" : "btn-default"); - - var $b = $(QWeb.render('WidgetButton', { - widget: { - string: text, - node: { - attrs: {'class': classes, icon: b.icon} - }, - fa_icon: true - } - })); - $b.prop('disabled', b.disabled); - $b.on('click', function(e) { - var click_def; - if(b.click) { - click_def = b.click.call(self, e); + this.$footer.empty(); + _.each(buttons, function (buttonData) { + var $button = dom.renderButton({ + attrs: { + class: buttonData.classes || (buttons.length > 1 ? 'btn-default' : '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(b.close) { - $.when(click_def).always(self.close.bind(self)); + if (buttonData.close) { + $.when(def).always(self.close.bind(self)); } }); - self.$footer.append($b); + self.$footer.append($button); }); }, |
