diff options
| author | qsm-odoo <qsm@odoo.com> | 2017-07-13 18:38:18 +0200 |
|---|---|---|
| committer | qsm-odoo <qsm@odoo.com> | 2017-07-24 14:28:35 +0200 |
| commit | 5f1ef0910bec16415989835b30727b976c80ea4f (patch) | |
| tree | 504f8196a5186e146ecae49221aa53eae2301721 /addons/web/static/src/js/views/view_dialogs.js | |
| parent | 68766764bc9c2c824c7844bb721a48189d812ef6 (diff) | |
[IMP] web, *: lazy load dialog xml template
* web_editor, web_planner, website
The 'Dialog' class is used in both backend and frontend. Also, lots of
actions can be done without the use of any modal. It thus makes sense
to lazy load its related xml only when a first modal is opened.
This change also allows to get rid of the "base_common.xml" file as the
dialog template is the only remaining one in there and, in the future
website update, it will allow to not load any static XML file on website
page loadings.
Diffstat (limited to 'addons/web/static/src/js/views/view_dialogs.js')
| -rw-r--r-- | addons/web/static/src/js/views/view_dialogs.js | 36 |
1 files changed, 21 insertions, 15 deletions
diff --git a/addons/web/static/src/js/views/view_dialogs.js b/addons/web/static/src/js/views/view_dialogs.js index d38400c2e84..97b17f00413 100644 --- a/addons/web/static/src/js/views/view_dialogs.js +++ b/addons/web/static/src/js/views/view_dialogs.js @@ -192,13 +192,16 @@ var FormViewDialog = ViewDialog.extend({ .then(function () { var $buttons = $('<div>'); self.form_view.renderButtons($buttons); - if ($buttons.children().length) { - self.$footer.empty().append($buttons.contents()); - } - dom.append(_super().$el, fragment, { - callbacks: [{widget: self.form_view}], - in_DOM: true, + self.opened().always(function () { + if ($buttons.children().length) { + self.$footer.empty().append($buttons.contents()); + } + dom.append(self.$el, fragment, { + callbacks: [{widget: self.form_view}], + in_DOM: true, + }); }); + _super(); }); }); @@ -282,7 +285,7 @@ var SelectCreateDialog = ViewDialog.extend({ }, open: function () { - if(this.options.initial_view !== "search") { + if (this.options.initial_view !== "search") { return this.create_edit_record(); } var self = this; @@ -303,10 +306,14 @@ var SelectCreateDialog = ViewDialog.extend({ this.loadViews(this.dataset.model, this.dataset.get_context(), [[false, 'list'], [false, 'search']], {}) .then(this.setup.bind(this, search_defaults)) .then(function (fragment) { - dom.append(_super().$el, fragment, { - callbacks: [{widget: self.list_controller}], - in_DOM: true, + self.opened().then(function () { + dom.append(self.$el, fragment, { + callbacks: [{widget: self.list_controller}], + in_DOM: true, + }); + self.set_buttons(self.__buttons); }); + _super(); }); return this; }, @@ -349,20 +356,20 @@ var SelectCreateDialog = ViewDialog.extend({ }).then(function (controller) { self.list_controller = controller; // Set the dialog's buttons - var buttons = [{ + self.__buttons = [{ text: _t("Cancel"), classes: "btn-default o_form_button_cancel", close: true, }]; if (!self.options.no_create) { - buttons.unshift({ + self.__buttons.unshift({ text: _t("Create"), classes: "btn-primary", click: self.create_edit_record.bind(self) }); } if (!self.options.disable_multiple_selection) { - buttons.unshift({ + self.__buttons.unshift({ text: _t("Select"), classes: "btn-primary o_select_button", disabled: true, @@ -372,7 +379,6 @@ var SelectCreateDialog = ViewDialog.extend({ }, }); } - self.set_buttons(buttons); return self.list_controller.appendTo(fragment); }).then(function () { searchview.toggle_visibility(true); @@ -401,7 +407,7 @@ var SelectCreateDialog = ViewDialog.extend({ self.on_selected([record.res_id]); }, })).open(); - dialog.on('closed', this, this.close.bind(this)); + dialog.on('closed', this, this.close); }, }); |
