diff options
| author | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
|---|---|---|
| committer | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
| commit | 3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch) | |
| tree | a44932296ef4a9b71d5f010906253d8c53727726 /addons/website/static/src/snippets/s_popup/options.js | |
| parent | 0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff) | |
initial commit 2
Diffstat (limited to 'addons/website/static/src/snippets/s_popup/options.js')
| -rw-r--r-- | addons/website/static/src/snippets/s_popup/options.js | 114 |
1 files changed, 114 insertions, 0 deletions
diff --git a/addons/website/static/src/snippets/s_popup/options.js b/addons/website/static/src/snippets/s_popup/options.js new file mode 100644 index 00000000..f31c00d3 --- /dev/null +++ b/addons/website/static/src/snippets/s_popup/options.js @@ -0,0 +1,114 @@ +odoo.define('website.s_popup_options', function (require) { +'use strict'; + +const options = require('web_editor.snippets.options'); + +options.registry.SnippetPopup = options.Class.extend({ + /** + * @override + */ + start: function () { + // Note: the link are excluded here so that internal modal buttons do + // not close the popup as we want to allow edition of those buttons. + this.$target.on('click.SnippetPopup', '.js_close_popup:not(a, .btn)', ev => { + ev.stopPropagation(); + this.onTargetHide(); + this.trigger_up('snippet_option_visibility_update', {show: false}); + }); + this.$target.on('shown.bs.modal.SnippetPopup', () => { + this.trigger_up('snippet_option_visibility_update', {show: true}); + }); + this.$target.on('hidden.bs.modal.SnippetPopup', () => { + this.trigger_up('snippet_option_visibility_update', {show: false}); + }); + return this._super(...arguments); + }, + /** + * @override + */ + destroy: function () { + this._super(...arguments); + this.$target.off('.SnippetPopup'); + }, + /** + * @override + */ + onBuilt: function () { + this._assignUniqueID(); + }, + /** + * @override + */ + onClone: function () { + this._assignUniqueID(); + }, + /** + * @override + */ + onTargetShow: async function () { + this.$target.modal('show'); + $(document.body).children('.modal-backdrop:last').addClass('d-none'); + }, + /** + * @override + */ + onTargetHide: async function () { + return new Promise(resolve => { + const timeoutID = setTimeout(() => { + this.$target.off('hidden.bs.modal.popup_on_target_hide'); + resolve(); + }, 500); + this.$target.one('hidden.bs.modal.popup_on_target_hide', () => { + clearTimeout(timeoutID); + resolve(); + }); + this.$target.modal('hide'); + }); + }, + + //-------------------------------------------------------------------------- + // Options + //-------------------------------------------------------------------------- + + /** + * Moves the snippet in footer to be common to all pages + * or inside wrap to be on one page only + * + * @see this.selectClass for parameters + */ + moveBlock: function (previewMode, widgetValue, params) { + const $container = $(widgetValue === 'moveToFooter' ? 'footer' : 'main'); + this.$target.closest('.s_popup').prependTo($container.find('.oe_structure:o_editable').first()); + }, + /** + * @see this.selectClass for parameters + */ + setBackdrop(previewMode, widgetValue, params) { + const color = widgetValue ? 'var(--black-50)' : ''; + this.$target[0].style.setProperty('background-color', color, 'important'); + }, + + //-------------------------------------------------------------------------- + // Private + //-------------------------------------------------------------------------- + + /** + * Creates a unique ID. + * + * @private + */ + _assignUniqueID: function () { + this.$target.closest('.s_popup').attr('id', 'sPopup' + Date.now()); + }, + /** + * @override + */ + _computeWidgetState: function (methodName, params) { + switch (methodName) { + case 'moveBlock': + return this.$target.closest('footer').length ? 'moveToFooter' : 'moveToBody'; + } + return this._super(...arguments); + }, +}); +}); |
